FastDFS集群搭建-詳細


FastDFS

1. 簡介

  • 小文件-適用於圖片
  • 靜默IO

搭建流程

目標:
新服務器:

  • Tracker
    10.16.42.160
    10.16.42.161

  • Storage
    10.16.42.162
    10.16.42.163

准備環境

上傳失敗:chmod 777 soft

統一存放目錄:/usr/local/soft

安裝目錄:/mnt/fastdfs

准備工作

這里給出我自己用的安裝包,有點老了,但是實踐過沒問題。其實也是找別人的。再次感謝那些分享的陌生人。
鏈接:https://pan.baidu.com/s/1rROaM_EL4MBSvXGezn_QUw
提取碼:84qy

sudo su - root
cd usr/local;
mkdir soft #統一安裝目錄
# 這里遇到了不能上傳文件的問題,是因為沒有寫權限
chmod 777 soft
cd soft/ 

安裝libfastcommon函數包

git clone https://github.com/happyfish100/libfastcommon.git --depth 1
#根目錄要有權限才能執行
chmod a+x *.sh
./make.sh && ./make.sh install

安裝fastdfs

tar -xzvf fastdfs.tar.gz
cd fastdfs
chmod a+x *.sh
./make.sh && ./make.sh install
# 拷貝這兩東西到生成的配置文件目錄
cp /usr/local/soft/FastDFS/conf/http.conf /etc/fdfs/
cp /usr/local/soft/FastDFS/conf/mime.types /etc/fdfs/

安裝fastdfs-nginx-module

tar -xzvf fastdfs-nginx-module.tar.gz

cd fastdfs-nginx-module/src/  #進入fast/fastdfs-nginx-module/src/目錄下
 
vim /usr/local/soft/fastdfs-nginx-module/src/config  #編輯配置文件config中的路徑,因為默認路徑和實際路徑是不符合的
# 全局替換`/usr/local`為`/usr`
:%s+/usr/local+/usr

#復制生成的mod_fastdfs.conf並修改里面的traker
cp /usr/local/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

此時,/etc/fdfs已經有一堆配置文件了,我們過去看看:

順便重命名一下:

cd etc/fastdfs
mv storage.conf.sample storage.conf
mv client.conf.sample client.conf
mv tracker.conf.sample tracker.conf

安裝nginx

安裝prec

pcre-config --version #檢查

yum -y install wget   #如果wget沒有安裝的,報wget命令未找到,需要先安裝wget,否則可以忽略
 
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz #安裝pcre
 
tar -zxvf pcre-8.35.tar.gz -C /usr/local/soft #解壓到/usr/local
 
cd /usr/local/soft/pcre-8.35 #進入pcre-8.35目錄
 
./configure 
 
make && make install #編譯安裝

pcre-config --version #查看版本

搭建

Nginx

安裝Nginx

#安裝nginx
tar -zxvf nginx-1.14.1.tar.gz
cd /usr/local/soft/nginx-1.14.1/

./configure --add-module=/usr/local/soft/fastdfs-nginx-module/src/
#編譯並安裝
make && make install

修改ngxin.conf配置

cd /usr/local/nginx/conf
#修改ngxin.conf,見下

image-20211114215652078

修改fast-nginx-module生成的mod_fastdfs.conf

vim /etc/fdfs/fastdfs-nginx-module.conf
#修改traker
base_path=/fastdfs/storage
tracker_server=10.224.201.100:22122 # tracker服務器
tracker_server=10.224.201.101:22122 #tracker服務器
group_name=group1                 #當前服務器的group名,默認
store_path0=/fastdfs/storage/m0        # 存儲路徑
#最重要的,默認的是不能用的!!!!
url_have_group_name=true #url中包含group名稱

啟動

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- [root@mvxl43154 conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- ngx_http_fastdfs_set pid=13780
# 有時需要重啟,這是停止的命令
/usr/local/nginx/sbin/nginx -s stop

啟動Tracker

准備

cd /etc/fdfs
vim tracker.conf
# 修改配置
base_path=/mnt/fastdfs/storage
tracker_server=......
# 去新建上面的設置文件夾,它不能自己新建、
mkdir xxx

啟動
這里遇到了坑,fdfs_trackerd /etc/fdfs/tracker.conf start在集群中會報錯
所以建議使用`/etc/init.d/fdfs_trackerd start

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

#發現上面的那個,在當前版本有bug,使用下面這個,stop、start、restar都有
/etc/init.d/fdfs_trackerd start
#有bug就重啟。重啟時要情況數據文件夾,避免沖突
/etc/init.d/fdfs_trackerd restart

這里遇到了兩個tracker節點之間通信的很奇怪的問題。最終像網上說的,把非leader關閉,把leader的data里產生的的配置拷貝到出問題服務器的data中。除了pid文件,這個當然不要。

啟動Storage

准備

vim tracker.conf
#配置參數
base_path=/mnt/fastdfs  #記得去新建文件夾
store_path0=/mnt/fastdfs/storage
tracker_server=.....:22122
http.server_port=:22122
# 這里遇到了不能同步的bug,實際上是配置文件和其他節點不同。這一點很坑。這里節點之間的配置文件最好全都復制來使用,不然隨時出現問題!!!
max_connections=1024
work_threads=8

啟動

#啟動
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
#或
/etc/init.d/fdfs_storaged restart
tail /xxx #看日志,地址是上面設置的base
ps -ef|grep storage

監控Storage狀態

# 監控
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
## 遇到bug重啟吧
#停止
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
#從集群中刪除
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf delete group1 10.16.42.162
#在服務器中,刪除數據文件夾
rm -rf /mnt/fastdfs/storage/data
#重啟節點
/etc/init.d/fdfs_storaged restart
#重新查狀態 
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

配置Client

Client將用於在服務器上直接上傳文件測試,轉發到配置的 tracker中

cd /etc/fdfs
vim client.conf
#配置參數
base_path=/mnt/fastdfs
store_path0=/mnt/fastdfs/storage
tracker_server=.....:22122
http.tracker_server_port=80

測試

# storage中上傳一個文件
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/soft/nginx-1.14.1.tar.gz
# 返回值
- group1/M00/08/48/ChAaY2GODtOAWG70AA95GDoMzU8.tar.gz
# 到瀏覽器中,訪問tracker的ip+返回值,可以訪問到strorage的文件
#這是刪除文件
/usr/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/08/48/ChAaY2GODtOAWG70AA95GDoMzU8.tar.gz

搭建完成

其他一些命令

復制文件

前面說了,最大的心得,就是要使用復制的文件,不然集群之間參數不同時會導致無法運行的

# 服務器之間復制文件,熟練后其實會比sftp方便
##下載
scp apps@10.16.26.99:/apps/fastng.tar.gz E:/
## 上傳
scp E:/fastng.tar.gz apps@10.16.26.99:/usr/local/soft
#關閉防火牆
systemctl stop firewalld
#看看端口是否正常
netstat -ano|grep 80
netstat -unltp|grep fdfs
#批量kill
pkill -9 fdfs

參考文章,非常感謝~~~


免責聲明!

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



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