安全、可靠、快速的企业云盘 Seafile 是一款开源的企业云盘,注重可靠性和性能。支持 Windows, Mac, Linux, iOS, Android 平台。支持文件同步或者直接挂载到本地访问。html
以上文案来自于官网,Seafile 官网node
Seafile 有个开源的服务器部署版本,并且是支持 Docker 部署的,本着熟悉熟悉 Docker 的初衷,我踏上了折腾的不归路。linux
大概能够分为如下步骤:nginx
官方文档:Get Docker CE for Ubuntuweb
sudo apt-get remove docker docker-engine docker.io containerd runc
复制代码
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
复制代码
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
复制代码
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
复制代码
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
复制代码
sudo docker run hello-world
复制代码
sudo groupadd docker # 新增 docker group
sudo gpasswd -a $USER docker # 将 docker 添加到 docker group 中
sudo service docker restart # 重启 docker 服务
newgrp - docker # 切换当前会话到新的 group
复制代码
使用阿里云的 Docker 镜像加速器,避免因为某些神秘缘由致使的镜像下载过慢docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://frsj7mun.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
复制代码
经过 Docker 官方镜像加速,中国区用户可以快速访问最流行的 Docker 镜像。shell
Docker 中国官方镜像加速json
服务器的端口号是有限的,并且默认都是使用 80 端口或 443 端口,使用 Docker 经过 Nginx 实现反向代理,配置多域名及多端口号。ubuntu
将一级或者二级域名绑定在服务器 IP 上,vim
docker pull nginx
复制代码
docker run –-name=nginx -p 80:80 -p 443:443 -v /nginx/conf.d:/etc/nginx/conf.d -d nginx
复制代码
上述命令会建立一个名为 nginx 的容器,端口映射为 80-80、443-443,文件夹映射为本机 /nginx/conf.d/
映射到镜像的 /etc/nginx/conf.d
文件夹,-d
表示在后台运行容器
/nginx/conf.d
目录下建立容器的 Nginx 配置文件cd /nginx/conf.d
sudo vim seafile.wangyongf.com.conf
复制代码
server {
listen 80;
server_name wangyongf.com; # 要解析进来域名
location / {
proxy_pass http://SERVER_LOCAL_IP:8001; # 服务器本地ip:Seafile容器对外的端口号
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
复制代码
服务器本地IP能够在云服务管理控制台看到,也能够在命令行直接查看。
请求的转发流程:
docker run -d --name seafile \
-e SEAFILE_SERVER_HOSTNAME=seafile.wangyongf.com \
-v /opt/seafile-data:/shared \
-p 8001:80 \
seafileltd/seafile:latest
复制代码
docker run -d --name seafile \
-e SEAFILE_SERVER_HOSTNAME=seafile.wangyongf.com \
-e SEAFILE_ADMIN_EMAIL=me@wangyongf.com \
-e SEAFILE_ADMIN_PASSWORD=a_very_secret_password \
-v /opt/seafile-data:/shared \
-p 8001:80 \
seafileltd/seafile:latest
复制代码
docker run -d --name seafile \
-e SEAFILE_SERVER_LETSENCRYPT=true \
-e SEAFILE_SERVER_HOSTNAME=seafile.wangyongf.com \
-e SEAFILE_ADMIN_EMAIL=me@wangyongf.com \
-e SEAFILE_ADMIN_PASSWORD=a_very_secret_password \
-v /opt/seafile-data:/shared \
-p 8001:80 \
-p 8002:443 \
seafileltd/seafile:latest
复制代码
Seafile 服务的配置会存放在 /shared/seafile/conf
目录下,你能够根据 Seafile 手册修改配置。
修改以后须要重启容器:
docker restart seafile
复制代码
到了这里,应该配置 OK 了。我在文章里也提到了不少的官方文档,若是遇到了问题,能够查阅官方文档,或者借助 Google/Baidu
建议开启 Seafile 的 https 配置,若是只是安装玩玩,那么无所谓,若是是真的本身使用,最好启用 https,不然你的文件不太安全呀呀呀呀。
本文中讨论的都是基于 Docker 部署的 Nginx 服务,和服务器上直接安装可能会有些区别。
上文中也说了,Seafile 的 Docker 官方镜像可配置启用 https,但实际上,也能够在 Nginx 层就启用 https,而后反向代理的时候使用 http 亦可,我在实践的时候就是采用的这种方式。
Nginx Docker 层启用 seafile.wangyongf.com 的操做步骤以下(个人操做步骤):
/nginx/conf.d/seafile.wangyongf.com.conf
中,此时配置文件大概长这样:server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
server_name seafile.wangyongf.com;
root /var/www/html;
# ssl configurations
ssl_certificate /ssl/live/seafile.wangyongf.com/fullchain.pem;
ssl_certificate_key /ssl/live/seafile.wangyongf.com/privkey.pem;
include /ssl/options-ssl-nginx.conf;
ssl_dhparam /ssl/ssl-dhparams.pem;
location / {
proxy_pass http://SERVER_LOCAL_IP:8001;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
if ($host = seafile.wangyongf.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name seafile.wangyongf.com;
return 404;
}
复制代码
能够看到,上述配置有几点:
为何证书是 /ssl/
目录呢,其实这个目录是我自定义的,你也能够随便叫什么别的目录,上文中咱们提到,这个配置是在 /nginx/conf.d/
下,是 Docker Nginx 的配置文件,容器内是访问不到宿主文件的,只能经过文件映射,所以必须将宿主上的ssl证书映射到容器中,对的,上述 /ssl/
就是映射的虚拟目录,其对应的是宿主上的 /etc/letsencrypt
目录。
所以,若是要使用上述的 Nginx 配置,Docker Nginx 容器须要新增一个 /etc/letsencrypt
到 /ssl
的目录映射,可是貌似 Docker 容器在建立完成以后没法再修改映射目录?(若是能够,欢迎留言告诉我~),我就基于现有的容器从新建了个容器,使用以下命令:
docker stop nginx
docker commit nginx seafile-nginx
docker run –-name=nginx -p 80:80 -p 443:443 -v /nginx/conf.d:/etc/nginx/conf.d -v /etc/letsencrypt:/ssl -d nginx
复制代码
sudo nginx -t (-c /etc/nginx/conf.d/default.conf)
复制代码
以后,也可使用相似的方式使用 Nginx 的反向代理部署其余的 Docker 服务
到了这里,应该没什么问题了,Seafile 应该已是 https 可访问状态了,这个时候,你能够下载个移动客户端,按照官方教程配置好,而后就开始愉快地使用 Seafile 吧~