如何在 Ubuntu 16.04 LTS 上安装 Seafile

在本教程中,我们将向您展示如何在 Ubuntu 16.04 LTS 上安装和配置 Seafile。 对于那些不知道的人,Seafile 是一个开源的云存储软件。 它为个人用户和组提供文件共享和同步,它提供客户端加密和从移动设备轻松访问。 还可以轻松与本地服务(如 LDAP 和 WebDAV)集成,或者可以使用高级网络服务和数据库(如 MySQL、SQLite、PostgreSQL、Memcached、Nginx 或 Apache 网络服务器。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Ubuntu 16.04 (Xenial Xerus) 服务器上逐步安装 Seafile 开源安全云存储。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 16.04 (Xenial Xerus)。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一种 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 16.04 LTS Xenial Xerus 上安装 Seafile

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt-get 终端中的命令。

sudo apt-get update sudo apt-get upgrade

步骤 2. 安装 LEMP(Linux、Nginx、MariaDB、PHP)服务器。

需要 Ubuntu 16.04 LAMP 服务器。 如果您没有安装 LEMP,您可以在此处按照我们的指南进行操作。 还要安装所有必需的 PHP 模块:

apt-get install php7.0-curl php7.0-gd php7.0-mbstring php7.0-mysql libapache2-mod-php7.0 php7.0-mcrypt php7.0-zip

安装 Python 模块:

apt-get install python2.7 libpython2.7 python-setuptools python-imaging python-ldap python-mysqldb python-memcache python-urllib3

步骤 3. 为 Seafile 配置 MariaDB 数据库。

默认情况下,MariaDB 未加固。 您可以使用 mysql_secure_installation 脚本。 您应该仔细阅读下面的每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录以及删除测试数据库和访问安全 MariaDB。

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y - 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

接下来,我们需要登录 MariaDB 控制台并为 Seafile 创建一个数据库。 运行以下命令:

mysql -u root -p

这将提示您输入密码,因此输入您的 MariaDB 根密码并点击 Enter. 登录到数据库服务器后,您需要为 Seafile 安装创建一个数据库:

MariaDB [(none)]> create database ccnet_db character set="utf8"; MariaDB [(none)]> create database seafile_db character set="utf8"; MariaDB [(none)]> create database seahub_db character set="utf8"; MariaDB [(none)]> create user [email protected] identified by 'password'; MariaDB [(none)]> grant all privileges on ccnet_db.* to [email protected] identified by 'password'; MariaDB [(none)]> grant all privileges on seafile_db.* to [email protected] identified by 'password'; MariaDB [(none)]> grant all privileges on seahub_db.* to [email protected] identified by 'password'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit

步骤 4. 在服务器上安装 Seafile。

您需要下载 Seafile 的最新稳定版本:

wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.6_x86-64.tar.gz

将压缩包解压到当前目录:

tar -xvzf seafile-server_6.0.6_x86-64.tar.gz mv seafile-server_6.0.6 seafile-server

安装 Seafile:

运行此脚本,该脚本将为 Seafile 服务器创建所需的数据库和目录,并在脚本验证所有 Python 所需模块的存在后,使用以下配置选项回答所有问题:

./setup-seafile-mysql.sh

Seafile 服务器成功安装后,它将生成一些有用的信息,例如需要在防火墙上打开哪些端口以允许外部连接以及要处理哪些脚本才能启动服务器。

步骤 5. 启动 Seafile 服务。

像这样为 Seafile 服务器创建一个启动脚本:

nano /lib/systemd/system/seafile.service

添加以下行:

[Unit] Description=Seafile Server After=network.target mariadb.service[Service] Type=oneshot ExecStart=/home/seafile/seafile-server/seafile.sh start ExecStop=/home/seafile/seafile-server/seafile.sh stop RemainAfterExit=yes User=seafile Group=seafile[Install] WantedBy=multi-user.target

Save 该文件并为 seahub 创建一个新的服务文件:

[Unit] Description=Seafile Hub After=network.target seafile.target[Service] Type=oneshot ExecStart=/home/seafile/seafile-server/seahub.sh start-fastcgi ExecStop=/home/seafile/seafile-server/seahub.sh stop RemainAfterExit=yes User=seafile Group=seafile[Install] WantedBy=multi-user.target

现在尝试使用服务和命令来启动一个新的 Seafile 服务器实例:

systemctl daemon-reload  systemctl start seafile systemctl start seahub

步骤 6. 为 Seafile 配置 Nginx Web 服务器。

*注意:在您的服务器上配置静态 IP 地址 192.168.77.21。

首先,新建一个虚拟主机文件,命名为 seafile.conf

nano /etc/nginx/sites-available/seafile.conf

添加以下行:

server {     listen 80;     server_name 192.168.77.21;proxy_set_header X-Forwarded-For $remote_addr;# Reverse proxy for seafile     location / {         fastcgi_pass    127.0.0.1:8000;         fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;         fastcgi_param   PATH_INFO           $fastcgi_script_name;fastcgi_param    SERVER_PROTOCOL        $server_protocol;         fastcgi_param   QUERY_STRING        $query_string;         fastcgi_param   REQUEST_METHOD      $request_method;         fastcgi_param   CONTENT_TYPE        $content_type;         fastcgi_param   CONTENT_LENGTH      $content_length;         fastcgi_param   SERVER_ADDR         $server_addr;         fastcgi_param   SERVER_PORT         $server_port;         fastcgi_param   SERVER_NAME         $server_name;         fastcgi_param   REMOTE_ADDR         $remote_addr;access_log      /var/log/nginx/seahub.access.log;         error_log       /var/log/nginx/seahub.error.log;         fastcgi_read_timeout 36000;     }# Reverse Proxy for seahub     location /seafhttp {         rewrite ^/seafhttp(.*)$ $1 break;         proxy_pass https://127.0.0.1:8082;         client_max_body_size 0;         proxy_connect_timeout  36000s;         proxy_read_timeout  36000s;         proxy_send_timeout  36000s;         send_timeout  36000s;     }#CHANGE THIS PATH WITH YOUR OWN DIRECTORY     location /media {         root /home/seafile/seafile-server/seahub;     } }

Save 文件并重新启动 Nginx:

systemctl restart nginx

步骤 7. 访问 Seafile。

Seafile 云存储将默认在 HTTP 端口 80 上可用。 打开您喜欢的浏览器并导航到 https://yourdomain.com 或 https://192.168.77.21。 Enter 这 admin 您在安装时创建的用于登录的电子邮件 ID 和密码。 如果您使用防火墙,请打开端口 8000 以启用对控制面板的访问。

恭喜! 您已成功安装 Seafile。 感谢您使用本教程在 Ubuntu 16.04 LTS (Xenial Xerus) 系统上安装 Seafile 开源安全云存储。 如需其他帮助或有用信息,我们建议您查看 Seafile 官方网站.

Save

Save