├── entrypoint.sh ├── Dockerfile ├── seafile-download.sh ├── README.md ├── mysql-setup.sh ├── seafile-nginx.sh ├── seafile-setup.sh └── seafile-setup-mysql.sh /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | 4 | if [ ! -d "/opt/seafile/installed/" ]; then 5 | /usr/bin/seafile-download 6 | fi 7 | 8 | if [ ! -f "/opt/seafile/conf/seahub_settings.pyc" ]; then 9 | if [ -z "$MYSQL_ENV_MYSQL_ROOT_PASSWORD" ]; then 10 | [ -z "$MYSQL_ROOT_PASSWORD" ] && MYSQL_ROOT_PASSWORD=123456 11 | /usr/bin/mysql-setup MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD 12 | /usr/bin/seafile-setup-mysql 13 | else 14 | /usr/bin/seafile-setup 15 | fi 16 | fi 17 | 18 | if [ ! -f "/etc/nginx/conf.d/seafile.conf" ]; then 19 | /usr/bin/seafile-nginx 20 | fi 21 | 22 | if [ -f "/etc/init.d/mysql" ]; then 23 | /etc/init.d/mysql stop &>/dev/null 24 | /etc/init.d/mysql start 25 | fi 26 | 27 | if [ -f "/etc/init.d/seafile" ]; then 28 | chown root:root /opt/seafile -R 29 | /etc/init.d/seafile stop &>/dev/null 30 | /etc/init.d/seafile start 31 | fi 32 | 33 | if [ -f "/etc/init.d/nginx" ]; then 34 | /etc/init.d/nginx stop &>/dev/null 35 | /etc/init.d/nginx start 36 | fi 37 | 38 | exec "$@" -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage:0.9.19 2 | MAINTAINER WangYan 3 | 4 | RUN mkdir -p /opt/seafile 5 | WORKDIR /opt/seafile 6 | 7 | RUN apt-get -y update && apt-get -y install wget apparmor\ 8 | sudo pwgen net-tools mysql-client libmysqlclient-dev \ 9 | python2.7 libpython2.7 python-setuptools python-imaging \ 10 | python-ldap python-mysqldb python-memcache python-urllib3 11 | 12 | # Seafile Config 13 | ADD ./seafile-download.sh /usr/bin/seafile-download 14 | ADD ./mysql-setup.sh /usr/bin/mysql-setup 15 | ADD ./seafile-setup.sh /usr/bin/seafile-setup 16 | ADD ./seafile-setup-mysql.sh /usr/bin/seafile-setup-mysql 17 | ADD ./seafile-nginx.sh /usr/bin/seafile-nginx 18 | ADD ./entrypoint.sh /entrypoint.sh 19 | 20 | RUN chmod +x /usr/bin/seafile-download /usr/bin/seafile-nginx \ 21 | /usr/bin/seafile-setup /usr/bin/seafile-setup-mysql \ 22 | /usr/bin/mysql-setup /entrypoint.sh 23 | 24 | # Expose Ports 25 | EXPOSE 8082 26 | EXPOSE 80 27 | EXPOSE 443 28 | 29 | # APT Clean 30 | RUN apt-get clean && \ 31 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ./nginx_signing.key 32 | 33 | ENTRYPOINT ["/entrypoint.sh"] 34 | 35 | CMD ["/sbin/my_init"] -------------------------------------------------------------------------------- /seafile-download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | cd /opt/seafile 4 | 5 | if [ "$APT_MIRRORS" = "aliyun" ];then 6 | sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list 7 | fi 8 | 9 | arch=$(uname -m | sed s/"_"/"-"/g) 10 | regexp="http(s?):\/\/[^ \"\(\)\<\>]*seafile-server_[\d\.\_]*$arch.tar.gz" 11 | 12 | which wget > /dev/null 13 | wget=$? 14 | which curl > /dev/null 15 | curl=$? 16 | if [ $wget -eq 0 ]; then 17 | addr=$(wget -c -t 10 -T 120 https://www.seafile.com/download/ -O - | grep -o -P "$regexp" | head -1) 18 | wget -q -c -t 10 -T 120 $addr 19 | elif [ $curl -eq 0 ]; then 20 | addr=$(curl -C - -Ls https://www.seafile.com/download/ | grep -o -P "$regexp" | head -1) 21 | curl -Ls -C - -O $addr 22 | else 23 | echo "Neither curl nor wget found. Exiting." 24 | exit 1 25 | fi 26 | 27 | # figure out what directory the tarball is going to create 28 | file=$( echo $addr | awk -F/ '{ print $NF }' ) 29 | 30 | # test that we got something 31 | if [ ! -z $file -a -f $file ]; then 32 | dir=$( tar tvzf $file 2>/dev/null | head -n 1 | awk '{ print $NF }' | sed -e 's!/!!g') 33 | tar xzf $file 34 | 35 | # mkdir only if we don't already have one 36 | [ ! -d installed ] && mkdir installed 37 | 38 | # move the tarball only if we created the directory 39 | [ -d $dir ] && mv seafile-server_* installed 40 | else 41 | echo "Seafile install file not downloaded. Exiting." 42 | exit 1 43 | fi -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Seafile-Docker 2 | 3 | 基于 `Ubuntu 16.04` 构建,一键自动安装最新版的 `Seafile`,并自动完成设置,使用外部`MySQL`数据库,支持 `Nginx SSL` 访问,默认开启 `WebDAV` 功能。了解更多信息,请访问`Seafile` 官网。 4 | 5 | ## 一、安装 Docker 6 | 7 | 关于Docker 更多信息,请访问其官网。 8 | 9 | **debian** 10 | 11 | ```shell 12 | apt-get update && \ 13 | apt-get -y install curl && \ 14 | curl -fsSL https://get.daocloud.io/docker | sh \ 15 | update-rc.d -f docker defaults && \ 16 | service docker start 17 | ``` 18 | 19 | **CentOS** 20 | 21 | ```shel 22 | yum update && \ 23 | curl -fsSL https://get.docker.com/ | sh && \ 24 | systemctl enable docker.service && \ 25 | systemctl start docker.service 26 | ``` 27 | 28 | ## 二、安装 MySQL 数据库 29 | 30 | **如果你想使用内置的数据库,请忽略步骤(二)(三)(四),直接跳到步骤(五)** 31 | 32 | > 注意将`123456`换成你的MySQL Root密码 33 | 34 | ```shell 35 | docker run --name mysql \ 36 | -v /var/lib/mysql:/var/lib/mysql \ 37 | -e MYSQL_ROOT_PASSWORD=123456 \ 38 | -p 3306:3306 \ 39 | -d mysql:latest 40 | ``` 41 | 42 | ## 三、安装 phpMyAdmin (可选) 43 | 44 | > **温馨提示:**国内主机请将 `idiswy/phpmyadmin:latest` 换成 `docker.wangyan.org/docker/phpmyadmin:latest` 45 | 46 | ```shell 47 | docker run --name phpmyadmin \ 48 | --link mysql:mysql \ 49 | -p 8080:80 \ 50 | -P -d idiswy/phpmyadmin:latest 51 | ``` 52 | 53 | ## 四、安装 Seafile (外部数据库) 54 | 55 | - `IP_OR_DOMAIN` 服务器IP或者域名 56 | - `SEAFILE_ADMIN` 创建 Seafile 管理员账号 57 | - `SEAFILE_ADMIN_PW` Seafile 管理员密码 58 | - `SQLSEAFILEPW` Seafile 数据库密码 59 | 60 | > 注意:如果有防火墙,请务必开放8082端口,用于客户端同步。 61 | > 国内主机请将 `idiswy/seafile:latest` 换成 `docker.wangyan.org/docker/seafile:latest` 62 | > 国内主机可增加`-e APT_MIRRORS=aliyun` 选项,使用国内的镜像源。 63 | 64 | ```shell 65 | docker run --name seafile \ 66 | --link mysql:mysql \ 67 | -p 8082:8082 \ 68 | -p 80:80 \ 69 | -p 443:443 \ 70 | -e IP_OR_DOMAIN=cloud.wangyan.org \ 71 | -e SEAFILE_ADMIN=info@wangyan.org \ 72 | -e SEAFILE_ADMIN_PW=123456 \ 73 | -e SQLSEAFILEPW=123456 \ 74 | -v /home/seafile:/opt/seafile \ 75 | -d idiswy/seafile 76 | ``` 77 | 78 | 安装可能需要 1 分钟左右,通过下面方法查看安装进度。 79 | 80 | ```shell 81 | docker logs -f seafile //查看安装进度 82 | ``` 83 | 84 | ## 五、安装 Seafile (内置数据库) 85 | 86 | **如果你想使用外部数据库,请返回到步骤(二)安装** 87 | 88 | - `MYSQL_ROOT_PASSWORD` MySQL Root 密码 89 | - `IP_OR_DOMAIN` 服务器IP或者域名 90 | - `SEAFILE_ADMIN` 创建 Seafile 管理员账号 91 | - `SEAFILE_ADMIN_PW` Seafile 管理员密码 92 | - `SQLSEAFILEPW` Seafile 数据库密码 93 | 94 | > 注意:如果有防火墙,请务必开放8082端口,用于客户端同步。 95 | > 国内主机请将 `idiswy/seafile:latest` 换成 `docker.wangyan.org/docker/seafile:latest` 96 | > 国内主机可增加`-e APT_MIRRORS=aliyun` 选项,使用国内的镜像源。 97 | 98 | ```shell 99 | docker run --name seafile \ 100 | -p 8082:8082 \ 101 | -p 80:80 \ 102 | -p 443:443 \ 103 | -e MYSQL_ROOT_PASSWORD=123456 \ 104 | -e IP_OR_DOMAIN=cloud.wangyan.org \ 105 | -e SEAFILE_ADMIN=info@wangyan.org \ 106 | -e SEAFILE_ADMIN_PW=123456 \ 107 | -e SQLSEAFILEPW=123456 \ 108 | -v /home/seafile:/opt/seafile \ 109 | -d idiswy/seafile 110 | ``` 111 | 安装可能需要 5 分钟左右,通过下面方法查看安装进度。 112 | 113 | ```shell 114 | docker logs -f seafile //查看安装进度 115 | ``` 116 | 117 | ## 六、常见操作 118 | 119 | ### 6.1 进入容器 120 | 121 | 首先,安装个小工具 122 | 123 | ```shell 124 | curl --fail -L -O https://github.com/phusion/baseimage-docker/archive/master.tar.gz && \ 125 | tar xzf master.tar.gz && \ 126 | ./baseimage-docker-master/install-tools.sh 127 | ``` 128 | 129 | 然后,进入容器 130 | 131 | ```shell 132 | docker-bash seafile 133 | ``` 134 | 135 | **配置文件路径** 136 | 137 | - `nginx 配置文件` /etc/nginx/conf.d/seafile.conf 138 | - `seafile 配置文件` /opt/seafile/conf/ 139 | 140 | ### 6.2 重启操作 141 | 142 | 重启 nginx(nginx 修改配置文件后,需要重启) 143 | 144 | ```shell 145 | sv reload nginx 146 | ``` 147 | 148 | 重启 seafile 149 | 150 | ```shell 151 | /etc/init.d/seafile restart 152 | ``` 153 | 154 | ## 七、系统设置(可选) 155 | 156 | ### 6.1. 解决Debian本地化问题 157 | 158 | ```shell 159 | apt-get update && apt-get install -y language-pack-zh-hans-base 160 | ``` 161 | 162 | ```shell 163 | cat >/etc/default/locale<<-EOF 164 | LANG=zh_CN.UTF-8 165 | LANGUAGE=zh_CN.UTF-8 166 | LC_ALL=zh_CN.UTF-8 167 | EOF 168 | ``` 169 | 170 | ```shell 171 | locale-gen "zh_CN.UTF-8" && dpkg-reconfigure locales 172 | ``` 173 | 174 | ### 7.2.设置中国时区 175 | 176 | **Debbian** 177 | 178 | ```shell 179 | rm -rf /etc/localtime && \ 180 | ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 181 | echo "Asia/Shanghai" > /etc/timezone && \ 182 | apt-get -y install ntpdate && ntpdate -d cn.pool.ntp.org 183 | ``` 184 | 185 | **CentOS 7** 186 | 187 | via 188 | 189 | ```shell 190 | imedatectl set-timezone Asia/Shanghai 191 | timedatectl set-ntp yes 192 | ``` 193 | 194 | ### 7.3.安装 FUSE 扩展 195 | 196 | ```shell 197 | mkdir -p /data/seafile-fuse && \ 198 | /opt/seafile/seafile-server-latest/seaf-fuse.sh start /data/seafile-fuse //启动 199 | ./seaf-fuse.sh stop //停止 200 | ``` 201 | 202 | ## 八、了解更多 203 | 204 | 关于`Seafile`更多信息,请访问其官网。 205 | 206 | 更多使用帮助请阅读`wiki`,其他问题欢迎在`issues`中反馈。 -------------------------------------------------------------------------------- /mysql-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 3 | export PATH TERM=xterm 4 | 5 | if [ $(id -u) != "0" ]; then 6 | printf "Error: You must be root to run this script!" 7 | exit 1 8 | fi 9 | 10 | if [ "$(which mysqld)" != '' ];then 11 | echo >&2 'MySQL is already installed!' 12 | exit 1 13 | fi 14 | 15 | clear 16 | echo "#############################################################" 17 | echo "# MySQL Auto Install Script" 18 | echo "# Env: Debian/Ubuntu" 19 | echo "# Intro: http://wangyan.org/" 20 | echo "#" 21 | echo "# Copyright (c) 2016, WangYan " 22 | echo "# All rights reserved." 23 | echo "# Distributed under the GNU General Public License, version 3.0." 24 | echo "#" 25 | echo "#############################################################" 26 | echo 27 | 28 | apt-get update -y && \ 29 | apt-get install -y perl pwgen --no-install-recommends 30 | 31 | if [ "${1:5:1}" != '_' ]; then 32 | echo 33 | echo "Please input the root password of mysql:" 34 | read -p "(Default password is random characters):" MYSQL_ROOT_PASSWORD 35 | if [ -z $MYSQL_ROOT_PASSWORD ]; then 36 | MYSQL_ROOT_PASSWORD="$(pwgen -1 16)" 37 | fi 38 | echo "---------------------------" 39 | echo "MYSQL_ROOT_PASSWORD = $MYSQL_ROOT_PASSWORD" 40 | echo "---------------------------" 41 | echo 42 | fi 43 | 44 | if [ "${1:5:1}" = '_' ]; then 45 | export "$@" 46 | if [ -z "$MYSQL_ROOT_PASSWORD" ]; then 47 | echo 48 | echo >&2 'Did you forget to add PASSWORD=... ?' 49 | exit 1 50 | fi 51 | fi 52 | 53 | echo 54 | echo "---------------------------" 55 | echo "-- MySQL ROOT PASSWORD:" 56 | echo "-- $MYSQL_ROOT_PASSWORD" 57 | echo "---------------------------" 58 | echo 59 | 60 | # Setup MySQL 61 | MYSQL_MAJOR=5.7 62 | MYSQL_VERSION=5.7.14-1ubuntu16.04 63 | 64 | echo "deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-${MYSQL_MAJOR}" >> /etc/apt/sources.list 65 | apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5 66 | 67 | 68 | { \ 69 | echo mysql-community-server mysql-community-server/data-dir select ''; \ 70 | echo mysql-community-server mysql-community-server/root-pass password ''; \ 71 | echo mysql-community-server mysql-community-server/re-root-pass password ''; \ 72 | echo mysql-community-server mysql-community-server/remove-test-db select false; \ 73 | } | debconf-set-selections && \ 74 | apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}" && \ 75 | rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld && \ 76 | chown -R mysql:mysql /var/lib/mysql /var/run/mysqld && \ 77 | chmod 777 /var/run/mysqld 78 | 79 | # MySQL Config 80 | 81 | sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf && \ 82 | echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf && mv /tmp/my.cnf /etc/mysql/my.cnf 83 | 84 | DATADIR="$(mysqld --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')" 85 | 86 | if [ ! -d "$DATADIR/mysql" ]; then 87 | 88 | mkdir -p "$DATADIR" 89 | chown -R mysql:mysql "$DATADIR" 90 | 91 | echo 92 | echo 'Initializing database' 93 | mysqld --initialize-insecure --user=mysql 94 | echo 'Database initialized' 95 | 96 | mysqld --user=mysql --skip-networking --explicit_defaults_for_timestamp & 97 | pid="$!" 98 | 99 | mysql=( mysql --protocol=socket -uroot ) 100 | 101 | for i in {30..0}; do 102 | if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then 103 | break 104 | fi 105 | echo 'MySQL init process in progress...' 106 | sleep 1 107 | done 108 | 109 | if [ "$i" = 0 ]; then 110 | echo >&2 'MySQL init process failed.' 111 | apt-get -y remove mysql-server="${MYSQL_VERSION}" 112 | apt -y autoremove 113 | rm -rf /var/lib/mysql /etc/mysql 114 | exit 1 115 | fi 116 | 117 | "${mysql[@]}" <<-EOSQL 118 | -- What's done in this file shouldn't be replicated 119 | -- or products like mysql-fabric won't work 120 | SET @@SESSION.SQL_LOG_BIN=0; 121 | DELETE FROM mysql.user ; 122 | CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; 123 | GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; 124 | DROP DATABASE IF EXISTS test ; 125 | FLUSH PRIVILEGES ; 126 | EOSQL 127 | 128 | if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then 129 | mysql+=( -p"${MYSQL_ROOT_PASSWORD}" ) 130 | fi 131 | 132 | if [ "$MYSQL_DATABASE" ]; then 133 | echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}" 134 | mysql+=( "$MYSQL_DATABASE" ) 135 | fi 136 | 137 | if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then 138 | echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}" 139 | if [ "$MYSQL_DATABASE" ]; then 140 | echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}" 141 | fi 142 | echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}" 143 | fi 144 | 145 | if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then 146 | "${mysql[@]}" <<-EOSQL 147 | ALTER USER 'root'@'%' PASSWORD EXPIRE; 148 | EOSQL 149 | fi 150 | 151 | if ! kill -s TERM "$pid" || ! wait "$pid"; then 152 | echo >&2 'MySQL init process failed.' 153 | exit 1 154 | fi 155 | 156 | echo 157 | echo 'MySQL init process done. Ready for start up.' 158 | echo 159 | fi 160 | 161 | /etc/init.d/mysql start -------------------------------------------------------------------------------- /seafile-nginx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | # ------------------------------------------- 4 | # NGINX 5 | # ------------------------------------------- 6 | curl -O "http://nginx.org/keys/nginx_signing.key" && \ 7 | apt-key add nginx_signing.key && rm -f nginx_signing.key && \ 8 | echo "deb http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list && \ 9 | echo "deb-src http://nginx.org/packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list && \ 10 | apt-get update && apt-get install -y nginx 11 | 12 | rm -f /etc/nginx/conf.d/* 13 | mkdir -p /etc/nginx/ssl/ 14 | 15 | [ -z $IP_OR_DOMAIN ] && IP_OR_DOMAIN=$(hostname -i) 16 | 17 | cat >/etc/nginx/conf.d/seafile.conf<<'EOF' 18 | server { 19 | listen 80; 20 | server_name "IP_OR_DOMAIN"; 21 | #rewrite ^ https://$http_host$request_uri? permanent; 22 | 23 | proxy_set_header X-Forwarded-For $remote_addr; 24 | 25 | location / { 26 | fastcgi_pass 127.0.0.1:8000; 27 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 28 | fastcgi_param PATH_INFO $fastcgi_script_name; 29 | 30 | fastcgi_param SERVER_PROTOCOL $server_protocol; 31 | fastcgi_param QUERY_STRING $query_string; 32 | fastcgi_param REQUEST_METHOD $request_method; 33 | fastcgi_param CONTENT_TYPE $content_type; 34 | fastcgi_param CONTENT_LENGTH $content_length; 35 | fastcgi_param SERVER_ADDR $server_addr; 36 | fastcgi_param SERVER_PORT $server_port; 37 | fastcgi_param SERVER_NAME $server_name; 38 | fastcgi_param REMOTE_ADDR $remote_addr; 39 | 40 | access_log /var/log/nginx/seahub.access.log; 41 | error_log /var/log/nginx/seahub.error.log; 42 | fastcgi_read_timeout 36000; 43 | } 44 | 45 | location /seafhttp { 46 | rewrite ^/seafhttp(.*)$ $1 break; 47 | proxy_pass http://127.0.0.1:8082; 48 | client_max_body_size 0; 49 | proxy_connect_timeout 36000s; 50 | proxy_read_timeout 36000s; 51 | proxy_send_timeout 36000s; 52 | send_timeout 36000s; 53 | } 54 | 55 | location /media { 56 | root /opt/seafile/seafile-server-latest/seahub; 57 | } 58 | } 59 | 60 | server { 61 | listen 443; 62 | server_name "IP_OR_DOMAIN"; 63 | 64 | ssl on; 65 | ssl_certificate /etc/nginx/ssl/Seafile-CA.pem; 66 | ssl_certificate_key /etc/nginx/ssl/Seafile-KEY.pem; 67 | 68 | ssl_session_cache shared:SSL:1m; 69 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 70 | ssl_session_timeout 5m; 71 | 72 | ssl_ciphers HIGH:!aNULL:!MD5; 73 | ssl_prefer_server_ciphers on; 74 | 75 | location / { 76 | fastcgi_pass 127.0.0.1:8000; 77 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 78 | fastcgi_param PATH_INFO $fastcgi_script_name; 79 | fastcgi_param SERVER_PROTOCOL $server_protocol; 80 | fastcgi_param QUERY_STRING $query_string; 81 | fastcgi_param REQUEST_METHOD $request_method; 82 | fastcgi_param CONTENT_TYPE $content_type; 83 | fastcgi_param CONTENT_LENGTH $content_length; 84 | fastcgi_param SERVER_ADDR $server_addr; 85 | fastcgi_param SERVER_PORT $server_port; 86 | fastcgi_param SERVER_NAME $server_name; 87 | fastcgi_param HTTPS on; 88 | fastcgi_param HTTP_SCHEME https; 89 | 90 | access_log /var/log/nginx/seahub.access.log; 91 | error_log /var/log/nginx/seahub.error.log; 92 | } 93 | 94 | location /seafhttp { 95 | rewrite ^/seafhttp(.*)$ $1 break; 96 | proxy_pass http://127.0.0.1:8082; 97 | client_max_body_size 0; 98 | proxy_connect_timeout 36000s; 99 | proxy_read_timeout 36000s; 100 | } 101 | 102 | location /media { 103 | root /opt/seafile/seafile-server-latest/seahub; 104 | } 105 | 106 | location /seafdav { 107 | fastcgi_pass 127.0.0.1:8080; 108 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 109 | fastcgi_param PATH_INFO $fastcgi_script_name; 110 | fastcgi_param SERVER_PROTOCOL $server_protocol; 111 | fastcgi_param QUERY_STRING $query_string; 112 | fastcgi_param REQUEST_METHOD $request_method; 113 | fastcgi_param CONTENT_TYPE $content_type; 114 | fastcgi_param CONTENT_LENGTH $content_length; 115 | fastcgi_param SERVER_ADDR $server_addr; 116 | fastcgi_param SERVER_PORT $server_port; 117 | fastcgi_param SERVER_NAME $server_name; 118 | 119 | client_max_body_size 0; 120 | 121 | access_log /var/log/nginx/seafdav.access.log; 122 | error_log /var/log/nginx/seafdav.error.log; 123 | } 124 | } 125 | EOF 126 | 127 | sed -i 's/IP_OR_DOMAIN/'$IP_OR_DOMAIN'/g' /etc/nginx/conf.d/seafile.conf 128 | 129 | cat > /etc/nginx/ssl/Seafile-CA.pem <<'EOF' 130 | -----BEGIN CERTIFICATE----- 131 | MIIDNTCCAh2gAwIBAgIJAKhzGE4s6v2dMA0GCSqGSIb3DQEBCwUAMDExCzAJBgNV 132 | BAYTAkNOMRAwDgYDVQQIDAdTZWFmaWxlMRAwDgYDVQQKDAdTZWFmaWxlMB4XDTE2 133 | MDMwMjE0MDcwN1oXDTE5MDMwMjE0MDcwN1owMTELMAkGA1UEBhMCQ04xEDAOBgNV 134 | BAgMB1NlYWZpbGUxEDAOBgNVBAoMB1NlYWZpbGUwggEiMA0GCSqGSIb3DQEBAQUA 135 | A4IBDwAwggEKAoIBAQDYzI49Lkp9syjTwQaTbcK0PkuBNwuoQQHErrdPH0phmKtX 136 | TjGSqCGyV1mHv1k/Dy17zEOFvSmLucnruk/wllDSIPDvnsdKkIplDMx9U755ckvA 137 | W2IjywyajlttqO1l1bMyxemrevJ3kBRuMUTjiAq+PVx5CU+mg7XPdIUofFu8dWbA 138 | e5MVZhOKdRwekj4PseRloLOzc4h9YdxiGqb6O9di3gMF4U4TLDT8exUxMbyUnWRv 139 | N6NFTwasxObkc0ba+3OCI1IunWNQuk0N4JqWlQTUrQ3zKohd34D9VZfsAXiZpwEk 140 | Axx+CJ1Y+yXO/IR4P5z5VIhnjG7z+w20wb6ISGW5AgMBAAGjUDBOMB0GA1UdDgQW 141 | BBR5RcNzAiD1wpEcx/9KUCLPVSvMfjAfBgNVHSMEGDAWgBR5RcNzAiD1wpEcx/9K 142 | UCLPVSvMfjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQA+UtYj2m9s 143 | Fz6oV5vpkr1kjPBv5OPG2E3IDq7OISOXETQYCJ7i/s8Wbx3LW2RA7Xfu4+LCtmri 144 | wAyEc+uqBkhm+epXxdoLZrhTwVTTTOBxAekxriRZpe+ebwRYClFFcxYSBLrMPUDK 145 | E7AE3hE7+R5VcYI0osIZNQdim3DtHtWHJt2fnZhRJdRicTplIm7K79hqrFl3hYte 146 | 2L0OPsqiXaG7SC3eO8Qp42w0BZzBBNzmPk1OYHooBDdGuhdCDzqIdFEQaXUm5/Dt 147 | 2j1lX3VBWmbkPt4GcB4GiOkYm5DP9PsUQZ4TH7TtwoYLoDLflPcsQ3kd/c+Bjrsr 148 | DVSG1NHj8xA1 149 | -----END CERTIFICATE----- 150 | EOF 151 | 152 | cat > /etc/nginx/ssl/Seafile-KEY.pem <<'EOF' 153 | -----BEGIN RSA PRIVATE KEY----- 154 | MIIEpAIBAAKCAQEA2MyOPS5KfbMo08EGk23CtD5LgTcLqEEBxK63Tx9KYZirV04x 155 | kqghsldZh79ZPw8te8xDhb0pi7nJ67pP8JZQ0iDw757HSpCKZQzMfVO+eXJLwFti 156 | I8sMmo5bbajtZdWzMsXpq3ryd5AUbjFE44gKvj1ceQlPpoO1z3SFKHxbvHVmwHuT 157 | FWYTinUcHpI+D7HkZaCzs3OIfWHcYhqm+jvXYt4DBeFOEyw0/HsVMTG8lJ1kbzej 158 | RU8GrMTm5HNG2vtzgiNSLp1jULpNDeCalpUE1K0N8yqIXd+A/VWX7AF4macBJAMc 159 | fgidWPslzvyEeD+c+VSIZ4xu8/sNtMG+iEhluQIDAQABAoIBAGeT+1URm7dIdHYO 160 | 36RqKT7SEGLQuLoPLNgaHSwpJ/FO7nWMvzRxLYA2KWkoq2vsRW/DHHN197Zw8h60 161 | aeLo/f4WjOX+tvpR6jzzC3PJIdSGHdjuEApHxWLGJrpSnfEsUywr0EMEP3mOFaS7 162 | 10zZv0A6ssaFA0/r114hLkk0eOOlVm1q1o445oQBYCIhW8j1P2enTOrdc7hz91U7 163 | 0BLN/9lRo1W23YCQsz9aMoUj7S3TBD1i7LVq5P28MI5N3GiqJQnvVHo9qE9ggAf+ 164 | hI4G1j6cI6JO5MyUeqjbhKDIjHeO1Do09Y01tM4eDC9FPF+5FSmDaOmNbF7IVIFz 165 | Nba10V0CgYEA7ilDE0GRvYaouPLMT37c9oLBLgU4azRlhb0oVxIhXjyVP6e//rW/ 166 | 6iu5S/x0UyEMW8naLbE7zijR0eQnkQa6sJlIRNlQSBhb2Fb4JYFDuh3N8ZBQDkoj 167 | ZQkRhtzVZGdHhWfLutRBdj4zJ20h6hKYcsSMKkWqT+p7mCfUheqf58sCgYEA6Qms 168 | x3k+TLP+Mdc+yFtFLu1sMcjuS7OFpgxje3zyl+Wj9ieFTRztwumyzOHptxwIQZrq 169 | LSTiWWcJnvnZgGLfDUtoGgzq6FclJ6a5IUQnpijiHh+9e9bYdjTrqc9MrLplNVS/ 170 | PI8W2DDfxGMRlwM1sMdoON/b6HfxOfcej+2uUAsCgYEAsGexvi6gI9D9Yli9Sti+ 171 | FH2PV2YYfxfFZwVQPwY33xRivE6loKXA7FPMoWLySqy8+bQOvi98C90iZSRoxjxE 172 | xhATfqO0mmIojZsFnModf1saMyZgleUGSI0qBUnHaeIyELdsKQuVHV8/BqIIL9fs 173 | QX4iECGf4Cffujkuaq76GHcCgYEA0SSGtSsh93Leolp8FRKcn4YjQPcErln6i1C5 174 | A73adup44VUMtG1PEUvt1SS3PUfiPQbMPiHJJtVrdArl4exaJLNVRXPsawKy7Mgb 175 | hDiHoP82GDUCOJ9T+5p5GhhaxvYuGNPrIW2F4hbS7IzA35fY2sPLzKdT1Gm4y/31 176 | ptR4SYsCgYA7aWUKa+SLyDWxGjv5aKWuMnTgV7Wjjbt1D7pjKeOMJrcYIiHmAKqG 177 | ji3fQNQLlBAWcWejUxUBmRUivjm0zvcozvGEv/CUCqBndzZacdjD00QG94KI2xAU 178 | NIhWl6NEtaFHkvfKo489yCmh607EtF/I/xuohH5hHfsMDCVdVbqETw== 179 | -----END RSA PRIVATE KEY----- 180 | EOF 181 | 182 | # APT Clean 183 | apt -y autoremove && apt-get clean && \ 184 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -------------------------------------------------------------------------------- /seafile-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 3 | export PATH TERM=xterm 4 | set -x 5 | # ------------------------------------------- 6 | # Vars Don't touch these unless you really know what you are doing! 7 | # ------------------------------------------- 8 | SEAFILE_VERSION=$(ls /opt/seafile/installed/ | awk -F_ '{print $2}') 9 | INSTALLPATH=/opt/seafile/seafile-server-${SEAFILE_VERSION} 10 | TOPDIR=$(dirname "${INSTALLPATH}") 11 | ##--Create conf/ccnet.conf--## 12 | CCNET_INIT=${INSTALLPATH}/seafile/bin/ccnet-init 13 | DEFAULT_CONF_DIR=${TOPDIR}/conf 14 | #--Generate conf/seahub_settings.py--## 15 | SEAHUB_SECRET_KEYGEN=${INSTALLPATH}/seahub/tools/secret_key_generator.py 16 | DEST_SETTINGS_PY=${TOPDIR}/conf/seahub_settings.py 17 | ##--Create ccnet/seafile.ini--## 18 | SEAFILE_DATA_DIR=${TOPDIR}/seafile-data 19 | DEFAULT_CCNET_CONF_DIR=${TOPDIR}/ccnet 20 | ##--Create conf/seafile.conf--## 21 | SEAF_SERVER_INIT=${INSTALLPATH}/seafile/bin/seaf-server-init 22 | FILESERVER_PORT=8082 23 | #--prepare avatar directory--## 24 | ORIG_AVATAR_DIR=${INSTALLPATH}/seahub/media/avatars 25 | DEST_AVATAR_DIR=${TOPDIR}/seahub-data/avatars 26 | MEDIA_DIR=${INSTALLPATH}/seahub/media 27 | #--Create symlink for current server version--## 28 | SEAFILE_SERVER_SYMLINK=${TOPDIR}/seafile-server-latest 29 | # copy user manuals to library template 30 | LIBRARY_TEMPLATE_DIR=${SEAFILE_DATA_DIR}/library-template 31 | SRC_DOCS_DIR=${INSTALLPATH}/seafile/docs/ 32 | 33 | # ------------------------------------------- 34 | # Seafile DB 35 | # ------------------------------------------- 36 | 37 | SEAFILE_SQL_USER=$(mysql -hmysql -p$MYSQL_PORT_3306_TCP_PORT -uroot -p$MYSQL_ENV_MYSQL_ROOT_PASSWORD -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'seafile')") 38 | 39 | if [ "$SEAFILE_SQL_USER" = "1" ];then 40 | mysql -hmysql -p$MYSQL_PORT_3306_TCP_PORT -uroot -p$MYSQL_ENV_MYSQL_ROOT_PASSWORD -sse "DROP USER 'seafile'@'%'" 41 | fi 42 | 43 | [ -z "$SQLSEAFILEPW" ] && SQLSEAFILEPW=$(pwgen) 44 | 45 | cat >/tmp/create_tables.sql<<-EOF 46 | DROP DATABASE IF EXISTS seafile_ccnet; 47 | DROP DATABASE IF EXISTS seafile_db; 48 | DROP DATABASE IF EXISTS seafile_seahub; 49 | CREATE DATABASE IF NOT EXISTS seafile_ccnet character set = 'utf8'; 50 | CREATE DATABASE IF NOT EXISTS seafile_db character set = 'utf8'; 51 | CREATE DATABASE IF NOT EXISTS seafile_seahub character set = 'utf8'; 52 | CREATE USER 'seafile'@'%' IDENTIFIED BY '$SQLSEAFILEPW'; 53 | GRANT ALL PRIVILEGES ON seafile_ccnet.* TO 'seafile'@'%'; 54 | GRANT ALL PRIVILEGES ON seafile_db.* TO 'seafile'@'%'; 55 | GRANT ALL PRIVILEGES ON seafile_seahub.* TO 'seafile'@'%'; 56 | EOF 57 | 58 | mysql -hmysql -p$MYSQL_PORT_3306_TCP_PORT -uroot -p$MYSQL_ENV_MYSQL_ROOT_PASSWORD <> ${DEFAULT_CONF_DIR}/ccnet.conf < ${DEFAULT_CONF_DIR}/seafdav.conf < "${DEST_SETTINGS_PY}" 108 | 109 | # ------------------------------------------- 110 | # Configuring conf/seahub_settings.py 111 | # ------------------------------------------- 112 | cat >> ${DEST_SETTINGS_PY} < "${DEFAULT_CCNET_CONF_DIR}/seafile.ini" 140 | 141 | # ------------------------------------------- 142 | # Create conf/seafile.conf 143 | # ------------------------------------------- 144 | LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${SEAF_SERVER_INIT} --seafile-dir "${DEFAULT_CONF_DIR}" \ 145 | --fileserver-port ${FILESERVER_PORT} 146 | 147 | # ------------------------------------------- 148 | # Configuring conf/seafile.conf 149 | # ------------------------------------------- 150 | cat >> ${DEFAULT_CONF_DIR}/seafile.conf </etc/init.d/seafile<<'EOF' 221 | #!/bin/sh 222 | 223 | ### BEGIN INIT INFO 224 | # Provides: seafile 225 | # Required-Start: $local_fs $remote_fs $network mysql 226 | # Required-Stop: $local_fs 227 | # Default-Start: 2 3 4 5 228 | # Default-Stop: 0 1 6 229 | # Short-Description: Starts Seafile Server 230 | # Description: starts Seafile Server 231 | ### END INIT INFO 232 | 233 | seafile_dir=/opt/seafile 234 | script_path=${seafile_dir}/seafile-server-latest 235 | seafile_init_log=${seafile_dir}/logs/seafile.init.log 236 | seahub_init_log=${seafile_dir}/logs/seahub.init.log 237 | 238 | fastcgi=true 239 | fastcgi_port=8000 240 | 241 | echo -e "\n \n About to perform $1 for seafile at `date -Iseconds` \n " >> ${seafile_init_log} 242 | echo -e "\n \n About to perform $1 for seahub at `date -Iseconds` \n " >> ${seahub_init_log} 243 | 244 | case "$1" in 245 | start) 246 | ${script_path}/seafile.sh ${1} >> ${seafile_init_log} 247 | if [ $fastcgi = true ]; 248 | then 249 | ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log} 250 | else 251 | ${script_path}/seahub.sh ${1} >> ${seahub_init_log} 252 | fi 253 | ;; 254 | restart) 255 | ${script_path}/seafile.sh ${1} >> ${seafile_init_log} 256 | if [ $fastcgi = true ]; 257 | then 258 | ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log} 259 | else 260 | ${script_path}/seahub.sh ${1} >> ${seahub_init_log} 261 | fi 262 | ;; 263 | stop) 264 | ${script_path}/seahub.sh ${1} >> ${seahub_init_log} 265 | ${script_path}/seafile.sh ${1} >> ${seafile_init_log} 266 | ;; 267 | *) 268 | echo "Usage: /etc/init.d/seafile {start|stop|restart}" 269 | exit 1 270 | ;; 271 | esac 272 | EOF 273 | 274 | chmod +x /etc/init.d/seafile -------------------------------------------------------------------------------- /seafile-setup-mysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 3 | export PATH TERM=xterm 4 | set -x 5 | clear 6 | echo "#############################################################" 7 | echo "# Seafile Auto Setup Script" 8 | echo "# Env: Debian/Ubuntu" 9 | echo "# Intro: http://wangyan.org/" 10 | echo "#" 11 | echo "# Copyright (c) 2016, WangYan " 12 | echo "# All rights reserved." 13 | echo "# Distributed under the GNU General Public License, version 3.0." 14 | echo "#" 15 | echo "#############################################################" 16 | echo 17 | 18 | # ------------------------------------------- 19 | # Vars Don't touch these unless you really know what you are doing! 20 | # ------------------------------------------- 21 | SEAFILE_VERSION=$(ls /opt/seafile/installed/ | awk -F_ '{print $2}') 22 | INSTALLPATH=/opt/seafile/seafile-server-${SEAFILE_VERSION} 23 | TOPDIR=$(dirname "${INSTALLPATH}") 24 | ##--Create conf/ccnet.conf--## 25 | CCNET_INIT=${INSTALLPATH}/seafile/bin/ccnet-init 26 | DEFAULT_CONF_DIR=${TOPDIR}/conf 27 | #--Generate conf/seahub_settings.py--## 28 | SEAHUB_SECRET_KEYGEN=${INSTALLPATH}/seahub/tools/secret_key_generator.py 29 | DEST_SETTINGS_PY=${TOPDIR}/conf/seahub_settings.py 30 | ##--Create ccnet/seafile.ini--## 31 | SEAFILE_DATA_DIR=${TOPDIR}/seafile-data 32 | DEFAULT_CCNET_CONF_DIR=${TOPDIR}/ccnet 33 | ##--Create conf/seafile.conf--## 34 | SEAF_SERVER_INIT=${INSTALLPATH}/seafile/bin/seaf-server-init 35 | FILESERVER_PORT=8082 36 | #--prepare avatar directory--## 37 | ORIG_AVATAR_DIR=${INSTALLPATH}/seahub/media/avatars 38 | DEST_AVATAR_DIR=${TOPDIR}/seahub-data/avatars 39 | MEDIA_DIR=${INSTALLPATH}/seahub/media 40 | #--Create symlink for current server version--## 41 | SEAFILE_SERVER_SYMLINK=${TOPDIR}/seafile-server-latest 42 | # copy user manuals to library template 43 | LIBRARY_TEMPLATE_DIR=${SEAFILE_DATA_DIR}/library-template 44 | SRC_DOCS_DIR=${INSTALLPATH}/seafile/docs/ 45 | 46 | # ------------------------------------------- 47 | # Seafile DB 48 | # ------------------------------------------- 49 | 50 | SEAFILE_SQL_USER=$(mysql -h127.0.0.1 -p3306 -uroot -p$MYSQL_ROOT_PASSWORD -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'seafile')") 51 | 52 | if [ "$SEAFILE_SQL_USER" = "1" ];then 53 | mysql -h127.0.0.1 -p3306 -uroot -p$MYSQL_ROOT_PASSWORD -sse "DROP USER 'seafile'@'%'" 54 | fi 55 | 56 | [ -z "$SQLSEAFILEPW" ] && SQLSEAFILEPW=$(pwgen) 57 | 58 | cat >/tmp/create_tables.sql<<-EOF 59 | DROP DATABASE IF EXISTS seafile_ccnet; 60 | DROP DATABASE IF EXISTS seafile_db; 61 | DROP DATABASE IF EXISTS seafile_seahub; 62 | CREATE DATABASE IF NOT EXISTS seafile_ccnet character set = 'utf8'; 63 | CREATE DATABASE IF NOT EXISTS seafile_db character set = 'utf8'; 64 | CREATE DATABASE IF NOT EXISTS seafile_seahub character set = 'utf8'; 65 | CREATE USER 'seafile'@'%' IDENTIFIED BY '$SQLSEAFILEPW'; 66 | GRANT ALL PRIVILEGES ON seafile_ccnet.* TO 'seafile'@'%'; 67 | GRANT ALL PRIVILEGES ON seafile_db.* TO 'seafile'@'%'; 68 | GRANT ALL PRIVILEGES ON seafile_seahub.* TO 'seafile'@'%'; 69 | EOF 70 | 71 | mysql -h127.0.0.1 -p3306 -uroot -p$MYSQL_ROOT_PASSWORD <> ${DEFAULT_CONF_DIR}/ccnet.conf < ${DEFAULT_CONF_DIR}/seafdav.conf < "${DEST_SETTINGS_PY}" 121 | 122 | # ------------------------------------------- 123 | # Configuring conf/seahub_settings.py 124 | # ------------------------------------------- 125 | cat >> ${DEST_SETTINGS_PY} < "${DEFAULT_CCNET_CONF_DIR}/seafile.ini" 153 | 154 | # ------------------------------------------- 155 | # Create conf/seafile.conf 156 | # ------------------------------------------- 157 | LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${SEAF_SERVER_INIT} --seafile-dir "${DEFAULT_CONF_DIR}" \ 158 | --fileserver-port ${FILESERVER_PORT} 159 | 160 | # ------------------------------------------- 161 | # Configuring conf/seafile.conf 162 | # ------------------------------------------- 163 | cat >> ${DEFAULT_CONF_DIR}/seafile.conf </etc/init.d/seafile<<'EOF' 234 | #!/bin/sh 235 | 236 | ### BEGIN INIT INFO 237 | # Provides: seafile 238 | # Required-Start: $local_fs $remote_fs $network mysql 239 | # Required-Stop: $local_fs 240 | # Default-Start: 2 3 4 5 241 | # Default-Stop: 0 1 6 242 | # Short-Description: Starts Seafile Server 243 | # Description: starts Seafile Server 244 | ### END INIT INFO 245 | 246 | seafile_dir=/opt/seafile 247 | script_path=${seafile_dir}/seafile-server-latest 248 | seafile_init_log=${seafile_dir}/logs/seafile.init.log 249 | seahub_init_log=${seafile_dir}/logs/seahub.init.log 250 | 251 | fastcgi=true 252 | fastcgi_port=8000 253 | 254 | echo -e "\n \n About to perform $1 for seafile at `date -Iseconds` \n " >> ${seafile_init_log} 255 | echo -e "\n \n About to perform $1 for seahub at `date -Iseconds` \n " >> ${seahub_init_log} 256 | 257 | case "$1" in 258 | start) 259 | ${script_path}/seafile.sh ${1} >> ${seafile_init_log} 260 | if [ $fastcgi = true ]; 261 | then 262 | ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log} 263 | else 264 | ${script_path}/seahub.sh ${1} >> ${seahub_init_log} 265 | fi 266 | ;; 267 | restart) 268 | ${script_path}/seafile.sh ${1} >> ${seafile_init_log} 269 | if [ $fastcgi = true ]; 270 | then 271 | ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log} 272 | else 273 | ${script_path}/seahub.sh ${1} >> ${seahub_init_log} 274 | fi 275 | ;; 276 | stop) 277 | ${script_path}/seahub.sh ${1} >> ${seahub_init_log} 278 | ${script_path}/seafile.sh ${1} >> ${seafile_init_log} 279 | ;; 280 | *) 281 | echo "Usage: /etc/init.d/seafile {start|stop|restart}" 282 | exit 1 283 | ;; 284 | esac 285 | EOF 286 | 287 | chmod +x /etc/init.d/seafile --------------------------------------------------------------------------------