在CentOS 8上安装和配置Seafile存储

时间:2020-02-23 14:31:05  来源:igfitidea点击:

如何在CentOS 8上安装和配置Seafile? Seafile Server是一个开放源代码,企业级,自托管文件托管平台,旨在提高性能和高可靠性。 Seafile使我们可以将文件放在自己的服务器上,并允许不同的设备同步和访问它。我们也可以将所有文件作为虚拟磁盘访问。在此博客中,我们将研究如何在CentOS 8上安装和配置Seafile文件共享服务器。

以下是Seafile的一些重要功能,它们构成了可靠的文件共享平台:

  • 文件加密
  • 文件锁定
  • 在线编辑和共同创作
  • 文件版本控制和Snapshot
  • Mobile File Access
  • 易于安装和使用的客户端
  • 文件共享和权限控制

在CentOS 8上安装Seafile Storage Server

这些是我们在CentOS 8系统上安装和配置Seafile Storage Server的步骤。

更新系统并设置主机名

我们将首先禁用CentOS selinux,以确保它不会阻止我们将要执行的任何安装。

$sudo vim /etc/selinux/config
# This file controls the state of SELinux on the system. 
# SELINUX= can take one of these three values: 
#     enforcing - SELinux security policy is enforced. 
#     permissive - SELinux prints warnings instead of enforcing. 
#     disabled - No SELinux policy is loaded. 
SELINUX=disabled
# SELINUXTYPE= can take one of these three values: 
#     targeted - Targeted processes are protected, 
#     minimum - Modification of targeted policy. Only selected processes are protected.  
#     mls - Multi Level Security protection. 
SELINUXTYPE=targeted

禁用Selinux之后,在CentOS 8上运行更新。

sudo dnf -y update
sudo dnf -y upgrade

现在配置主机文件并设置服务器主机名

sudo hostnamectl set-hostname seafile.example.com
echo “<your-server-ip> seafile.example.com” | sudo tee -a /etc/hosts

重新启动系统

sudo reboot

添加EPEL存储库并安装依赖项

首先让我们安装Seafile依赖项和所需的软件包

sudo dnf -y install epel-release
sudo dnf -y install python3 python3-imaging MySQL-python3 python3-simplejson python3-setuptools mariadb mariadb-server nginx

配置MariaDB数据库服务器

在安装依赖项时,我们已经安装了MariaDB。让我们继续进行配置。启动MariaDB并启用它以在系统引导时启动。

sudo systemctl start mariadb
sudo systemctl enable mariadb

确保mariadb安装安全并设置root密码。

$sudo mysql_secure_installation
Enter current password for root (enter for none):  Press Enter
Set root password? [Y/n] y
New password:  Enter New Password
Re-enter new password:  Repeat New Password 
Remove anonymous users? [Y/n] Y 
Disallow root login remotely? [Y/n] Y 
Remove test database and access to it? [Y/n] Y 
Reload privilege tables now? [Y/n] Y 
... Success! 
Cleaning up... 
All done!  If you've completed all of the above steps, your MariaDB

创建Seafile数据库

配置了MariaDB之后,我们将继续创建Seafile用户和数据库。使用以下命令连接到MySQL,然后输入我们在上面设置的密码。

mysql -u root -p

我们将为Seafile和以下三个数据库创建一个用户:ccnet_dbseafile_dbseahub_db

连接到MySQL后,运行以下命令来创建所需的数据库:

create database ccnet_db character set = 'utf8';
create database seafile_db character set = 'utf8';
create database seahub_db character set = 'utf8';
create user theitroad@localhost identified by 'yourpassword';
grant all privileges on ccnet_db.* to theitroad@localhost identified by 'yourpassword';
grant all privileges on seafile_db.* to theitroad@localhost identified by 'yourpassword';
grant all privileges on seahub_db.* to theitroad@localhost identified by 'yourpassword';
flush privileges;
exit

在CentOS 8上安装Seafile

我们将在/var/www路径中安装Seafile。

sudo mkdir -p /var/www/seafile
cd /var/www/seafile

使用wget命令下载Seafile,然后解压缩下载的存档。

wget https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_7.1.5_x86-64.tar.gz

解压缩下载的文件

sudo tar xvf seafile-server_7.1.5_x86-64.tar.gz

将目录重命名为seafile-server并切换到该目录。

sudo mv seafile-server-7.1.5/seafile-server

在CentOS 8上配置Seafile

执行setup-seafile-mysql.sh文件以配置数据库。

$cd  seafile-server
$sudo ./setup-seafile-mysql.sh

Checking python on this machine ... 
----------------------------------------------------------------- 
This script will guide you to setup your seafile server using MySQL. 
Make sure you have read seafile server manual at 

       https://download.seafile.com/published/seafile-manual/home.md 

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 
What is the ip or domain of the server? 
For example: www.mycompany.com, 192.168.1.101 
[ This server's ip or domain ] seafile.example.com

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" ]  press Enter

What is the port of mysql server? 
[ default "3306" ]  Press Enter

Which mysql user to use for seafile? 
[ mysql user for seafile ] seacloud

What is the password for mysql user "seahub"? 
[ password for seahub ]  Enter seacloud password
                                                                                                                 
verifying password of user seacloud ...  done 

Enter the existing database name for ccnet: 
[ ccnet database ] ccnet_db 

verifying user "seacloud" access to database ccnet_db ...  done 

Enter the existing database name for seafile: 
[ seafile database ] seafile_db 

verifying user "seacloud" access to database seafile_db ...  done 

Enter the existing database name for seahub: 
[ seahub database ] seahub_db 

verifying user "seacloud" access to database seahub_db ...  done 

--------------------------------- 
This is your configuration 
--------------------------------- 

   server name:            seafile 
   server ip/domain:       seafile.example.com 

   seafile data dir:       /var/www/seafile/seafile-data 
   fileserver port:        8082 

   database:               use existing 
   ccnet database:         ccnet_db 
   seafile database:       seafile_db 
   seahub database:        seahub_db 
   database user:          seacloud 
--------------------------------- 
Press ENTER to continue, or Ctrl-C to abort

--------------------------------- 

Generating ccnet configuration ... 

done 
Successly create configuration dir /var/www/seafile/ccnet. 
Generating seafile configuration ... 

Done. 
done 
Generating seahub configuration ... 
---------------------------------------- 
Now creating ccnet database tables ... 

---------------------------------------- 
---------------------------------------- 
Now creating seafile database tables ... 

---------------------------------------- 
---------------------------------------- 
Now creating seahub database tables ... 

---------------------------------------- 

creating seafile-server-latest 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://download.seafile.com/published/seafile-manual/home.md 

for information.

现在,我们可以启动seafile和seahub服务。使用以下命令启动seafile:

$sudo ./seafile.sh start
[08/17/20 11:16:33] ../common/session.c(148): using config file /var/www/seafile/conf/ccnet.conf 
Starting seafile server, please wait ... 
** Message: seafile-controller.c(563): No seafevents. 

Seafile server started 

Done.

启动seahub服务

$./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 ] theitroad@localhost 

What is the password for the admin account? 
[ admin password ]  Enter Admin password

Enter the password again: 
[ admin password again ]  Repeat Admin password
---------------------------------------- 
Successfully created seafile admin 
---------------------------------------- 
!!! 
!!! WARNING: configuration file should have a valid Python extension. 
!!! 

Error:Seahub failed to start. 
Please try to run "./seahub.sh start" again
Seahub Failed to start.

从上面的输出中可以看到,seahub没有启动。为了得到相关的错误,请使用以下命令启动seafile:

$sudo ./seahub.sh start-fastcgi

from _sha1 import sha1 
ModuleNotFoundError: No module named '_sha1' 
Error:Seahub failed to start.

输出显示该错误大约是sha1,即。我通过用文件/var/www/seafile/seafile-server/seahub/seahub/repo_api_tokens/models.py中的import hashlib从_sha1 import sha1替换来解决此问题。该文件如下所示:

$sudo vim /var/www/seafile/seafile-server/seahub/seahub/repo_api_tokens/models.py
import hashlib 
import hmac 
import uuid 
from django.db import models

保存文件并再次启动seahub

$sudo ./seafile.sh start
LC_ALL is not set in ENV, set to en_US.UTF-8 
Starting seahub at port 8000 ... 
Seahub is started 
Done.

配置防火墙

如果文件墙处于活动状态,请确保通过防火墙打开seafile端口:

sudo firewall-cmd –permanent –add-port=8000/tcp
sudo firewall-cmd –permanent –add-port=8082/tcp
sudo firewall-cmd --reload

在浏览器上访问Seafile

使用端口8000上的主机名/IP地址从浏览器访问seafile:http://<主机名>:8000。如果发现Seafile没有加载到浏览器中,请检查seafile gunicorn配置。确保它未绑定到本地IP地址,如下所示:

$sudo vim /var/www/seafile/conf/gunicorn.conf.py
# default localhost:8000 
#bind = 127.0.0.1:8000
bind = "0.0.0.0:8000"

保存文件,我们应该可以在浏览器中启动seafile了。我们应该看到如下页面:

使用我们先前配置的管理员凭据登录,我们将看到如下所示的页面:

要开始添加新文件夹/文件,请单击"新建库"并为新文件夹提供一个名称,然后单击"提交"。

我们应该能够选择新的库,然后创建或者上传文件夹/文件。

步骤9:配置Seafile客户端

我们将使用Ubuntu 20.04 Client计算机测试与Seafile Server的连接。

要在Ubuntu 20.04上连接到Seafile,首先运行以下命令在Ubuntu 20.04上安装seafile客户端

$sudo wget https://linux-clients.seafile.com/seafile.asc -O /usr/share/keyrings/seafile-keyring.asc
$sudo bash -c "echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/seafile-keyring.asc] https://linux-clients.seafile.com/seafile-deb/focal/stable main' > /etc/apt/sources.list.d/seafile.list"
$sudo apt update
$sudo apt install -y seafile-gui

仅用于cli,请运行以下命令:

sudo apt-get install seafile-cli

安装完成后,在应用程序中搜索seafile客户端,我们应该会看到它。

双击打开并为库选择一个文件夹,然后单击下一步

现在提供seafile服务器连接到的详细信息:

当我们单击Login时,我们应该连接到seafile服务器。