Loading... 早在2020年,我写过了基于Docker的<a class="post_link" href="https://blog.zakikun.com/archives/18.html"><i data-feather="file-text"></i>搭建Seafile (WinServer 2019+Docker for Windows)</a> 最近因为租了3年轻量应用服务器,顺便就把网盘也搬过来。 #### 部署环境 ```plaintext 系统: Debian 11.1 Mariadb: v10.5.12 Nginx: v1.18.0 Seafile: v9.0.4 elasticsearch: v7.17.1 java: v11.0.14 其他Python相关依赖 ``` ##### 相关依赖 ```bash sudo apt-get update # 如果和我一样安装的是mariadb, libmysqlclient-dev需要改成libmariadbclient-dev sudo apt-get install -y python3 python3-setuptools python3-pip python3-ldap libmysqlclient-dev sudo apt-get install -y memcached libmemcached-dev sudo pip3 install --timeout=3600 django==3.2.* future mysqlclient pymysql Pillow pylibmc captcha jinja2 sqlalchemy==1.4.3 psd-tools django-pylibmc django-simple-captcha pycryptodome==3.12.0 cffi==1.14.0 ``` ##### 创建seafile用户 seafile专业版本身会要求使用seafile名称的账户进行所有操作,所以我们登录root账户创建一个seafile账户并加入sudo用户组方便后续部署 ```bash adduser seafile # seafile账户加入sudo组 usermod -G sudo seafile ``` 以下命令默认以seafile用户执行 ##### Mariadb ###### 安装 ```bash sudo apt update sudo apt install mariadb-server # 安装之后一般会自启动, 用以下命令查看运行情况 sudo systemctl status mariadb # 开机启动mariadb sudo systemctl enable mariadb ``` ###### 初始化 使用mysql_secure_installation初始化数据库 `mysql_secure_installation` 后续提示为root账户设置密码,删除匿名用户,限制远程访问,移除测试数据库,重载权限表格。 除了密码之外,一般回答"Y"继续即可。 ###### 修改root账户验证方式 由于mariadb安装后默认会以unix_socket 身份验证插件,在使用phpmyadmin或者其他软件访问时会出现不少问题,这里修改root账户为mysql_native_password本地密码验证 方法一: 命令 ```bash mysql -u root -p ``` ```sql ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password; ALTER USER 'root'@'localhost' IDENTIFIED BY '密码填这里'; ``` 方法2: phpmyadmin ![image.png](/usr/uploads/images/个人用Seafile专业版部署/mariadb-创建seafile用户.png) ##### Nginx ###### 安装 ```bash # 安装nginx sudo apt install nginx # 启动nginx sudo systemctl start nginx # 开机启动 sudo systemctl enable nginx # 查看版本 nginx -v ``` ###### 配置seafile.conf `vim /etc/nginx/sites-enabled/seafile.conf` ###### seafile.conf ```nginx log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time'; server { listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2; server_name blog.zakikun.com; #记得修改此处域名或IP server_tokens off; # SSL ssl_certificate /etc/nginx/ssl/zakikun.com/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/zakikun.com/privkey.pem; ssl_session_timeout 5m; ssl_session_cache shared:SSL:50m; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; ssl_prefer_server_ciphers off; # HSTS (ngx_http_headers_module is required) (63072000 seconds = 2 years) add_header Strict-Transport-Security "max-age=63072000; preload" always; # Force SSL if ($scheme = "http") { return 301 https://$host$request_uri; } 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-Proto https; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 1200s; # used for view/edit office file via Office Online Server client_max_body_size 0; access_log /var/log/nginx/seahub.access.log seafileformat; 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_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; access_log /var/log/nginx/seafhttp.access.log seafileformat; error_log /var/log/nginx/seafhttp.error.log; # 上传大文件时nginx缓存文件机制不太好, 所以直接关闭缓存, 直接访问seafile后端 proxy_request_buffering off; } location /seafdav { proxy_pass http://127.0.0.1:8080; 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 $scheme; proxy_read_timeout 1200s; client_max_body_size 0; access_log /var/log/nginx/seafdav.access.log seafileformat; error_log /var/log/nginx/seafdav.error.log; } location /media { root /opt/seafile/seafile-server-latest/seahub; } } ``` ###### 重启nginx生效配置 `systemctl restart nginx`或 `nginx -s reload` ##### 其他所需软件 安装 ```bash # JAVA sudo apt install default-jre -y # poppler-utils sudo apt-get install poppler-utils -y ``` #### 下载Seafile并解压 登录Seafile客户中心,下载Seafile专业版软件包 ![](/usr/uploads/images/个人用Seafile专业版部署/seafile-下载Seafile专业版软件包.png) 找到 `seafile-pro-server_9.0.4_x86-64_Ubuntu.tar.gz`下载并上传到服务器 `/opt/seafile` ```bash # 创建文件夹 mkdir /opt/seafile cd /opt/seafile # 解压 tar -xzf seafile-pro-server_9.0.4_x86-64_Ubuntu.tar.gz ``` 解压后得到/opt/seafile/seafile-pro-server-9.0.4,文件结构如下 ```bash /opt/seafile ├── seafile-pro-server-9.0.4 │ ├── check-db-type.py │ ├── check_init_admin.py │ ├── index_op.py │ ├── migrate.py │ ├── migrate-repo.py │ ├── migrate-repo.sh │ ├── migrate.sh │ ├── pro │ ├── remove-objs.py │ ├── remove-objs.sh │ ├── reset-admin.sh │ ├── run_index_master.sh │ ├── run_index_worker.sh │ ├── runtime │ ├── seaf-backup-cmd.py │ ├── seaf-backup-cmd.sh │ ├── seaf-encrypt.sh │ ├── seaf-fsck.sh │ ├── seaf-fuse.sh │ ├── seaf-gc.sh │ ├── seafile │ ├── seafile-background-tasks.sh │ ├── seafile.sh │ ├── seaf-import.sh │ ├── seahub │ ├── seahub.sh │ ├── setup-seafile-mysql.py │ ├── setup-seafile-mysql.sh │ ├── setup-seafile.sh │ ├── sql │ └── upgrade └── seafile-pro-server_9.0.4_x86-64_Ubuntu.tar.gz ``` 更改文件夹权限以便启动 ```bash sudo chmod -R seafile: /opt/seafile ``` #### 初始化Seafile和相关数据库 ``` cd seafile-pro-server-9.0.4 ./setup-seafile-mysql.sh ``` 运行后脚本会询问填入一些信息 | Option | 描述 | 备注 | | --------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------ | | server name | Seafile服务器名字 | 3-15个字符, 只能用英文字母, 数字或下划线'_' | | server's ip or domain | Seafile服务器的域名或者IP | 客户端程序会通过这里设置的域名或IP访问服务端Seafile client program will access the server using this address | | fileserver port | Seafile文件服务器使用的TCP端口 | 默认8082, 除非已被占用, 不然最好保持默认 | 下一步会询问如何配置数据库,首次安装选1新建数据库![](/usr/uploads/images/个人用Seafile专业版部署/seafile-配置数据库.png) 后面同样要填入相关信息 | Question | Description | Note | | ------------------------------- | ------------------------------------- | ----------------------------------------- | | mysql server host | mysql服务器的域名或IP | 默认为localhost | | mysql server port | mysql服务器使用的TCP端口 | 默认为3306 | | mysql root password | mysql root账户的密码 | seafile使用为root账户创建相关数据库 | | mysql user for Seafile | seafile程序接入数据库时使用的账户名 | 默认seafile; 如果不存在,则自动创建 | | mysql password for Seafile user | seafile程序接入数据库时使用账户的密码 | 遵循mysql密码要求,不支持百分比"%"符号 | | database name | ccnet数据库的名称 | 默认为"ccnet-db",如果不存在,则自动创建 | | seafile database name | Seafile数据库的名称 | 默认为"seafile-db",如果不存在,则自动创建 | | seahub database name | seahub数据库的名称 | 默认为"seahub-db",如果不存在,则自动创建 | 初始化成功后,文件目录应该如下 ```bash $ tree /opt/seafile -L 2 seafile ├── ccnet ├── conf │ └── ccnet.conf │ └── gunicorn.conf.py │ └── seafdav.conf │ └── seafile.conf │ └── seahub_settings.py ├── seafile-data │ └── library-template ├── seafile-server-9.0.4 │ └── check_init_admin.py │ ├── reset-admin.sh │ ├── runtime │ └── seaf-fsck.sh │ └── seaf-gc.sh │ ├── seafile │ ├── seafile.sh │ ├── seahub │ ├── seahub.sh │ └── setup-seafile-mysql.py │ ├── setup-seafile-mysql.sh │ └── sql │ └── upgrade ├── seafile-server-latest -> seafile-server-9.0.4 ├── seahub-data │ └── avatars └── seafile-pro-server_9.0.4_x86-64_Ubuntu.tar.gz ``` #### 启动Seafile ``` ./seafile.sh start # 启动seaf-server ./seahub.sh start # 启动seahub ``` 成功启动后则可以通过 `blog.zakikun.com`(同nginx配置一致)访问到seafile #### 为seafile和seahub配置systemd服务提供开机启动 首先进入`/usr/lib/systemd/system`创建相应的service文件 ```bash cd /usr/lib/systemd/system vim seafile.service ``` 然后填入以下内容,其中ExecStart和ExecStop根据具体路径修改 ```markdown [Unit] Description=Seafile After=network.target [Service] Type=oneshot ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop RemainAfterExit=yes User=seafile Group=seafile [Install] WantedBy=multi-user.target ``` 继续创建seahub.service,vim seahub.service ```markdown [Unit] Description=Seafile hub After=network.target seafile.service [Service] Type=oneshot ExecStart = /opt/seafile/seafile-server-latest/seahub.sh start ExecStop = /opt/seafile/seafile-server-latest/seahub.sh stop RemainAfterExit=yes User=seafile Group=seafile [Install] WantedBy=multi-user.target ``` fs给seafile和seahub的服务启用开机启动 ```bash # 重载systemd systemctl daemon-reload # 启用开机启动seafile和seahub systemctl enable seafile systemctl enable seahub ``` 此外以后如果想启动、重启、停止seafile和seahub,可以这样代替上面的启动、停止命令 ```bash systemctl start/stop/restart seafile # 启动/停止/重启 seafile systemctl start/stop/restart seahub # 启动/停止/重启 seahub ``` #### 常见问题 ##### 头像无法正常显示 ###### 方法1: 按原样修复 正常情况下启动后Seafile会在/opt/seafile路径下做一个软链接实现通用文件夹名称指向运行版本文件夹 ```bash root@VM-20-5-debian:/opt/seafile# ls -l total 28 drwx------ 2 seafile seafile 4096 Mar 15 16:01 ccnet drwx------ 3 seafile seafile 4096 Mar 15 19:59 conf drwxr-xr-x 3 seafile seafile 4096 Mar 15 16:31 logs drwxr-xr-x 2 seafile seafile 4096 Mar 16 13:46 pids drwx------ 2 seafile seafile 4096 Mar 15 16:01 pro-data lrwxrwxrwx 1 seafile seafile 19 Mar 15 15:59 seafile-data -> /data/seafile-data/ drwxr-xr-x 8 seafile seafile 4096 Mar 15 18:10 seafile-pro-server-9.0.4 lrwxrwxrwx 1 seafile seafile 24 Mar 15 16:01 seafile-server-latest -> seafile-pro-server-9.0.4 #这个 drwxr-xr-x 5 seafile seafile 4096 Mar 15 17:50 seahub-data ``` 也就是所有对于 `/opt/seafile/seafile-server-latest`的访问都会转到 `/opt/seafile/seafile-pro-server-9.0.4` 启动脚本后程序会自动创建复制一些文件到相应位置,比如: 复制默认的头像文件夹 `./seafile-pro-server-9.0.4/seahub/media/avatars -> /opt/seafile/seahub-data/avatars` 复制自定义上传头像文件夹 `./seafile-pro-server-9.0.4/seahub/media/custom -> /opt/seafile/seahub-data/media/custom` 创建软链接让上述两个文件夹的最终存储在seahub-data内 ```bash root@VM-20-5-debian:/opt/seafile# ls -l ./seafile-server-latest/seahub/media/ total 36 drwxr-xr-x 5 seafile seafile 4096 Jan 21 17:45 assets lrwxrwxrwx 1 seafile seafile 29 Mar 15 17:56 avatars -> ../../../seahub-data/avatars/ # 指向avatars drwxr-xr-x 2 seafile seafile 4096 Oct 21 09:58 cors drwxr-xr-x 6 seafile seafile 4096 Jan 22 14:39 css lrwxrwxrwx 1 seafile seafile 27 Mar 15 17:40 custom -> ../../../seahub-data/custom # 指向custom drwxr-xr-x 2 seafile seafile 4096 Jan 19 14:03 favicons drwxr-xr-x 4 seafile seafile 4096 Oct 20 17:59 fontawesome drwxr-xr-x 5 seafile seafile 4096 Dec 6 17:07 img drwxr-xr-x 5 seafile seafile 4096 Dec 6 17:07 js drwxr-xr-x 12 seafile seafile 4096 Oct 20 17:59 locales drwxr-xr-x 2 seafile seafile 4096 Oct 21 09:58 office-template root@VM-20-5-debian:/opt/seafile# ``` 在nginx配置中可以看到web访问 `/media`时路径是跳转到 `/opt/seafile/seafile-server-latest/seahub`,结合上述正常软链接指向,最终会读取 `/opt/seafile/seahub-data/media`文件夹内的文件 问题就出在Seafile启动后由于源码的问题,在seafile-server-latest/seahub/media创建的两个软链接指向不正确的路径,这里我们只要将原有的文件复制到seahub-data内,然后修复软链接即可 ```bash su seafile cd /opt/seafile # 复制原文件覆盖 cp -rf ./seafile-pro-server-9.0.4/seahub/media/avatars ./seahub-data/avatars # 创建custom文件夹 mkdir ./seahub-data/custom # 删除原有软链接 rm -f ./seafile-server-latest/seahub/media/avartars rm -f ./seafile-server-latest/seahub/media/custom # 创建修复软链接 ln -s /opt/seafile/seahub-data/avatars /opt/seafile/seafile-server-latest/seahub/media/avatars ln -s /opt/seafile/seahub-data/custom /opt/seafile/seafile-server-latest/seahub/media/custom ``` 最后重启Seafile ```bash ./seafile-server-latest/seafile.sh restart && ./seafile-server-latest/seaseahub.sh restart ``` ###### 方法2: 启用https时偶然修复 在<a class="post_link" href="https://blog.zakikun.com/archives/18.html"><i data-feather="file-text"></i>搭建Seafile (WinServer 2019+Docker for Windows)</a>中,docker版在修改SERVICE_URL后可能强制更新修复了文件链接的问题,但我个人在整个Seafile部署完毕后如何改动都无法重现,此处仅提供一个思路 #### 可选配置 ##### 部署elasticsearch 从9.0.x开始,由于版权问题,seafile官方不再集成elasticsearch,所以需要我们自己部署 详细可以看另一篇文章<a class="post_link" href="https://blog.zakikun.com/archives/29.html"><i data-feather="file-text"></i>Debian11部署elasticsearch</a> ##### 部署memcached ###### 安装 在相关依赖部分其实已经安装完毕,这里只做提醒 ``` # on Debian/Ubuntu 18.04+ apt-get install memcached libmemcached-dev -y pip3 install --timeout=3600 pylibmc django-pylibmc ``` ###### 启动memcache ``` systemctl enable --now memcached ``` ###### 修改seahub_settings.py `vim /opt/seafile/conf/seahub_settings.py` 添加下面的内容 ``` CACHES = { 'default': { 'BACKEND': 'django_pylibmc.memcached.PyLibMCCache', 'LOCATION': '127.0.0.1:11211', }, } ``` 最后修改:2022 年 07 月 26 日 © 允许规范转载 打赏 赞赏作者 支付宝 赞 2 个人分享,随意打赏