diff --git a/README.md b/README.md index c18603f..0cf50a9 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,20 @@ ### 使用步骤 -安装干净的 Ubuntu 14.04 系统并切换成 root 账号 (sudo -i)。 +安装干净的 Ubuntu 14.04 或 CentOS 7 系统并切换成 root 账号 (sudo -i)。 获取安装脚本 +Ubuntu 14.04: ``` wget https://raw.githubusercontent.com/haiwen/seafile-server-installer-cn/master/seafile-server-ubuntu-14-04-amd64-http ``` +CentOS 7: +``` +wget https://raw.githubusercontent.com/haiwen/seafile-server-installer-cn/master/seafile-server-centos-7-amd64-http +``` + 运行安装脚本并指定要安装的版本 (5.0.2) ``` @@ -24,7 +30,7 @@ bash seafile-server-ubuntu-14-04-amd64-http 5.0.2 * 如果要安装专业版, 需要先将下载好的专业版的包 `seafile-pro-server_5.0.1_x86-64.tar.gz` 放到 `/opt/` 目录下 * 如果是安装开源版,安装脚本在执行过程中会检查**/opt**目录下是否有指定版本号的安装包,如果存在则会安装此包,否则会从 Seafile 网站下载。所以,为了避免因下载失败而导致安装中断,您可以提前下载好安装包放到**/opt/**目录下。 -该脚本运行完后会在命令行中打印配置信息和管理员账号密码,请仔细阅读。(你也可以查看安装日志 /opt/seafile/aio_seafile-server.log) +该脚本运行完后会在命令行中打印配置信息和管理员账号密码,请仔细阅读。(你也可以查看安装日志 /aio_seafile-server.log) #### 通过 Web UI 对服务器进行配置 @@ -56,9 +62,20 @@ rm -rf /opt/seafile 自动安装脚本会在系统中安装开机自动启动脚本。您也可以使用该脚本来关闭/启动 Seafile 服务,命令如下: - service seafile-server stop - service seafile-server start +Ubuntu 14.04: +``` +service seafile-server stop +service seafile-server start +``` +CentOS 7: +``` +service seafile stop +service seahub stop + +service seafile start +service seahub start +``` ## 其他高级配置 @@ -66,7 +83,7 @@ rm -rf /opt/seafile * 拷贝 `db-backup` 目录到 `/opt/seafile` * 修改 `db-backup/db_backup.sh` 中的 `USER` `PASSWD` -* 执行 `crontab -e` 并添加内容 `0 1 * * * * /opt/seafile/db-backup/db_backup.sh` (每天凌晨1:00进行备份) +* 执行 `crontab -e` 并添加内容 `0 1 * * * /opt/seafile/db-backup/db_backup.sh` (每天凌晨1:00进行备份) ### 配置邮件发送 @@ -77,19 +94,15 @@ rm -rf /opt/seafile ### 版本升级 * 切换为 root 用户 -* 关闭 seafile-server 相关服务:service seafile-server stop -* 切换为 seafile 用户:su - seafile -s /bin/bash +* 关闭 seafile-server 相关服务 * 下载高版本的安装包到 /opt/seafile 目录,并解压 * 进入安装包下的 upgrade 目录,执行相关的升级脚本,具体可参考 http://manual.seafile.com/deploy/upgrade.html -* 退出 seafile 用户:exit -* 启动 seafile-server 相关服务:service seafile-server start +* 启动 seafile-server 相关服务 ### 迁移社区版到专业版 * 切换为 root 用户 -* 关闭 seafile-server 相关服务:service seafile-server stop -* 切换为 seafile 用户:su - seafile -s /bin/bash +* 关闭 seafile-server 相关服务 * 下载专业版安装包到 /opt/seafile 目录,并解压 * 进入解压好的安装包目录,执行 ./pro/pro.py setup --migrate,具体可参考 http://manual.seafile.com/deploy_pro/migrate_from_seafile_community_server.html -* 退出 seafile 用户:exit -* 启动 seafile-server 相关服务:service seafile-server start +* 启动 seafile-server 相关服务 diff --git a/seafile-server-centos-7-amd64-http b/seafile-server-centos-7-amd64-http new file mode 100644 index 0000000..08f1473 --- /dev/null +++ b/seafile-server-centos-7-amd64-http @@ -0,0 +1,558 @@ +#!/bin/bash +# +# seafile-server-installer/seafile-server-centos-7-amd64 +# +# Copyright 2015, Alexander Jackson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# + +if [[ $HOME == "" ]]; then + export HOME=/root +fi + +if [[ $SEAFILE_DEBUG != "" ]]; then + set -x +fi +set -e + +if [[ "$#" -ne 1 ]]; then + echo "You must specif Seafile version to install" + echo "Like: $0 4.4.2" + exit 1 +fi + +clear +cat < /etc/nginx/conf.d/seafile.conf <<'EOF' +server { + listen 80; + server_name ""; + + location / { + fastcgi_pass 127.0.0.1:8000; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_script_name; + fastcgi_param SERVER_PROTOCOL $server_protocol; + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param SERVER_ADDR $server_addr; + fastcgi_param SERVER_PORT $server_port; + fastcgi_param SERVER_NAME $server_name; + + access_log /var/log/nginx/seahub.access.log; + error_log /var/log/nginx/seahub.error.log; + } + location /seafhttp { + rewrite ^/seafhttp(.*)$ $1 break; + proxy_pass http://127.0.0.1:8082; + client_max_body_size 0; + proxy_connect_timeout 36000s; + proxy_read_timeout 36000s; + } + location /media { + root /opt/seafile/seafile-server-latest/seahub; + } + location /seafdav { + fastcgi_pass 127.0.0.1:8080; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_script_name; + fastcgi_param SERVER_PROTOCOL $server_protocol; + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param SERVER_ADDR $server_addr; + fastcgi_param SERVER_PORT $server_port; + fastcgi_param SERVER_NAME $server_name; + + client_max_body_size 0; + + access_log /var/log/nginx/seafdav.access.log; + error_log /var/log/nginx/seafdav.error.log; + } +} +EOF + +# Create optimized nginx.conf +cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup +cat > /etc/nginx/nginx.conf <<'ENDOFFILE' +user nginx nginx; +worker_processes 4; + +events { + worker_connections 8096; + multi_accept on; + use epoll; +} + +pid /var/run/nginx.pid; +worker_rlimit_nofile 40000; + +http { + server_tokens off; + server_names_hash_bucket_size 128; + client_max_body_size 50M; + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + error_log /var/log/nginx/error.log warn; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + client_body_timeout 12; + client_header_timeout 12; + keepalive_timeout 15; + send_timeout 10; + # Fully disabled gzip compression to mitigate Django BREACH attack: https://www.djangoproject.com/weblog/2013/aug/06/breach-and-django/ + gzip off; + #gzip_vary on; + #gzip_proxied expired no-cache no-store private auth any; + #gzip_comp_level 9; + #gzip_min_length 10240; + #gzip_buffers 16 8k; + #gzip_http_version 1.1; + #gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/xml font/woff2; + #gzip_disable "MSIE [1-6]."; + include /etc/nginx/conf.d/*.conf; +} +ENDOFFILE +systemctl restart nginx + +# ------------------------------------------- +# MariaDB +# ------------------------------------------- +if [[ -f "/root/.my.cnf" ]] ; +then + echo "MariaDB installed before, skip this part" +else + yum install mariadb-server -y + systemctl start mariadb + systemctl enable mariadb + + SQLROOTPW=$(pwgen) + + mysqladmin -u root password $SQLROOTPW + + cat > /root/.my.cnf < /etc/systemd/system/seafile.service <<'EOF' +[Unit] +Description=Seafile Server +After=network.target mariadb.service + +[Service] +Type=oneshot +ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start +ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop +RemainAfterExit=yes +User=root +Group=root + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable seafile + +cat > /etc/systemd/system/seahub.service <<'EOF' +[Unit] +Description=Seafile Seahub +After=network.target seafile.service + +[Service] +ExecStart=/opt/seafile/seafile-server-latest/seahub.sh start-fastcgi 8000 +ExecStop=/opt/seafile/seafile-server-latest/seahub.sh stop +User=root +Group=root +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable seahub + +# Seafile restart script +cat > /usr/local/sbin/seafile-server-restart << 'EOF' +#!/bin/bash +for ACTION in stop start ; do + for SERVICE in seafile seahub ; do + systemctl ${ACTION} ${SERVICE} + done +done +EOF +chmod 700 /usr/local/sbin/seafile-server-restart + +# ------------------------------------------- +# Seafile +# ------------------------------------------- +mkdir -p /opt/seafile/installed +cd /opt/seafile/ +if ! is_pro && [[ ! -e /opt/${SEAFILE_SERVER_PACKAGE} ]]; then + curl -OL ${SEAFILE_SERVER_PACKAGE_URL} +else + cp /opt/${SEAFILE_SERVER_PACKAGE} . +fi +tar xzf ${SEAFILE_SERVER_PACKAGE} + +mv ${SEAFILE_SERVER_PACKAGE} installed + + +# ------------------------------------------- +# Seafile DB +# ------------------------------------------- +SQLSEAFILEPW=$(pwgen) + +cat > /opt/seafile/.my.cnf <> ${DEST_SETTINGS_PY} < ${seafile_dir}/aio_seafile-server.log< # @@ -99,11 +99,8 @@ echo # Vars # ------------------------------------------- SEAFILE_ADMIN=admin@seafile.local -SEAFILE_USER=seafile SERVER_NAME=$(hostname -s) IP_OR_DOMAIN=$(hostname -i) -HOSTNAME=$(hostname -i) -FILESERVER_PORT=8082 SEAFILE_VERSION=$1 TIME_ZONE=Asia/Shanghai @@ -245,10 +242,6 @@ cat > /etc/init.d/seafile-server <<'EOF' ### END INIT INFO # Author: Alexander Jackson -# - -# Change the value of "user" to your linux user name -user=seafile # Change the value of "seafile_dir" to your path of seafile installation seafile_dir=/opt/seafile @@ -263,26 +256,26 @@ fastcgi_port=8000 case "$1" in start) - sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log} + ${script_path}/seafile.sh start >> ${seafile_init_log} if [ $fastcgi = true ]; then - sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} + ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} else - sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log} + ${script_path}/seahub.sh start >> ${seahub_init_log} fi ;; restart) - sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log} + ${script_path}/seafile.sh restart >> ${seafile_init_log} if [ $fastcgi = true ]; then - sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log} + ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log} else - sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log} + ${script_path}/seahub.sh restart >> ${seahub_init_log} fi ;; stop) - sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log} - sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log} + ${script_path}/seafile.sh $1 >> ${seafile_init_log} + ${script_path}/seahub.sh $1 >> ${seahub_init_log} ;; *) echo "Usage: /etc/init.d/seafile-server {start|stop|restart}" @@ -298,7 +291,6 @@ update-rc.d seafile-server defaults # ------------------------------------------- # Seafile # ------------------------------------------- -adduser --system --gecos "${SEAFILE_USER}" ${SEAFILE_USER} --home /opt/seafile mkdir -p /opt/seafile/installed cd /opt/seafile/ if ! is_pro && [[ ! -e /opt/${SEAFILE_SERVER_PACKAGE} ]]; then @@ -323,17 +315,6 @@ password=$SQLSEAFILEPW EOF chmod 600 /opt/seafile/.my.cnf -chown -R ${SEAFILE_USER}.nogroup /opt/seafile/ - -mysql -e "CREATE DATABASE IF NOT EXISTS \`ccnet-db\` character set = 'utf8';" -mysql -e "CREATE DATABASE IF NOT EXISTS \`seafile-db\` character set = 'utf8';" -mysql -e "CREATE DATABASE IF NOT EXISTS \`seahub-db\` character set = 'utf8';" -mysql -e "create user 'seafile'@'localhost' identified by '$SQLSEAFILEPW';" -mysql -e "GRANT ALL PRIVILEGES ON \`ccnet-db\`.* to \`seafile\`@localhost;" -mysql -e "GRANT ALL PRIVILEGES ON \`seafile-db\`.* to \`seafile\`@localhost;" -mysql -e "GRANT ALL PRIVILEGES ON \`seahub-db\`.* to \`seafile\`@localhost;" -mysql seahub-db < ${INSTALLPATH}/seahub/sql/mysql.sql - # ------------------------------------------- # Go to /opt/seafile/seafile-pro-server-${SEAFILE_VERSION} @@ -344,149 +325,30 @@ cd $INSTALLPATH # Vars - Don't touch these unless you really know what you are doing! # ------------------------------------------- TOPDIR=$(dirname "${INSTALLPATH}") -SRC_DOCS_DIR=${INSTALLPATH}/seafile/docs/ -SEAHUB_SECRET_KEYGEN=${INSTALLPATH}/seahub/tools/secret_key_generator.py -DEFAULT_CCNET_CONF_DIR=${TOPDIR}/ccnet -DEFAULT_SEAFILE_DATA_DIR=${TOPDIR}/seafile-data DEFAULT_CONF_DIR=${TOPDIR}/conf SEAFILE_DATA_DIR=${TOPDIR}/seafile-data -LIBRARY_TEMPLATE_DIR=${SEAFILE_DATA_DIR}/library-template DEST_SETTINGS_PY=${TOPDIR}/conf/seahub_settings.py -CCNET_INIT=${INSTALLPATH}/seafile/bin/ccnet-init -SEAF_SERVER_INIT=${INSTALLPATH}/seafile/bin/seaf-server-init -MEDIA_DIR=${INSTALLPATH}/seahub/media -ORIG_AVATAR_DIR=${INSTALLPATH}/seahub/media/avatars -DEST_AVATAR_DIR=${TOPDIR}/seahub-data/avatars -SEAFILE_SERVER_SYMLINK=${TOPDIR}/seafile-server-latest mkdir -p ${DEFAULT_CONF_DIR} # ------------------------------------------- -# Create ccnet conf +# Create ccnet, seafile, seahub conf using setup script # ------------------------------------------- -export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH} -LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH "${CCNET_INIT}" -c "${DEFAULT_CCNET_CONF_DIR}" \ - --name "${SERVER_NAME}" --host "${IP_OR_DOMAIN}" -F "${DEFAULT_CONF_DIR}" - -# Fix service url -eval "sed -i 's/^SERVICE_URL.*/SERVICE_URL = http:\/\/${IP_OR_DOMAIN}/' ${DEFAULT_CONF_DIR}/ccnet.conf" - - -# ------------------------------------------- -# Create seafile conf -# ------------------------------------------- -LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${SEAF_SERVER_INIT} --seafile-dir "${SEAFILE_DATA_DIR}" \ - --fileserver-port ${FILESERVER_PORT} -F "${DEFAULT_CONF_DIR}" - - -# ------------------------------------------- -# Write seafile.ini -# ------------------------------------------- -echo "${SEAFILE_DATA_DIR}" > "${DEFAULT_CCNET_CONF_DIR}/seafile.ini" +./setup-seafile-mysql.sh auto -u seafile -w ${SQLSEAFILEPW} -r ${SQLROOTPW} # ------------------------------------------- # Configure Seafile WebDAV Server(SeafDAV) # ------------------------------------------- -cat > ${DEFAULT_CONF_DIR}/seafdav.conf < "${DEST_SETTINGS_PY}" - - -# ------------------------------------------- -# prepare avatar directory -# ------------------------------------------- -mkdir -p "${TOPDIR}/seahub-data" -mv "${ORIG_AVATAR_DIR}" "${DEST_AVATAR_DIR}" -ln -s ../../../seahub-data/avatars ${MEDIA_DIR} - - -# ------------------------------------------- -# create logs directory -# ------------------------------------------- -mkdir -p "${TOPDIR}/logs" - - -# ------------------------------------------- -# Create symlink for current server version -# ------------------------------------------- -ln -s "$(basename ${INSTALLPATH})" "${SEAFILE_SERVER_SYMLINK}" - - -# Fix permissions -chmod 0600 "$DEST_SETTINGS_PY" -chmod 0700 "$DEFAULT_CCNET_CONF_DIR" -chmod 0700 "$SEAFILE_DATA_DIR" -chmod 0700 "$DEFAULT_CONF_DIR" - - -# ------------------------------------------- -# copy user manuals to library template -# ------------------------------------------- -mkdir -p ${LIBRARY_TEMPLATE_DIR} -cp -f ${SRC_DOCS_DIR}/*.doc ${LIBRARY_TEMPLATE_DIR} - - -# ------------------------------------------- -# Configuring ccnet.conf -# ------------------------------------------- -cat >> ${DEFAULT_CONF_DIR}/ccnet.conf <> ${DEFAULT_CONF_DIR}/seafile.conf <> ${DEST_SETTINGS_PY} < ${seafile_dir}/aio_seafile-server.log<