一,查看本地centos的版本
[root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)
說明:架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,查看fdfs的版本
[root@localhost data]# fdfs_monitor /etc/fdfs/client.conf | grep version version = 6.06
三,配置storage.conf文件
[root@localhost fdfs]# vi /etc/fdfs/storage.conf
以下為各示例項的值:
我們創建3個path:
base_path = /data/fastdfs store_path_count = 3 store_path0 = /data/fastdfs/storage0 store_path1 = /data/fastdfs/storage1 store_path2 = /data/fastdfs/storage2
說明: base_path應該位於多個子目錄的父層級
store_path的名字應該從0開始:例:store_path0、store_path1、
一個group中有多台storage server時,每台機器上的子目錄配置應相同
四,創建storage.conf中配置的各個子目錄
[root@localhost liuhongdi]# mkdir /data/fastdfs/storage0 [root@localhost liuhongdi]# mkdir /data/fastdfs/storage1 [root@localhost liuhongdi]# mkdir /data/fastdfs/storage2 [root@localhost liuhongdi]# chmod 777 /data/fastdfs/storage1 [root@localhost liuhongdi]# chmod 777 /data/fastdfs/storage0 [root@localhost liuhongdi]# chmod 777 /data/fastdfs/storage2
五,重啟服務
[root@localhost liuhongdi]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop [root@localhost liuhongdi]# ps auxfww | grep fdfs root 5157 0.0 0.0 12320 1076 pts/0 S+ 16:41 0:00 | \_ grep --color=auto fdfs root 4703 0.0 0.1 155692 6964 ? Sl 16:27 0:00 \_ /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start [root@localhost liuhongdi]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start [root@localhost liuhongdi]# ps auxfww | grep fdfs root 5203 0.0 0.0 12320 1100 pts/0 S+ 16:42 0:00 | \_ grep --color=auto fdfs root 4703 0.0 0.1 155692 6964 ? Sl 16:27 0:00 \_ /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start root 5190 92.5 0.0 15168 2312 ? R 16:42 0:03 \_ /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
六,查看新建的目錄是否已被fastdfs管理
[root@localhost liuhongdi]# ls /data/fastdfs/storage0/data/
說明:如果看到fastdfs已在配置目錄下創建了 data及logs目錄,表示目錄被初始化成功
七,測試上傳到指定目錄
[root@localhost liuhongdi]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/liuhongdi/image/nginx.jpg 192.168.3.172:23000 1 group1/M01/00/00/wKgDrF5WMRWAFebkAAAyP-hllUI424.jpg
[root@localhost liuhongdi]# ls /data/fastdfs/storage1/data/00/00/ wKgDrF5WMRWAFebkAAAyP-hllUI424.jpg
說明: fdfs_upload_file命令行最后的參數1,表示對應 store_path1
如果為0,表示對應 store_path0
說明:返回的path是M01,和我們設置的path相對應
從storage1目錄下可以看到相應的文件
八,在web訪問中的配置
1,修改fastdfs的nginx模塊的配置文件
[root@localhost liuhongdi]# vi /etc/fdfs/mod_fastdfs.conf
設置以下幾項:
store_path_count=3 store_path0=/data/fastdfs/storage0 store_path1=/data/fastdfs/storage1 store_path2=/data/fastdfs/storage2
2,重啟nginx
[root@localhost liuhongdi]# /usr/local/soft/nginx/sbin/nginx -s stop ngx_http_fastdfs_set pid=5946 [root@localhost liuhongdi]# /usr/local/soft/nginx/sbin/nginx ngx_http_fastdfs_set pid=5959
3,測試效果:
從瀏覽器訪問:
http://192.168.3.172/group1/M01/00/00/wKgDrF5WMRWAFebkAAAyP-hllUI424.jpg
可以看到圖片