说明:本人使用的是单节点,tracker和storage的ip均为192.168.1.201.仅作为测试使用
原文档为:https://github.com/LionHeartFXCX/fastdfsOnDocker
上面有少许错误,在配置nginx复制文件错了.
1.下载镜像
#docker pull index.alauda.cn/lionheart/fastdfs_storage
#docker pull index.alauda.cn/lionheart/fastdfs_tracker
2.创建配置文件的目录
mkdir -p /home/fastdfs/tracker
mkdir -p /home/fastdfs/storage
3.创建备用的container,用来复制文件
docker run -d --name trackerconfig
docker run -d --name storageconfig
4.拷贝配置文件(分为4个部分,fdfs_conf,etc_conf,nginx_conf,fast_file)
1)tracker
- fdfs
docker cp trackerconfig:/home/fastdfs/fastdfs-5.05/conf /home/fastdfs/tracker/
mv /home/fastdfs/tracker/conf /home/fastdfs/tracker/fdfs_conf - etc
docker cp trackerconfig:/etc/fdfs /home/tracker/
mv /home/fastdfs/tracker/fdfs /home/fastdfs/tracker/etc_conf - nginx
docker cp trackerconfig:/usr/local/nginx/conf /home/tracker/
mv /home/fastdfs/tracker/conf /home/fastdfs/tracker/nginx_conf - fast_file
docker cp trackerconfig:/home/fastdfs_file /home/fastdfs/tracker/
2)storage
- fdfs
docker cp storageconfig:/home/fastdfs/fastdfs-5.05/conf /home/fastdfs/storage/
mv /home/fastdfs/storage/conf /home/fastdfs/storage/fdfs_conf
- etc
docker cp storageconfig:/etc/fdfs /home/fastdfs/storage/
mv /home/fastdfs/storage/fdfs /home/fastdfs/storage/etc_conf
- nginx
docker cp storageconfig:/usr/local/nginx/conf /home/storage/
mv /home/fastdfs/storage/conf /home/fastdfs/storage/nginx_conf
- fast_file
docker cp storageconfig:/home/fastdfs_file /home/fastdfs/storage/
5.分别修改
vi /home/fastdfs/storage/fdfs_conf/storage.conf
tracker_server=ipaddress:22122
(ipaddress为具体的ip地址,为你所部署的该节点的ip地址,如192.168.0.1,该ip地址不能为localhost或者127.0.0.1,如果将tracker和storage节点部署在一台服务器上,那么就用其对外公开的ip地址来代替)
vi /home/fastdfs/tracker/nginx_conf/nginx.conf
修改storage的ip地址
vi /home/fastdfs/storage/etc_conf/mod_fastdfs.conf
tracker_server=ipaddress:22122
6.创建用于运行的容器(创建之后会进入容器中,输入exit退出)
docker run -it --name tracker --net=host --privileged=true \
-v /home/fastdfs/tracker/fdfs_conf:/home/fastdfs/fastdfs-5.05/conf/ \
-v /home/fastdfs/tracker/nginx_conf:/usr/local/nginx/conf/ \
-v /home/fastdfs/tracker/etc_conf:/etc/fdfs \
-v /home/fastdfs/tracker/fastdfs_file:/home/fastdfs_file \
index.alauda.cn/lionheart/fastdfs_tracker
docker run -it --name storage --net=host --privileged=true \
-v /home/fastdfs/storage/fdfs_conf:/home/fastdfs/fastdfs-5.05/conf/ \
-v /home/fastdfs/storage/nginx_conf:/usr/local/nginx/conf/ \
-v /home/fastdfs/storage/etc_conf:/etc/fdfs \
-v /home/fastdfs/storage/fastdfs_file:/home/fastdfs_file \
index.alauda.cn/lionheart/fastdfs_storage
7.运行
1)tracker节点
docker start tracker
docker exec tracker fdfs_trackerd /home/fastdfs/fastdfs-5.05/conf/tracker.conf
docker exec tracker /usr/local/nginx/sbin/nginx
2)storage节点
docker start storage
docker exec storage fdfs_storaged /home/fastdfs/fastdfs-5.05/conf/storage.conf
docker exec storage /usr/local/nginx/sbin/nginx
8.测试
在tracker节点上运行测试命令即可
修改/home/fastdfs/tracker/fdfs_conf/client.conf
tracker_server=192.168.1.201:22122
放一张图片到/home/fastdfs/tracker/fastdfs_file中
运行:
docker exec tracker fdfs_test /home/fastdfs/fastdfs-5.05/conf/client.conf upload /home/fastdfs_file/1.jpg
结果为:
FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.1.201, port=23000
group_name=group1, ip_addr=192.168.1.201, port=23000 storage_upload_by_filename group_name=group1, remote_filename=M00/00/00/wKgByVeErs2Afw9RAATel2Yx1ck351.jpg source ip address: 192.168.1.201 file timestamp=2016-07-12 08:48:13 file size=319127 file crc32=1714542025 example file url: http://192.168.1.201/group1/M00/00/00/wKgByVeErs2Afw9RAATel2Yx1ck351.jpg storage_upload_slave_by_filename group_name=group1, remote_filename=M00/00/00/wKgByVeErs2Afw9RAATel2Yx1ck351_big.jpg source ip address: 192.168.1.201 file timestamp=2016-07-12 08:48:13 file size=319127 file crc32=1714542025 example file url: http://192.168.1.201/group1/M00/00/00/wKgByVeErs2Afw9RAATel2Yx1ck351_big.jpg |
在浏览器中输入相应的url,即可访问
注意点:
1)在tracker节点上,tracker配置nginx为80端口
2)在storage节点上,storage配置nginx为8888端口,所以结果的url使用storage的ip也可以访问
如: http://(storageip):8888/group1/M00/00/00/wKgByVeErs2Afw9RAATel2Yx1ck351_big.jpg
3)在tracker节点上的nginx使用了ngx_cache_purge模块
4)在storage节点上的nginx使用了fastdfs-nginx-module 模块