如果您正在寻找一种简单安全的方式来同步和共享 Ubuntu 系统上的文件,Seafile Ubuntu 是一个值得探索的解决方案。Seafile是一个自托管文件同步和协作平台,其操作类似于Dropbox或Google Drive,只是用户可以完全控制他们的数据,并有可能通过消除第三方订阅费来节省资金。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 Seafile
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。安装所需的依赖项。
Seafile 需要在您的系统上安装一些依赖项。要安装它们,请在终端中运行以下命令:
<span class="pln">sudo apt install python3 python3</span><span class="pun">-</span><span class="pln">setuptools python3</span><span class="pun">-</span><span class="pln">pip python3</span><span class="pun">-</span><span class="pln">mysqldb python3</span><span class="pun">-</span><span class="pln">dev python3</span><span class="pun">-</span><span class="pln">ldaplib python3</span><span class="pun">-</span><span class="pln">urllib3 python3</span><span class="pun">-</span><span class="pln">requests</span>
第 3 步。安装 MariaDB。
默认情况下,MariaDB 在 Ubuntu 22.04 基本存储库上可用。现在运行以下命令将最新版本的MariaDB安装到您的Ubuntu系统中:
<span class="pln">sudo apt install mariadb</span><span class="pun">-</span><span class="pln">server mariadb</span><span class="pun">-</span><span class="pln">client</span>
成功安装后,启用MariaDB(在系统启动时自动启动),启动并使用以下命令验证状态:
<span class="pln">sudo systemctl enable mariadb sudo systemctl start mariadb sudo systemctl status mariadb</span>
确认安装并检查已安装的 MariaDB 构建版本:
<span class="pln">mariadb </span><span class="pun">--</span><span class="pln">version</span>
默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方仔细阅读,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限:mysql_secure_installation
<span class="pln">mysql_secure_installation</span>
像这样配置它:
<span class="pun">-</span> <span class="typ">Set</span><span class="pln"> root password</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y</span>
现在登录到 MariaDB 控制台并为 Seafile 创建一个数据库。运行以下命令:
<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
这将提示您输入密码,因此请输入您的MariaDB root密码并按Enter键。我们将为每个服务器组件创建一个数据库。
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE seafile_server</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE ccnet_server</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE seahub_server</span><span class="pun">;</span>
然后,创建数据库用户并为创建的数据库授予权限:
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE USER </span><span class="str">'seafile'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'Your-Strong-Password'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL ON seafile_server</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'seafile'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL ON ccnet_server</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'seafile'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL ON seahub_server</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'seafile'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> QUIT</span><span class="pun">;</span>
有关安装 MariaDB 的其他资源,请阅读以下帖子:
- 如何在 Ubuntu Linux √ 上安装 MariaDB
第 4 步。在 Ubuntu 22.04 上安装 Seafile。
默认情况下,Seafile 在 Ubuntu 22.04 基本存储库上不可用。现在运行以下命令,将最新的稳定版本的 Seafile 下载到您的 Ubuntu 系统:
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_10.0.1_x86-64.tar.gz</span>
接下来,通过执行以下命令提取包:
<span class="pln">tar </span><span class="pun">-</span><span class="pln">xzf seafile</span><span class="pun">-</span><span class="pln">server_10</span><span class="pun">.</span><span class="lit">0.1</span><span class="pln">_x86</span><span class="pun">-</span><span class="lit">64.tar</span><span class="pun">.</span><span class="pln">gz</span>
移动到解压缩的目录中:
<span class="pln">cd seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="lit">10.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span>
运行安装脚本:
<span class="pun">./</span><span class="pln">setup</span><span class="pun">-</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">mysql</span><span class="pun">.</span><span class="pln">sh</span>
按照提示使用您的首选设置配置 Seafile。
完成后,现在切换到目录:/opt/seafile/seafile-server-latest
<span class="pln">cd </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">latest</span>
运行以下命令以启动 Seaf 服务器:
<span class="pun">./</span><span class="pln">seafile</span><span class="pun">.</span><span class="pln">sh start</span>
此外,运行以下命令以启动 Seahub:
<span class="pun">./</span><span class="pln">seahub</span><span class="pun">.</span><span class="pln">sh start</span>
第5步。创建海文件系统服务。
现在我们创建并打开文件进行编辑:/etc/systemd/system/seafile.service
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">systemd</span><span class="pun">/</span><span class="pln">system</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">.</span><span class="pln">service</span>
添加以下文件:
<span class="pun">[</span><span class="typ">Unit</span><span class="pun">]</span> <span class="typ">Description</span><span class="pun">=</span><span class="typ">Seafile</span> <span class="com"># add mysql.service or postgresql.service depending on your database to the line below</span> <span class="typ">After</span><span class="pun">=</span><span class="pln">network</span><span class="pun">.</span><span class="pln">target mysql</span><span class="pun">.</span><span class="pln">service </span><span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span> <span class="typ">Type</span><span class="pun">=</span><span class="pln">forking </span><span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">seafile</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">.</span><span class="pln">sh start </span><span class="typ">ExecStop</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">seafile</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">.</span><span class="pln">sh stop </span><span class="typ">LimitNOFILE</span><span class="pun">=</span><span class="pln">infinity </span><span class="typ">User</span><span class="pun">=</span><span class="pln">seafile </span><span class="typ">Group</span><span class="pun">=</span><span class="pln">seafile </span><span class="pun">[</span><span class="typ">Install</span><span class="pun">]</span> <span class="typ">WantedBy</span><span class="pun">=</span><span class="pln">multi</span><span class="pun">-</span><span class="pln">user</span><span class="pun">.</span><span class="pln">target</span>
保存并关闭文件,然后创建并打开文件进行编辑:/etc/systemd/system/seahub.service
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">systemd</span><span class="pun">/</span><span class="pln">system</span><span class="pun">/</span><span class="pln">seahub</span><span class="pun">.</span><span class="pln">service</span>
添加以下文件:
<span class="pun">[</span><span class="typ">Unit</span><span class="pun">]</span> <span class="typ">Description</span><span class="pun">=</span><span class="typ">Seafile</span><span class="pln"> hub </span><span class="typ">After</span><span class="pun">=</span><span class="pln">network</span><span class="pun">.</span><span class="pln">target seafile</span><span class="pun">.</span><span class="pln">service </span><span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span> <span class="typ">Type</span><span class="pun">=</span><span class="pln">forking </span><span class="com"># change start to start-fastcgi if you want to run fastcgi</span> <span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">seafile</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">/</span><span class="pln">seahub</span><span class="pun">.</span><span class="pln">sh start </span><span class="typ">ExecStop</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">seafile</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">/</span><span class="pln">seahub</span><span class="pun">.</span><span class="pln">sh stop </span><span class="typ">User</span><span class="pun">=</span><span class="pln">seafile </span><span class="typ">Group</span><span class="pun">=</span><span class="pln">seafile </span><span class="pun">[</span><span class="typ">Install</span><span class="pun">]</span> <span class="typ">WantedBy</span><span class="pun">=</span><span class="pln">multi</span><span class="pun">-</span><span class="pln">user</span><span class="pun">.</span><span class="pln">target</span>
保存并关闭文件,然后重新加载管理器,以便进行更改:systemd
<span class="pln">sudo systemctl daemon</span><span class="pun">-</span><span class="pln">reload sudo systemctl enable </span><span class="pun">--</span><span class="pln">now seafile sudo systemctl enable </span><span class="pun">--</span><span class="pln">now seahub</span>
第 6 步。安装Nginx。
默认情况下,Nginx 在 Ubuntu 22.04 基本存储库上可用。现在运行以下命令,将最新版本的 Nginx 安装到您的 Ubuntu 系统中:
<span class="pln">sudo apt install nginx</span>
成功安装后,启用 Nginx(在系统启动时自动启动)、启动并使用以下命令验证状态:
<span class="pln">sudo systemctl enable nginx sudo systemctl start nginx sudo systemctl status nginx</span>
确认安装并检查已安装的 Nginx 构建版本:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">v</span>
现在我们使用以下命令创建一个新的配置文件:/etc/nginx/conf.d/seafile.conf
<span class="pln">server </span><span class="pun">{</span><span class="pln"> listen </span><span class="lit">80</span><span class="pun">;</span><span class="pln"> listen </span><span class="pun">[::]:</span><span class="lit">80</span><span class="pun">;</span><span class="pln"> server_name </span><strong><span class="has-inline-color has-vivid-green-cyan-color"><span class="pln">seafile</span><span class="pun">.</span><span class="pln">your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span></span></strong><span class="pun">;</span><span class="pln"> autoindex off</span><span class="pun">;</span><span class="pln"> client_max_body_size </span><span class="lit">100M</span><span class="pun">;</span><span class="pln"> access_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">.</span><span class="pln">com</span><span class="pun">.</span><span class="pln">access</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span><span class="pln"> error_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">.</span><span class="pln">com</span><span class="pun">.</span><span class="pln">error</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span><span class="pln"> location </span><span class="pun">/</span> <span class="pun">{</span><span class="pln"> proxy_pass http</span><span class="pun">:</span><span class="com">//127.0.0.1:8000;</span><span class="pln"> proxy_set_header </span><span class="typ">Host</span><span class="pln"> $host</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="pln">IP $remote_addr</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Host</span><span class="pln"> $server_name</span><span class="pun">;</span><span class="pln"> proxy_read_timeout </span><span class="lit">1200s</span><span class="pun">;</span> <span class="pun">}</span><span class="pln"> location </span><span class="pun">/</span><span class="pln">seafhttp </span><span class="pun">{</span><span class="pln"> rewrite </span><span class="pun">^/</span><span class="pln">seafhttp</span><span class="pun">(.*)</span><span class="pln">$ $1 </span><span class="kwd">break</span><span class="pun">;</span><span class="pln"> proxy_pass http</span><span class="pun">:</span><span class="com">//127.0.0.1:8082;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span><span class="pln"> proxy_connect_timeout </span><span class="lit">36000s</span><span class="pun">;</span><span class="pln"> proxy_read_timeout </span><span class="lit">36000s</span><span class="pun">;</span><span class="pln"> proxy_send_timeout </span><span class="lit">36000s</span><span class="pun">;</span><span class="pln"> send_timeout </span><span class="lit">36000s</span><span class="pun">;</span> <span class="pun">}</span><span class="pln"> location </span><span class="pun">/</span><span class="pln">media </span><span class="pun">{</span><span class="pln"> root </span><span class="pun">/</span><span class="pln">srv</span><span class="pun">/</span><span class="pln">seafile</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">/</span><span class="pln">seahub</span><span class="pun">;</span> <span class="pun">}</span> <span class="pun">}</span>
保存并关闭文件,然后重新启动 Nginx Web 服务器,以便进行更改:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">t sudo systemctl restart nginx</span>
步骤 7.配置防火墙。
Ubuntu 22.04 默认运行防火墙。启用通过端口 HTTP 和 HTTPS 的连接:ufw
80
443
<span class="pln">sudo ufw allow </span><span class="str">'Nginx FULL'</span><span class="pln"> sudo ufw enable sudo ufw status</span>
第8步。访问海文件网页界面。
成功安装后,您可以使用首选的Web浏览器访问Seafile网络界面。打开浏览器并输入以下地址:
<span class="pln">http</span><span class="pun">:</span><span class="com">//seafile.your-domain.com</span>
您应该看到以下页面:
感谢您使用本教程在 Ubuntu 系统上安装 Seafile。如需其他帮助或有用信息,我们建议您查看官方 Seafile 网站。