FastDFS的實現 環境 FastDFS的實現 FastDFS實現nginx代理 ...
FastDFS的實現
環境
centos7.1節點提供tracker和storage服務
centos7.2,centos7.3只提供storage服務
FastDFS的實現
fastdfs-5.0.11-1.el7.centos.x86_64.rpm #主程式
fastdfs-debuginfo-5.0.11-1.el7.centos.x86_64.rpm #debug先關的包
fastdfs-server-5.0.11-1.el7.centos.x86_64.rpm #提供tracker和storage節點的服務
fastdfs-tool-5.0.11-1.el7.centos.x86_64.rpm #工具包
libfastcommon-1.0.36-1.el7.centos.x86_64.rpm #下麵四個是依賴的包
libfastcommon-devel-1.0.36-1.el7.centos.x86_64.rpm
libfdfsclient-5.0.11-1.el7.centos.x86_64.rpm
libfdfsclient-devel-5.0.11-1.el7.centos.x86_64.rpm
nginx-1.10.2-1.el7.centos.x86_64.rpm #使用nginx做為web界面需要用到的包
nginx-all-modules-1.10.2-1.el7.centos.noarch.rpm
nginx-filesystem-1.10.2-1.el7.centos.noarch.rpm
nginx-mod-http-geoip-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-http-image-filter-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-http-perl-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-http-xslt-filter-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-mail-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-stream-1.10.2-1.el7.centos.x86_64.rpm
1》安裝
yum localinstall ./* #安裝軟體
cd /etc/fdfs/ ;ls #發現有很多示例
anti-steal.jpg client.conf.sample http.conf mime.types storage.conf.sample storage_ids.conf.sample tracker.conf.sample
2》在centos7.1節點上配置tracker節點
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf.sample.bak
mv tracker.conf.sample tracker.conf
vim tracker.conf
base_path=/app/fastdfs/tracker #設置tracker的存儲路徑
store_group=shen #設置一個存儲組,註意不能帶任何符號,不然會出現埠啟用不了
mkdir -pv /app/fastdfs/tracker #在centos7.1節點上創建tracker的數據目錄
mkdir /app/fastdfs/storage #創建storage的存儲目錄
3》在centos7.2和7.3節點上只創建storage的存儲目錄
mkdir /app/fastdfs/storage -pv
4》在三個節點上對storage進行配置
cd /etc/fdfs/
cp storage.conf.sample storage.conf.sample.bak
mv storage.conf.sample storage.conf
vim storage.conf
group_name=shen
base_path=/app/fastdfs/storage #storage的基礎路徑,用於存儲日誌等
store_path0=/app/fastdfs/storage #storage的存儲路徑,這個必須設置,可以和上面的在同一個目錄下
tracker_server=192.168.213.251:22122 #指明tracker主機
在centos7.1節點上啟動tracker和storage服務
systemctl start fdfs_trackerd
systemctl start fdfs_storaged
ss -nltp #發現tracker監聽的埠是22122,storage監聽的埠是23000
在centos7.2和7.3節點上啟動storage服務
systemctl start fdfs_storaged
ss -nlt #發現23000埠已經打開
5》配置客戶端的配置文件,在centos7.1節點設置
cd /etc/fdfs/ ;ls
anti-steal.jpg http.conf storage.conf storage_ids.conf.sample tracker.conf.sample.bak
client.conf.sample mime.types storage.conf.sample.bak tracker.conf
cp client.conf.sample client.conf.bak
mv client.conf.bak client.conf
vim client.conf
base_path=/app/fastdfs/tracker
tracker_server=192.168.213.251:22122
fdfs_monitor /etc/fdfs/client.conf #可以查看存儲節點的狀態信息
6》文件的上傳和查看操作
cd /etc/fdfs/ ;ls
anti-steal.jpg client.conf.sample mime.types storage.conf.sample.bak tracker.conf
client.conf http.conf storage.conf storage_ids.conf.sample tracker.conf.sample.bak
fdfs_upload_file /etc/fdfs/client.conf /app/flower.jpg #註意上傳時要指明客戶端的配置文件
shen/M00/00/00/wKjV-1o01sOAHG17AAAN9EUC0YY902.jpg
cd /app/fastdfs/storage/data/00/00/ ;ls #每個節點的此目錄下都有這個文件,說明同步成功
wKjV-1o01sOAHG17AAAN9EUC0YY902.jpg
fdfs_file_info /etc/fdfs/client.conf shen/M00/00/00/wKjV-1o01sOAHG17AAAN9EUC0YY902.jpg #查看文件
source storage id: 0
source ip address: 192.168.213.251
file create timestamp: 2017-12-16 16:18:11
file size: 3572
file crc32: 1157812614 (0x4502D186)
fdfs_test /etc/fdfs/client.conf upload /root/anaconda-ks.cfg #上傳測試
fdfs_upload_file /etc/fdfs/client.conf /root/anaconda-ks.cfg #上傳文件
magedu/M00/00/00/rBIVB1oylFSADeGrAAAHXGXWizs514.cfg
fdfs_download_file /etc/fdfs/client.conf magedu/M00/00/00/rBIVB1oylFSADeGrAAAHXGXWizs514.cfg #下載文件到當前目錄
FastDFS實現nginx代理
1》在centos7.1節點安裝nginx的相關包,註意要安裝nginx-1.10版本,不然可能沒有ngx_fastdfs_module模塊,如果之前已經安裝nginx及相應的依賴包,最好先卸載了
cd /app
ls #將nginx-1.10.2版本的nginx及相應的依賴包下載到本地
nginx-1.10.2-1.el7.centos.x86_64.rpm #註意版本要統一都是1.10.2的版本
nginx-all-modules-1.10.2-1.el7.centos.noarch.rpm #下麵這些都是nginx的依賴包
nginx-filesystem-1.10.2-1.el7.centos.noarch.rpm
nginx-mod-http-geoip-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-http-image-filter-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-http-perl-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-http-xslt-filter-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-mail-1.10.2-1.el7.centos.x86_64.rpm
nginx-mod-stream-1.10.2-1.el7.centos.x86_64.rpm
yum install ./nginx*
2》修改nginx的配置文件
vim /etc/nginx/nginx.conf
location /magedu/M00 { #表示匹配以 /magdu/M00開頭的uri
root /app/fastdfs/storage; #指明數據存儲的目錄
ngx_fastdfs_module;
}
nginx
ngx_http_fastdfs_set pid=14594
ss -nlt
3》修改fastdfs_module配置文件的設置
vim /etc/fdfs/mod_fastdfs.conf
url_have_group_name = true #是否允許訪問的url中包含組名
store_path0=/app/fastdfs/storage #指明storage節點存儲數據的目錄
tracker_server=172.18.21.107:22122 #指明tracker節點
group_name=magedu #指明組名
4》測試
fdfs_upload_file /etc/fdfs/client.conf /app/sunset.jpg #上傳一個文件
magedu/M00/00/00/rBIVa1ozvNWAJLHkAAAKwLGLsZc035.jpg
訪問如下網站就可以看到存儲的圖片
http://172.18.21.107/magedu/M00/00/00/rBIVa1ozvNWAJLHkAAAKwLGLsZc035.jpg