手动在CentOS 8下安装Seafile,搭建私有云

使用Seafile已经好几年,日常中使用它来同步照片、同步Enpass的密码库、存储历史文档,6.X版本持续运行几年也未发生问题,因为备案政策越来越繁杂等原因,不得不重新购置一台海外服务器来重新部署一下Seafile,由于Seafile7以上版本对Python版本要求提高到3.X,图省事系统镜像就直接选用了CentOS 8,由于服务器中已安装其他服务,未避免出现不可预知的问题,这里选择手动安装,觉得麻烦的可以使用Seafile官方提供的一键安装脚本。

安装Seafile

我选择将Seafile安装到/usr/local/seafile目录,可根据实际需求进行修改,本次安装版本为8.0.7(2021-08-29),可前往Seafile官网下载页面获取最新版本下载链接。

1
2
3
4
5
6
mkdir /usr/local/seafile
cd /usr/local/seafile
wget https://seafile-downloads.oss-cn-shanghai.aliyuncs.com/seafile-server_8.0.8_x86-64.tar.gz
tar -xzf seafile-server_*
mkdir installed
mv seafile-server_* installed

安装相关依赖

如使用Sqlite安装,依赖组件中的mysql部分可不进行安装。

1
yum install python3 python3-setuptools python3-pip python3-ldap python3-devel gcc gcc-c++ -y pip3 install --timeout=3600 django==2.2.* future Pillow pylibmc captcha jinja2 sqlalchemy==1.4.3 psd-tools django-pylibmc django-simple-captcha

用户配置

为避免安全隐患,建议使用非Root账户运行Seafile,这里创建名为“seafile”的账户执行后续安装。因为仅个人使用的原因,这里选择轻量级的Sqlite数据库进行安装。

1
2
3
4
5
useradd --system --comment ""seafile"" seafile --home-dir  /usr/local/seafile
chown seafile:seafile -R /usr/local/seafile
su seafile
cd /usr/local/seafile/seafile-server-*
./setup-seafile.sh

初始化Seafile

完成以上安装步骤后,可以尝试初次启动Seafile,确保Seafile能够正常运行的同时对Seafile进行创建管理员账号等初始化操作。

1
2
./seafile.sh start 
./seahub.sh start

如无问题,Seafile及Seahub服务应该能正常启动,如果遇到启动失败,可尝试执行./seahub.shstart-fastcgi查看无法正常启动的原因。新版Seafile的8000端口默认监听在127.0.0.1地址上,无法通过IP+端口的方式进行访问,需要配置Nginx反向代理,或者修改Seafile安装目录下conf中的gunicorn.conf.py文件,将监听地址由127.0.0.1:8080改为0.0.0.0:8080。
完成安装后,记得执行su root切换回Root账户,为避免权限问题造成的麻烦,后续配置将在Root账户下进行。

配置Nginx

这里提供一份Nginx配置示例文件,可以根据实际情况修改server_name、ssl_certificate、ssl_certificate_key、access_log、error_log以及media路径,如果不需要Webdav服务,可删除配置文件中的seafdav部分。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
server {
listen 80;
server_name cloud.carefu.link;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name cloud.carefu.link;

# SSL
ssl_certificate /usr/local/nginx/conf/ssl/carefu.link.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/carefu.link.key;
ssl_trusted_certificate /usr/local/nginx/conf/ssl/certificate.cer;

# Security Headers
add_header X-XSS-Protection ""1; mode=block"" always;
add_header X-Content-Type-Options ""nosniff"" always;
add_header Referrer-Policy ""no-referrer-when-downgrade"" always;
add_header Content-Security-Policy ""default-src 'self' http: https: data: blob: 'unsafe-inline'; frame-ancestors 'self';"" always;
add_header Permissions-Policy ""interest-cohort=()"" always;
add_header Strict-Transport-Security ""max-age=31536000; includeSubDomains; preload"" always;

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;

access_log /data/wwwlogs/seahub.access.log;
error_log /data/wwwlogs/seahub.error.log;

proxy_read_timeout 1200s;
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 /seafdav {
proxy_pass http://127.0.0.1:8080/seafdav;
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 /data/wwwlogs/seafdav.access.log;
error_log /data/wwwlogs/seafdav.error.log;
}

location /media {
root /usr/local/seafile/seafile-server-latest/seahub;
}
}

修改完Nginx配置文件后使用nginx -t验证配置文件,如无报错,执行systemctl restart nginx重启Nginx。现在,你可以使用域名访问Seafile,使用初始化时设置的账号密码登录后点击右上角进入系统管理,这里需要对设置中的SERVICE_URL和FILE_SERVER_ROOT进行修改,参考如下:

1
2
https://carefu.link #SERVICE_URL 
https://carefu.link/seafhttp #FILE_SERVER_ROOT

配置开机启动

这里需要在/etc/systemd/system/目录下创建名为seafile.serviceseahub.service的systemd服务管理文件。

seafile.service

1
2
3
4
5
6
7
8
9
10
11
12
[Unit] Description=Seafile # add mysql.service or postgresql.service depending on your database to the line below 
After=network.target 

[Service]
Type=oneshot
ExecStart=/usr/local/seafile/seafile-server-latest/seafile.sh start
ExecStop=/usr/local/seafile/seafile-server-latest/seafile.sh stop
RemainAfterExit=yes
User=seafile
Group=seafile 

[Install] WantedBy=multi-user.target

seahub.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit] 
Description=Seafile hub
After=network.target seafile.service

[Service]
# change start to start-fastcgi if you want to run fastcgi
ExecStart=/usr/local/seafile/seafile-server-latest/seahub.sh start
ExecStop=/usr/local/seafile/seafile-server-latest/seahub.sh stop
User=seafile
Group=seafile
Type=oneshot
RemainAfterExit=yes 

[Install]
WantedBy=multi-user.target

设置开机启动服务

1
2
systemctl enable seafile.service 
systemctl enable seahub.service

配置Webdav

修改Seafile安装目录下conf中的seafdav.conf文件,参考如下,其中share_name部分可根据实际需求进行修改,注意同时需要修改Nginx配置文件中的相应部分。

1
2
3
4
[WEBDAV] 
enabled = true
port = 8080
share_name = /seafdav

配置完成后,需执行./seafile.shrestart重启Seafile服务。

配置Memcached

事实上,仅个人使用是无需配置Memcached缓存的,但这台服务器本身已有Memcached服务为博客提供缓存,便顺手为Seafile进行配置。需要修改Seafile安装目录下conf中的seahub_settings.py文件,将以下内容加入其中。

1
2
3
4
5
6
7
8
9
10
CACHES = {
'default': {
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
'LOCATION': '127.0.0.1:11211',
},
'locmem': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
}
COMPRESS_CACHE_BACKEND = 'locmem'

保存文件后,记得执行./seahub.shrestart重启seahub服务。现在,你可以安心的享受Seafile为生活、工作带来的便利了。
Seafile作为私有云盘而言,无疑是很优秀的,完善的客户端、丰富的支持文档,让安装、使用变得更简单,同时相对于ownCloud等而言,则拥有更好的性能。免费社区版对于个人而言,是完全够用的。

手动在CentOS 8下安装Seafile,搭建私有云

https://goldrun.fyi/posts/25310.html

作者

谨行

发布于

2026-02-04

更新于

2026-02-09

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.