CentOS7 安裝FastDFS分布式文件系統


CentOS7 安裝FastDFS分布式文件系統

最近要用到fastDFS,所以自己研究了一下,在搭建FastDFS的過程中遇到過很多的問題,為了能幫忙到以后搭建FastDFS的同學,少走彎路,與大家分享一下。FastDFS的作者淘寶資深架構余慶,這個優秀的輕量及的分布式文件系統的開源沒多久,立馬就火了。

FastDFS是為互聯網應用量身定做的一套分布式文件存儲系統,非常適合用來存儲用戶圖片、視頻、文檔等文件

版本介紹

系統:centos7.4

fastdfs-6.06.tar.gz

libfastcommon-1.0.43.tar.gz 

fastdfs-nginx-module-1.22.tar.gz

nginx-1.17.7.tar.gz

一.FastDFS搭建工具下載

作者的GitHub地址:https://github.com/happyfish100

下載地址:

nginx地址

二:使用 wget 命令下載壓縮包,如果沒有 wget 命令使用 yum 命令安裝

yum install wget

三:下載 fastdfs

wget -c "https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz" \
-O fastdfs-6.06.tar.gz

四:下載 libfastcommon

wget -c "https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz" \
-O libfastcommon-1.0.43.tar.gz

五:下載 fastdfs-nginx-module

wget -c "https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz" \
-O fastdfs-nginx-module-1.22.tar.gz

六:下載 nginx

wget -c http://nginx.org/download/nginx-1.17.7.tar.gz

七:安裝編譯工具及庫文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

八:測試環境關閉防火牆

systemctl stop firewalld.service

九:開機禁用防火牆

systemctl disable firewalld.service

十:查看防火牆狀態

firewall-cmd --state

十一:解壓下載好的包

tar -zxvf fastdfs-6.06.tar.gz
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
tar -zxvf libfastcommon-1.0.43.tar.gz
tar -zxvf nginx-1.17.7.tar.gz

十二:編譯安裝 libfastcommon

1、進入解壓后的目錄

# cd /opt/softwares/libfastcommon-1.0.43

2、編譯安裝

# ./make.sh && ./make.sh install

3、檢查

ls /usr/lib64|grep libfastcommon
ls /usr/lib|grep libfastcommon

出現libfastcommon.so即成功

十三:編譯安裝 fastdfs

1、進入解壓后的目錄

# cd /opt/softwares/fastdfs-6.06

2、編譯安裝

# ./make.sh && ./make.sh install

3、檢查

# ls /usr/bin|grep fdfs

4、啟用配置文件

cd /etc/fdfs/
cp storage.conf.sample storage.conf
cp client.conf.sample client.conf
cp tracker.conf.sample tracker.conf
mkdir -p /fastdfs/tracker

5、修改 tracker.conf 文件

vim /etc/fdfs/tracker.conf
base_path = /fastdfs/tracker

6、啟動 tracker 服務

/etc/init.d/fdfs_trackerd start

7、檢查服務是否啟動

ps -ef|grep fdfs

8、修改 storage.conf 文件

vim /etc/fdfs/storage.conf
base_path = /fastdfs/storage
store_path0 = /fastdfs/storage
tracker_server = 192.168.0.179:22122
http.server_port = 80

9、創建目錄

mkdir -p /fastdfs/storage

10、啟動 storage 服務

/etc/init.d/fdfs_storaged start

11、設置開機啟動

vim /etc/rc.d/rc.local

加入配置

/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start

12、編輯 client.conf 文件

vim /etc/fdfs/client.conf

修改

base_path = /fastdfs/tracker
tracker_server=192.168.0.179:22122

十四:安裝 nginx 和 fastdfs-nginx-module

1、安裝pcre

yum -y install pcre pcre-devel

2、進入解壓目錄

cd /opt/softwares/nginx-1.17.7

3、添加 http_stub_status_module 模塊

./configure --prefix=/usr/local/nginx --with-http_stub_status_module

4、進入 /opt/softwares/fastdfs-nginx-module-1.22/src/

cd /opt/softwares/fastdfs-nginx-module-1.22/src

5、編輯配置文件

vim config

6、將config文件中的/usr/local替換成/usr

:%s+/usr/local+/usr

7、進入 nginx 解壓目錄

cd /opt/softwares/nginx-1.17.7

8、添加fastdfs-nginx-module

./configure --add-module=/opt/softwares/fastdfs-nginx-module-1.22/src/

9、編譯安裝

make && make install

10、復制並修改fastdfs-ngin-module中的配置文件

cp /opt/softwares/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf

修改配置

connect_timeout=10
tracker_server=192.168.0.179:22122
url_have_group_name = true
store_path0=/fastdfs/storage

11、進入fastdfd源碼conf目錄

cd /opt/softwares/fastdfs-6.06/conf

12、將http.conf,mime.types兩個文件拷貝到/etc/fdfs/目錄下

cp http.conf mime.types /etc/fdfs/

13、創建一個軟連接,在/fastdfs/storage文件存儲目錄下創建軟連接,將其鏈接到實際存放數據 的目錄

ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00

14、編輯 nginx 配置

vim /usr/local/nginx/conf/nginx.conf

修改配置

server {
    listen       80;
    server_name  192.168.0.179;
    location ~/group([0-9])/M00 {
            root  /fastdfs/storage/data;
            ngx_fastdfs_module;
    }
}

15、啟動 nginx

/usr/local/nginx/sbin/nginx

測試

1、下載測試圖片到本地

wget -c "https://t.ki4.cn/2019/10/zau26v.jpg" -O springboot.jpg

2、上傳測試圖片

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/softwares/fastdfs-6.06/conf/springboot.jpg

得到返回文件名

group1/M00/00/00/wKgAs17MHPaAa5inAACumtGPxf4201.jpg

與ip拼接:http://192.168.0.179/group1/M00/00/00/wKgAs17MHPaAa5inAACumtGPxf4201.jpg

原文地址:https://developer.aliyun.com/article/745317

=======================================================================================

微信公眾號:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM