1 Swarm部署
1.1 注意点
- fastdfs.yml 里的 TRACKER_SERVER 是宿主主机的IP地址,部署时需要先手工设置好。
- 部署好 nginx 后,需要手工将 external/fastdfs.conf 文件拷贝到 docker volumn 的 `chaipp_nginx-conf/_data/conf.d/`目录里,并重启 nginx 服务(后续有时间自己做个镜像就不要这么麻烦了)。
- 重启Nginx后,可以访问了:http://192.168.1.220:58080/data/00/00/wKgB3F022LyAMBqgABtktRyVd54063.png
1.2 fastdfs.yml
version: '3.6'
services:
fastdfs-tracker:
image: season/fastdfs
command: tracker
volumes:
- "fastdfs-tracker-data:/fastdfs/tracker/data"
# 使用 host 网路后,不能再设置 ports,否则报错。
# ports:
# - "22122:22122"
networks:
- chahost
deploy:
placement:
constraints:
- node.role == manager
fastdfs-storage:
image: season/fastdfs
command: storage
volumes:
- "fastdfs-storage-data:/fastdfs/storage/data"
# path 目录存储了上传的文件
- "fastdfs-storage-path:/fastdfs/store_path"
- "fastdfs-storage-conf:/fdfs_conf"
environment:
TRACKER_SERVER: "192.168.1.220:22122"
networks:
- chahost
depends_on:
- season-fastdfs-tracker
deploy:
placement:
constraints:
- node.role == manager
nginx:
image: nginx
volumes:
- "nginx-conf:/etc/nginx"
- "nginx-html:/usr/share/nginx/html"
- "fastdfs-storage-path:/fastdfs"
ports:
- "58080:81"
networks:
- chanet
deploy:
placement:
constraints:
- node.role == manager
volumes:
fastdfs-tracker-data:
fastdfs-storage-data:
fastdfs-storage-path:
fastdfs-storage-conf:
nginx-conf:
nginx-html:
networks:
chanet:
driver: overlay
attachable: true
# fastdfs 网络模式必须是host, 原因是当上传文件时,tracker会把storage的IP和端口发给client,如果是bridge模式,则发送的是内网IP,client无法访问到。
chahost:
external: true
name: host
1.3 fastdfs.conf
server {
listen 81;
server_name 192.168.1.220;
# 字符显示编码集utf-8不设置网页内容可能无法显示中文
charset utf-8;
#root html;
#index index.html index.htm index.php;
location /data{
# 指定实际目录绝对路径
root /fastdfs;
# 开启目录浏览功能
autoindex on;
}
}