Seafile私有云盘搭建详解

目前,开源私有云盘的可选方案有:Seafile、Nextcloud、ownCloud、可道云等等,前两个为目前最火热的方案。考虑到国产化因素,本文最终选择了由清华大学的学长开发的Seafile,目前已在北大、清华等高校、中国平安等金融机构使用。

1. 服务器系统要求

  • Seafile 6.0.7版本:Windows服务器端
  • Seafile 7.0.x版本(基于Python2):CentOS 7、Ubuntu 16.04
  • Seafile 7.1.x版本(基于Python3):CentOS 8、Ubuntu 18.04、Debian 10

总结:考虑到2020年1月1日起,官方宣布结束对Python2.7的支持,建议选择最新的7.1.x版本,使用Centos 8等服务器系统。

确定服务器系统版本后,如果使用的是VMware虚拟机,需要配置网路,设定一个静态IP用作远程连接和日后访问,并保证内外网络相通,并开放8000、8082端口;如果使用的阿里云或腾讯云服务器,无需配置网络环境(本身就能与互联网互通),但需要在安全组中开放8000、8082端口。

2. 安装系统环境

  • 数据库:MySQL、SQLite
  • Web服务器:Nginx、Apache
  • 语言环境:Python2、Python3
  • 其他:python3-setuptools、python3-pip、python3-ldap(必选)

总结:本文最终选用CentOS 8+MySQL+Nginx+Python3+Seafile 7.1.x

由于MySQL、Nginx的安装教程已有很多,本文不再赘述(需要注意的是,安装完MySQL后进行初始化,并记住密码)。Python3及相关依赖环境的安装直接执行以下代码即可:

yum install python3 python3-setuptools python3-pip python3-ldap -y
pip3 install --timeout=3600 Pillow pylibmc captcha jinja2 sqlalchemy psd-tools \django-pylibmc django-simple-captcha

3. 安装Seafile服务器

  • 第一步:下载Seafile服务器安装包
https://www.seafile.com/download/
  • 第二步:在服务器上新建Seafile目录
mkdir /opt/Seafile
  • 第三步:将下载好的Seafile服务器安装包通过FTP工具上传至/opt/seafile目录
  • 第四步:在终端中,解压并安装Seafile
cd /opt/seafile
tar -xzf seafile-server_*
mkdir installed
mv seafile-server_* installed #将压缩包移至installed目录中,之后就用不着它了
cd /opt/seafile/seafile-server-* #进入解压包的目录
./setup-seafile-mysql.sh #运行安装脚本
  • 第五步:依据提示,输入相关信息。需要注意的是,数据库选项选择“新建数据库”,接着输入上文提到的MySQL密码。官方手册没有指出要自己配置数据库和Web服务器,导致许多新入门的同学在输入数据库密码这一步卡死。
  • 第六步:测试一下seafile服务器能否启动,显示success即证明安装成功。
cd /opt/seafile/seafile-server-* #进入Seafile服务器目录
./seafile.sh start # 启动 Seafile 服务
./seahub.sh start  # 启动 Seahub 网站 (默认运行在127.0.0.1:8000端口上)
  • 第七步:恭喜你已经完成Seafile服务器的安装,进度条已到达80%,再简单配置一下Nginx就大功告成啦。

4. 配置环境

cd /etc/nginx #进入你安装的Nginx目录
vim nginx.conf #修改Nginx配置文件,具体如下:(需要将server_name改为自己的IP地址,其余部分可以不用改)

------------------------------------------------------------------------------------------------------------
user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
	client_max_body_size 0; #上传文件大小不设限,原配置是限制了1M的上传大小

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  1.1.1.1;
		proxy_set_header X-Forwarded-For $remote_addr;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
			 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;

         # used for view/edit office file via Office Online Server

         client_max_body_size 0;

         access_log      /var/log/nginx/seahub.access.log;

         error_log       /var/log/nginx/seahub.error.log;

        }
		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 /media {

        root /opt/seafile/seafile-server-latest/seahub;

    }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  1.1.1.1;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
  • 接着,重启Nginx
nginx -s reload

5. 启动

./seafile.sh restart # 停止当前的 Seafile 进程,然后重启 Seafile
./seahub.sh restart  # 停止当前的 Seahub 进程,并在 8000 端口重新启动 Seahub

在浏览器中,输入你的IP地址,即可登录

大功告成~~~

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YClIrKug-1601195472001)(

6. 总结与展望

在功能方面,基础版的Seafile已经搭建完成了,后续可以安装OnlyOffice等工具实现在线预览PDF、Doc等功能,可参考https://www.jianshu.com/p/26c955e8c26a

在外观方面,可以自定义颜色、图标等

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐