如何在 Ubuntu 22.04|20.04|18.04 上安装 Seafile 服务器
在这篇博文中,我将向您展示如何在 Ubuntu 22.04|20.04|18.04 上安装 Seafile 服务器。 Seafile Server 是一个开源、企业、自托管文件托管平台,旨在提高性能和高可靠性。 Seafile 使您能够将文件放在自己的服务器上,并允许其他人和您的不同设备同步和访问它。您还可以像虚拟磁盘一样访问所有文件。
Seafile的特点
- 内置文件加密:文件在同步到服务器之前会被加密。即使系统管理员也无法查看这些文件。
- Drive 客户端:使用 Drive 客户端访问
本地 S: 盘
中的云端文件,无需同步。 - 可靠的文件同步:具有可靠且高效的文件同步功能,可提高您的工作效率。
- 易于升级:只需在几秒钟内运行一个简单的脚本即可完成升级
- 企业就绪:Seafile 支持
AD/LDAP
集成、组同步、细粒度权限控制,使该工具可以轻松应用于您的企业环境。
Seafile 服务器要求
- HTTP 服务器 – Nginx 或 Apache
- 数据库服务器 – MySQL 或 MariaDB
- Python工具
我们的安装步骤将从安装上述软件要求开始,然后再下载和设置 Seafile 服务器。按照以下步骤在 Ubuntu 22.04|20.04|18.04 上安装 Seafile 服务器。
第1步:安装MariaDB数据库服务器
使用以下步骤开始安装 MariaDB 数据库服务器。
sudo apt update
sudo apt install mariadb-server
安全的 MariaDB 数据库服务器:
sudo mysql_secure_installation
安装MariaDB数据库服务器后,为Seafile创建用户和数据库。
首先以 root 用户身份登录 MySQL shell:
$ sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Seafile Server 的三个组件需要自己的数据库:
- ccnet服务器
- 海洋文件服务器
- 海港服务器
我们将为每个服务器组件创建一个数据库。
CREATE DATABASE seafile_server;
CREATE DATABASE ccnet_server;
CREATE DATABASE seahub_server;
创建数据库用户并为创建的数据库授予权限。
CREATE USER 'seafile'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL ON seafile_server.* TO 'seafile'@'localhost';
GRANT ALL ON ccnet_server.* TO 'seafile'@'localhost';
GRANT ALL ON seahub_server.* TO 'seafile'@'localhost';
QUIT;
以 seafile
用户身份登录数据库来确认访问:
$ sudo mysql -u seafile -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| ccnet_server |
| information_schema |
| seafile_server |
| seahub_server |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]> QUIT
Bye
第2步:安装Python依赖项
Seafile 严重依赖于 Python 及其模块。通过在终端中运行以下命令,在 Ubuntu 上安装所需的 Python 依赖项。
sudo apt update
sudo apt install ffmpeg memcached libmemcached-dev python3 python3-{pip,pil,ldap,urllib3,setuptools,mysqldb,memcache,requests}
sudo pip3 install --upgrade pip
sudo pip3 install Pillow pylibmc captcha jinja2 sqlalchemy django-pylibmc django-simple-captcha python3-ldap mysqlclient
第 3 步:下载并安装 Seafile 服务器
下载前检查 Seafile 服务器的最新版本。本文在您安装时可能已过时。
sudo apt -y install wget
export VER="9.0.10"
wget https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_${VER}_x86-64.tar.gz
下载文件后,将存档解压到 /srv
目录。
sudo tar -xvf seafile-server_${VER}_x86-64.tar.gz -C /srv
sudo mv /srv/seafile-server-${VER} /srv/seafile
无需安装,只需运行安装脚本即可。
cd /srv/seafile/
sudo ./setup-seafile-mysql.sh
该脚本将指导您使用 MySQL 设置 Seafile 服务器。
$ sudo ./setup-seafile-mysql.sh
Checking python on this machine ...
Checking python module: setuptools ... Done.
Checking python module: python-imaging ... Done.
Checking python module: python-mysqldb ... Done.
-----------------------------------------------------------------
This script will guide you to setup your seafile server using MySQL.
Make sure you have read seafile server manual at
https://github.com/haiwen/seafile/wiki
Press ENTER to continue
-----------------------------------------------------------------
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] Seafile-Server
What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] fileserver.example.com
Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/srv/seafile-data" ]
Which port do you want to use for the seafile fileserver?
[ default "8082" ]
-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
[ 1 or 2 ] 2
What is the host of mysql server?
[ default "%" ] localhost
What is the port of mysql server?
[ default "3306" ] <Enter>
Which mysql user to use for seafile?
[ mysql user for seafile ] seafile
What is the password for mysql user "seafile"?
[ password for seafile ] StrongPassword
verifying password of user seafile ... done
Enter the existing database name for ccnet:
[ ccnet database ] ccnet_server
verifying user "seafile" access to database ccnet_server ... done
Enter the existing database name for seafile:
[ seafile database ] seafile_server
verifying user "seafile" access to database seafile_server ... done
Enter the existing database name for seahub:
[ seahub database ] seahub_server
verifying user "seafile" access to database seahub_server ... done
---------------------------------
This is your configuration
---------------------------------
server name: Seafile-Server
server ip/domain: fileserver.example.com
seafile data dir: /srv/seafile-data
fileserver port: 8082
database: use existing
ccnet database: ccnet_server
seafile database: seafile_server
seahub database: seahub_server
database user: seafile
---------------------------------
Press ENTER to continue, or Ctrl-C to abort
---------------------------------
Generating ccnet configuration ...
done
Successly create configuration dir /srv/ccnet.
Generating seafile configuration ...
Done.
done
Generating seahub configuration ...
----------------------------------------
Now creating seahub database tables ...
----------------------------------------
creating seafile symbolic link ... done
-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------
run seafile server: ./seafile.sh { start | stop | restart }
run seahub server: ./seahub.sh { start <port> | stop | restart <port> }
-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------
port of seafile fileserver: 8082
port of seahub: 8000
When problems occur, Refer to
https://github.com/haiwen/seafile/wiki for information.
Seafile 服务器将在端口 8082
上运行,Seafile Web UI 将在端口 8000
上可用。
启动 Seafile 服务
启动 Seafile 服务器守护进程来处理原始文件上传、下载和同步:
$ cd /srv/seafile
$ sudo ./seafile.sh start
[12/15/18 05:08:27] ../common/session.c(132): using config file /srv/conf/ccnet.conf
Starting seafile server, please wait ...
Seafile server started
Done.
然后启动 Seahub (Django) Web 前端服务:
$ sudo ./seahub.sh start
LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...
----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------
What is the email for the admin account?
[ admin email ] [email
What is the password for the admin account?
[ admin password ] <ENTER ADMIN PASSWORD>
Enter the password again: <CONFIRM ADMIN PASSWORD>
[ admin password again ]
----------------------------------------
Successfully created seafile admin
----------------------------------------
Seahub is started
Done.
如果您遇到区域设置问题,请按如下所示进行设置:
echo "export LC_ALL=en_US.UTF-8" >>~/.bashrc
echo "export LANG=en_US.UTF-8" >>~/.bashrc
echo "export LANGUAGE=en_US.UTF-8" >>~/.bashrc
source ~/.bashrc
将这些行添加到 ~/.bashrc
文件中以具有持久的 LC 设置。
第四步:创建 Seafile Systemd 服务
我更喜欢使用 systemd 管理 Seafile。为 Seafile 后端服务器创建一个 systemd 单元文件。
sudo tee /etc/systemd/system/seafile.service<<EOF
[Unit]
Description=Seafile
After= mysql.service
After=network.target
[Service]
Type=forking
ExecStart=/srv/seafile/seafile.sh start
ExecStop=/srv/seafile/seafile.sh stop
[Install]
WantedBy=multi-user.target
EOF
还为 Seahub 创建一个
sudo tee /etc/systemd/system/seahub.service<<EOF
[Unit]
Description=Seafile
After= mysql.service
After=network.target
[Service]
Type=forking
ExecStart=/srv/seafile/seahub.sh start
ExecStop=/srv/seafile/seahub.sh stop
[Install]
WantedBy=multi-user.target
EOF
启动并启用服务以在引导时启动:
sudo systemctl daemon-reload
sudo systemctl start seafile && sudo systemctl enable seafile
sudo systemctl start seahub && sudo systemctl enable seahub
确认服务状态:
$ systemctl status seafile
● seafile.service - Seafile
Loaded: loaded (/etc/systemd/system/seafile.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-15 06:01:19 PST; 14s ago
Process: 26437 ExecStart=/srv/seafile/seafile.sh start (code=exited, status=0/SUCCESS)
Tasks: 14 (limit: 2319)
CGroup: /system.slice/seafile.service
├─26476 /srv/seafile/seafile/bin/seafile-controller -c /srv/ccnet -d /srv/seafile-data -F /srv/conf
├─26478 ccnet-server -F /srv/conf -c /srv/ccnet -f /srv/logs/ccnet.log -d -P /srv/pids/ccnet.pid
└─26482 seaf-server -F /srv/conf -c /srv/ccnet -d /srv/seafile-data -l /srv/logs/seafile.log -P /srv/pids/seaf-server.pid
Dec 15 06:01:16 ubuntu-01 systemd[1]: Starting Seafile...
Dec 15 06:01:16 ubuntu-01 seafile.sh[26437]: [12/15/18 06:01:16] ../common/session.c(132): using config file /srv/conf/ccnet.conf
Dec 15 06:01:16 ubuntu-01 seafile.sh[26437]: Starting seafile server, please wait ...
Dec 15 06:01:19 ubuntu-01 seafile.sh[26437]: Seafile server started
Dec 15 06:01:19 ubuntu-01 seafile.sh[26437]: Done.
Dec 15 06:01:19 ubuntu-01 systemd[1]: Started Seafile.
$ systemctl status seahub
● seahub.service - Seafile
Loaded: loaded (/etc/systemd/system/seahub.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-15 06:02:43 PST; 4s ago
Process: 26572 ExecStart=/srv/seafile/seahub.sh start (code=exited, status=0/SUCCESS)
Main PID: 26600 (python2.7)
Tasks: 6 (limit: 2319)
CGroup: /system.slice/seahub.service
├─26600 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
├─26607 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
├─26608 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
├─26609 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
├─26610 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
└─26611 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
Dec 15 06:02:38 ubuntu-01 systemd[1]: Starting Seafile...
Dec 15 06:02:38 ubuntu-01 seahub.sh[26572]: LC_ALL is not set in ENV, set to en_US.UTF-8
Dec 15 06:02:38 ubuntu-01 seahub.sh[26572]: Starting seahub at port 8000 ...
Dec 15 06:02:43 ubuntu-01 seahub.sh[26572]: Seahub is started
Dec 15 06:02:43 ubuntu-01 seahub.sh[26572]: Done.
Dec 15 06:02:43 ubuntu-01 systemd[1]: Started Seafile.
第5步:配置Nginx反向代理
现在您已经运行了服务,是时候将 nginx 配置为 Seafile 服务器的反向代理了。
sudo apt -y install nginx
在 /etc/nginx/conf.d/seafile.conf
下创建一个包含以下内容的新配置文件。
server {
listen 80;
listen [::]:80;
server_name fileserver.example.com;
autoindex off;
client_max_body_size 100M;
access_log /var/log/nginx/seafile.com.access.log;
error_log /var/log/nginx/seafile.com.error.log;
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_read_timeout 1200s;
}
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://127.0.0.1:8082;
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 /srv/seafile/seahub;
}
}
在 http://example.com
上访问您的 Seafile 服务器域名
输入管理员用户电子邮件和密码进行登录。您应该进入 Seafile 仪表板,如下所示。
您已在 Ubuntu LTS 上成功安装并配置了 Seafile 服务器。
类似文章:
- 在 Ubuntu 上安装和配置 Pydio 文件共享服务器
- 如何在 Ubuntu 上安装 Nextcloud