docker安装fastdfs
- 拉取镜像
docker pull delron/fastdfs - 启动tracker服务
docker run -d --network=host --name tracker -v /root/fastdfs/tracker:/var/fdfs delron/fastdfs tracker - 启动storage服务
docker run -d --name storage --restart=always --net host -v /root/fastdfs/storage:/var/fdfs -e TRACKER_SERVER="IP地址:22122" delron/fastdfs storage
-
最基础的fastdfs已经可以使用啦
-
测试
docker exec -it storage bash echo "test" > test.txt fdfs_upload_file /etc/fdfs/client.conf test.txt 返回一个地址 ip:8888/group1/M00/00/00/**********************
多个项目使用不用的路径存储
项目环境是单节点,在同一group下,分项目目录来存储不同项目内容。
新建存储目录
mkdir -p /data/fastdfs/storage/blog
然后编辑存储文件
编辑 vim /etc/fdfs/storage.conf
store_path_count=2
store_path0=/data/fastdfs/storage/blog
store_path1=/data/fastdfs/storage/img
编辑 mod_fastdfs.conf
[root@VM-0-9-centos ~]# vim /etc/fdfs/mod_fastdfs.conf
store_path_count=2
store_path0=/data/fastdfs/storage/blog
store_path1=/data/fastdfs/storage/img
group_count = 0
[group1]
group_name=group1
storage_server_port=23000
store_path_count=2
store_path0=/data/fastdfs/storage/blog
store_path1=/data/fastdfs/storage/img
配置nginx
-
配置二级域名,指向8888端口
vim /root/nginx/conf.d/blog.conf
server { listen 80; server_name img.lvxiaoyi.top; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://IP地址:8888; } }
-
vim /usr/local/nginx/conf/nginx.conf
server {
listen 8888;
server_name 二级域名;
#location ~/group[0-9]/ {
# ngx_fastdfs_module;
#}
#
location /group1/M00 {
alias /data/fastdfs/storage/blog/data;
# ngx_fastdfs_module;
}
location /group1/M01 {
alias /data/fastdfs/storage/img/data;
# ngx_fastdfs_module;
}
测试
把文件传输到第一个项目中
fdfs_upload_file /etc/fdfs/client.conf test.txt IP地址:23000 0
group1/M00/00/00/rBEACWAqiOeAD54SAAAAIE3xxaY240.txt
把文件传输到第二个文件中
fdfs_upload_file /etc/fdfs/client.conf test.txt IP地址:23000 1
访问
http://域名/group1/M00/00/00/rBEACWAqiOeAD54SAAAAIE3xxaY240.txt