Docker安装FastDFS
1,升级所有软件包
[root@localhost /]# sudo yum update
2,执行 Docker 安装脚本
[root@localhost /]# curl -fsSL https://get.docker.com -o get-docker.sh
[root@localhost /]# sudo sh get-docker.sh
3,启动 Docker 进程
[root@localhost /]# sudo systemctl start docker
4,设置Docker开机启动
[root@localhost /]# systemctl enable docker
5,查看可用的FastDFS镜像
[root@localhost /]# docker search fastdfs
6,拉取morunchang/fastdfs FastDFS镜像
[root@localhost /]# docker pull morunchang/fastdfs
7,查看拉取的 FastDFS镜像
8,作为跟踪节点启动容器服务
[root@localhost /]# docker run -d --name tracker --net=host morunchang/fastdfs sh tracker.sh
9,作为存储节点启动容器服务
[root@localhost /]# docker run -d --name storage --net=host -e TRACKER_IP=192.168.1.199:22122 -e GROUP_NAME=group1 -v /root/data/fast_data:/data/fast_data morunchang/fastdfs sh storage.sh
其中192.168.1.199修改为你的IP地址;
/root/data/fast_data:/data/fast_data 是将容器内的存储路径映射到本地;
10,查看启动的容器
11,进入跟踪容器内部,修改配置
[root@localhost ~]# docker exec -it tracker /bin/bash
root@localhost:/# cd etc/nginx/conf/
root@localhost:/etc/nginx/conf# vi nginx.conf
修改nginx配置
root@localhost:/etc/nginx/conf# cd /etc/fdfs/
root@localhost:/etc/fdfs# vi client.conf
修改client.conf配置
root@localhost:/etc/fdfs# vi tracker.conf
修改tracker.conf配置
退出容器
root@localhost:/etc/fdfs# exit
12,进入存储容器内部,修改配置
[root@localhost ~]# docker exec -it storage /bin/bash
root@localhost:/# cd etc/nginx/conf/
root@localhost:/etc/nginx/conf# vi nginx.conf
修改nginx配置
root@localhost:/etc/nginx/conf# cd /etc/fdfs/
root@localhost:/etc/fdfs# vi client.conf
修改client.conf配置
root@localhost:/etc/fdfs# vi storage.conf
修改storage.conf配置
root@localhost:/etc/fdfs# vi http.conf
修改默认错误路径,http.anti_steal.check_token=true的意思为打开防盗链功能,http.anti_steal.secret_key=FastDFS1234567890为相应的秘钥,默认是false,如果是测试的话不需要改为ture;http.anti_steal.token_check_fail=/home/error.html指向错误加载路径,默认的文件找不到会报错,在这里我们把他修改为自定义的一个文件
创建错误加载文件
root@localhost:/# cd /
root@localhost:/# cd home/
root@localhost:/home# touch error.html
root@localhost:/home# ls
error.html
root@localhost:/home# vi error.html
退出容器
root@localhost:/etc/fdfs# exit
13,重启跟踪节点和存储节点容器
[root@localhost ~]# docker restart tracker
[root@localhost ~]# docker restart storage
14,测试
[root@localhost ~]# docker exec -it storage /bin/bash
root@localhost:/# touch test.html
root@localhost:/# vi test.html
root@localhost:/# fdfs_upload_file storage.conf test.html
group1/M00/00/14/wKgBx11Pc_6Ab2rYAAAABSV-x8w65.html
root@localhost:/#
访问http://192.168.1.199/group1/M00/00/14/wKgBx11Pc_6Ab2rYAAAABSV-x8w65.html