title: Seafile安装与配置v3 english_title: seafile-install-configuration top: 0 tags: - seafile fancybox: true comments: true description: 迁移了下seafile服务器,发现以前的那个教程过时了,现在重新开一个。 date: 2018-12-13 21:10:26 categories: permalink: --- 迁移了下seafile服务器,发现以前的那个教程过时了,现在重新开一个。 用的是Ubuntu 16.04LTS,并且开通全部端口。 为了管理方便安装宝塔面板,在这里可以配置防火墙。 安装命令 ```bash wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh ``` 创建程序目录seafile,建议放在root目录之外,防止因为权限产生的错误,给775权限,文件夹所有者root。 ```bash sudo -i mkdir cloud seafile chmod 775 seafile ``` 从官网下载seafile安装包,专业版需要到seafile英文版网站登陆客户中心后获取。 社区版下载地址`https://www.seafile.com/en/download/` 专业版下载地址`https://download.seafile.com/d/6e5297246c/?p=/pro` seafile-server-6.3.4 64bit版本下载 ```bash wget https://download.seadrive.org/seafile-server_6.3.4_x86-64.tar.gz ``` 下载后解压到seafile文件夹 ``` tar -xzf seafile-server_* ``` 移动安装包 ``` mkdir installed mv seafile-server_* installed ``` 解压后检查下目录结构 ``` # tree . -L 2 . ├── installed │ └── seafile-server_*_x86-64.tar.gz └── seafile-server-* ├── reset-admin.sh ├── runtime ├── seafile ├── seafile.sh ├── seahub ├── seahub.sh ├── setup-seafile.sh └── upgrade ``` ## 安装依赖包 - MariaDB 或者 MySQL 服务器 (MariaDB 是 MySQL 的分支) - python 2.7 (从 Seafile 5.1 开始,python 版本最低要求为2.7) - python-setuptools - python-imaging - python-mysqldb - python-ldap - python-urllib3 - python-memcache (或者 python-memcached) - jre ```bash sudo apt-get update sudo apt-get install python sudo apt-get install python2.7 libpython2.7 python-setuptools python-ldap python-urllib3 ffmpeg python-pip python-mysqldb python-memcache python-requests pip install Pillow pip install moviepy # used in movie file thumbnails sudo apt-get install openjdk-8-jre ``` 安装数据库并设置数据库roor密码这里我使用面板创建 命令行安装 ``` sudo apt install mysql-client-core-5.7 ``` 再顺便安好pureftpd、phpMyAdmin、Memcached 自己安装Memcached的话直接安装django-pylibmc模块,并且最好将缓存设置大于128M ``` pip install django-pylibmc ``` 配置也要相应的修改,按照官方的文档的配置在启动seahub调试时会报错 ``` CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', 'LOCATION': '127.0.0.1.11211', } } ``` ### 配置MySQL数据库 seafile由3个核心部件组成。 我们需要为这个给定的组件创建一个数据库。这一步可以使用官方提供的脚本自动进行。 - ccnet服务器 - seafile服务器 - seahub 现在正在为列出的给定数据库创建mysql数据库,帐户和设置权限。 (这只是一个例子,您可以在数据库名称上创建自己的设计)。 ```table seafile部件 | 数据库名称 | 帐户 ccnet服务器 | ccnet-db | seafile seafile服务器 | seafile-db | seafile seahub | seahub-db | seafile ``` 以root用户身份登录到mysql ``` mysql -u root -p ``` 输入之前安装设置的Mysql密码,然后在mysql shell中发出这些命令: ``` create database`ccnet-db`character set =utf8; create database`seafile-db`character set =utf8; create database`seahub-db`character set =utf8; create user 'seafile'@'localhost' identified by 'seafile'; grant all privileges on `ccnet-db`.* to `seafile`@localhost; grant all privileges on `seafile-db`.* to `seafile`@localhost; grant all privileges on `seahub-db`.* to `seafile`@localhost; ``` ## 安装 ``` cd seafile-server-pro-* ./setup-seafile-mysql.sh ``` 下面配置按你需求填写 第一项是主机名称 第二项是主机的IP或者域名 第三项是seafile存储数据存放位置这里填的是`/cloud` 第四项是端口默认即可 第五项是数据库,如果没有按照上面创建数据库,这里可以选1自动配置,然后输入数据库的配置信息 这样一般就会成功了,没有成功的话可能是没有创建目录的权限用root权限运行下就可以。 如果用宝塔面板,成功之后需要手动放行8000和8082端口。 到了这一步就可以启动了 在 seafile-server-pro-*目录下,运行如下命令: - 启动Seafile: ``` ./seafile.sh start ``` - 启动Seahub(默认运行在8000端口上) ``` ./seahub.sh start ``` ## 一些配置 ### 更改端口 参考官方文档: **6.2.x 及其之前版本** - 关闭 Seafile 服务器 ``` ./seahub.sh stop # 停止 Seafile 进程 ./seafile.sh stop # 停止 Seahub ``` - 更改`*/conf/ccnet.conf`文件中`SERVICE\_URL` 的值(假设你的 ip 或者域名时`192.168.1.100`), 如下 (从 5.0 版本开始,可以直接在管理员界面中设置。注意,如果同时在 Web 界面和配置文件中设置了这个值,以 Web 界面的配置为准。): ``` `SERVICE_URL = http://192.168.1.100:8001 ` ``` - 重启 Seafile 服务器 ``` ./seafile.sh start # 启动 Seafile 服务 ./seahub.sh start 8001 # 启动 Seahub 网站 (运行在8001端口上) ``` **6.3.x 及其以上版本** 6.3.0 及其之后的版本,我们弃用了 `./seahub.sh start ` 的方式使seahub进程监听在其他端口。但是,您可以通过修改 `conf/gunicorn.conf` 中的端口设置来指定seahub启动端口。 - 关闭 Seafile 服务器 ``` ./seahub.sh stop # 停止 Seafile 进程 ./seafile.sh stop # 停止 Seahub ``` - 更改`*/conf/ccnet.conf`文件中`SERVICE\_URL` 的值(假设你的 ip 或者域名时`192.168.1.100`), 如下 (从 5.0 版本开始,可以直接在管理员界面中设置。注意,如果同时在 Web 界面和配置文件中设置了这个值,以 Web 界面的配置为准。): ``` `SERVICE_URL = http://192.168.1.100:8001 ` ``` - **修改conf/gunicorn.conf** ``` # default localhost:8000 bind = "0.0.0.0:8001" ``` - 重启 Seafile 服务器 ``` ./seafile.sh start # 启动 Seafile 服务 ./seahub.sh start # 启动 Seahub 网站 (运行在8001端口上) ``` ### 邮件提醒 按照[官方文档](https://manual-cn.seafile.com/config/sending_email.html)配置 ### memcached [官方文档](https://manual-cn.seafile.com/deploy/add_memcached.html) 如果使用[django-pylibmc](https://pypi.org/project/django-pylibmc/)组件修改相应段落为 ``` 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache' ``` ### 多存储后端 [官方文档](https://manual-cn.seafile.com/deploy_pro/multiple_storage_backends.html) ### webdav 修改conf文件夹下的seafdav.conf ``` [WEBDAV] enabled = true port = 8080 fastcgi = true host = 0.0.0.0 share_name = / ``` ### 开启 Office/PDF 文件在线预览 [官方文档](https://manual-cn.seafile.com/deploy_pro/office_documents_preview.html) ### Nginx 如果需要使用Nginx的话 参见[官方文档](https://manual-cn.seafile.com/deploy/deploy_with_nginx.html) 这里是我的配置 ``` server { listen 80; listen 443 ssl http2; server_name cloud.liangs.me; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/cloud.liangs.me; #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 #error_page 404/404.html; #HTTP_TO_HTTPS_START if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } #HTTP_TO_HTTPS_END ssl_certificate /etc/letsencrypt/live/cloud.liangs.me/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/cloud.liangs.me/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; error_page 497 https://$host$request_uri; #SSL-END #ERROR-PAGE-START 错误页配置,可以注释、删除或修改 error_page 404 /404.html; error_page 502 /502.html; #ERROR-PAGE-END #PHP-INFO-START PHP引用配置,可以注释或修改 include enable-php-00.conf; #PHP-INFO-END #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效 include /www/server/panel/vhost/rewrite/cloud.liangs.me.conf; #REWRITE-END proxy_set_header X-Forwarded-For $remote_addr; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains"; server_tokens off; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Forwarded-Proto https; proxy_read_timeout 1200s; # used for view/edit office file via Office Online Server client_max_body_size 0; } location /seafhttp { rewrite ^/seafhttp(.*)$ $1 break; proxy_pass http://127.0.0.1:8082; client_max_body_size 0; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; proxy_send_timeout 36000s; send_timeout 36000s; } location /media { root /root/seafile-pro-server-6.2.9/seahub; } #禁止访问的文件或目录 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } #一键申请SSL证书验证目录相关设置 location ~ \.well-known{ allow all; } access_log /www/wwwlogs/cloud.liangs.me.log; error_log /www/wwwlogs/cloud.liangs.me.error.log; } ``` ### 开机启动 参考[官方文档](https://manual-cn.seafile.com/deploy/start_seafile_at_system_bootup.html) 这里是我的三个配置文件 - seafile.service ```bash [Unit] Description=Seafile hub After=network.target seafile.service [Service] # change start to start-fastcgi if you want to run fastcgi ExecStart=/seafile/seafile-server-latest/seahub.sh start ExecStop=/seafile/seafile-server-latest/seahub.sh stop User=root Group=root Type=oneshot RemainAfterExit=yes [Install] WantedBy=multi-user.target ``` - seahub.service ```bash [Unit] Description=Seafile hub After=network.target seafile.service [Service] # change start to start-fastcgi if you want to run fastcgi ExecStart=/seafile/seafile-server-latest/seahub.sh start ExecStop=/seafile/seafile-server-latest/seahub.sh stop User=root Group=root Type=oneshot RemainAfterExit=yes [Install] WantedBy=multi-user.target ``` - seafile-client.service ```bash [Unit] Description=Seafile client # Uncomment the next line you are running seafile client on the same computer as server # After=seafile.service # Or the next one in other case # After=network.target [Service] Type=oneshot ExecStart=/usr/bin/seaf-cli start ExecStop=/usr/bin/seaf-cli stop RemainAfterExit=yes User=root Group=root [Install] WantedBy=multi-user.target ``` **Ubuntu 14.10 以及更旧的版本** ```bash #!/bin/bash ### BEGIN INIT INFO # Provides: seafile-server # Required-Start: $remote_fs $syslog mysql # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Seafile server # Description: Start Seafile server ### END INIT INFO # Change the value of "user" to your linux user name user=root # Change the value of "seafile_dir" to your path of seafile installation # usually the home directory of $user seafile_dir=/seafile script_path=${seafile_dir}/seafile-server-latest seafile_init_log=${seafile_dir}/logs/seafile.init.log seahub_init_log=${seafile_dir}/logs/seahub.init.log # Change the value of fastcgi to true if fastcgi is to be used fastcgi=false # Set the port of fastcgi, default is 8000. Change it if you need different. fastcgi_port=80 # # Write a polite log message with date and time # echo -e "\n \n About to perform $1 for seafile at `date -Iseconds` \n " >> ${seafile_init_log} echo -e "\n \n About to perform $1 for seahub at `date -Iseconds` \n " >> ${seahub_init_log} case "$1" in start) sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log} if [ $fastcgi = true ]; then sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log} else sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log} fi ;; restart) sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log} if [ $fastcgi = true ]; then sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log} else sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log} fi ;; stop) sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log} sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log} ;; *) echo "Usage: /etc/init.d/seafile-server {start|stop|restart}" exit 1 ;; esac ``` **注意:** 如果你正在使用本地 mysql 服务,请将 `# Required-Start: $remote\_fs $syslog` 替换为 `# Required-Start: $remote\_fs $syslog mysql`. 确保 seafile-server 脚本可执行 ``` sudo chmod +x /etc/init.d/seafile-server ``` 添加 seafile-server 到 rc.d 中 ``` sudo update-rc.d seafile-server defaults ``` ## 错误调试 出现No module named memcache错误 安装缺少的组件 ``` pip install django-pylibmc ``` 或者换成django-pylibmc,并且如上文配置