前言:本文為大家如何在麒麟伺服器上部署FastDFS,請大家多多點贊、收藏、評論、關注哦!
什麼是FastDFSFastDFS 是一個開源的高效能分散式檔案系統(DFS)。 它的主要功能包括:檔案儲存,檔案同步和檔案訪問,以及高容量和負載平衡。
FastDFS 系統有三個角色:跟蹤伺服器(Tracker Server)、儲存伺服器(Storage Server)和客戶端(Client)。
Tracker Server: 跟蹤伺服器,主要做排程工作,起到均衡的作用;負責管理所有的storage server和group,每個 storage 在啟動後會連線 Tracker,告知自己所屬 group 等資訊,並保持週期性心跳。多個 Tracker 之間是對等關係,不存在單點故障。Storage Server: 儲存伺服器,主要提供容量和備份服務;以 group 為單位,每個 group 內可以有多臺 storage server,組內的storage server上的資料互為備份。Client:客戶端,上傳下載資料的伺服器。1 部署 FastDFS系統軟體說明:
CentOS 7.6libfastcommon: FastDFS分離出的一些公用函式包FastDFS: FastDFS本體fastdfs-nginx-module: FastDFS 和 nginx 的關聯模組,解決組內同步延遲問題nginx整個搭建所需環境資源及用途如下表:
(1) 下載libfastcommon
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.zip
(2)下載 FastDFS
wget https://github.com/happyfish100/fastdfs/archive/V6.06.zip
(3)下載 nginx
wget https://nginx.org/download/nginx-1.18.0.tar.gz
(4)下載 nginx 編譯依賴
pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.zip
zlib
wget http://zlib.net/zlib-1.2.11.tar.gz
openssl
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.zip
fastdfs-nginx-module
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.zip
(5) 安裝需要的軟體
<span style="font-weight: normal;">vim /etc/fdfs/tracker.conf需要修改的內容如下port=22122 # tracker伺服器埠(預設22122,一般不修改)base_path=/data/fastdfs # 儲存日誌和資料的根目錄 啟動 fastdfs-tracker 服務並加入自動啟動systemctl start fdfs_trackerdsystemctl enable fdfs_trackerd# centos 可以使用 systemctl enable 命令,但kylin作業系統執行會報錯,需要# 安裝 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 來設定自動啟動(將# fdfs_trackerd 的 2,3,4,5項啟用即可)。 netstat -tulnp # 檢視服務是否啟動,埠是否開啟</span>
(6) 編譯安裝libfastcommon
<span style="font-weight: normal;">vim /etc/fdfs/tracker.conf需要修改的內容如下port=22122 # tracker伺服器埠(預設22122,一般不修改)base_path=/data/fastdfs # 儲存日誌和資料的根目錄 啟動 fastdfs-tracker 服務並加入自動啟動systemctl start fdfs_trackerdsystemctl enable fdfs_trackerd# centos 可以使用 systemctl enable 命令,但kylin作業系統執行會報錯,需要# 安裝 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 來設定自動啟動(將# fdfs_trackerd 的 2,3,4,5項啟用即可)。 netstat -tulnp # 檢視服務是否啟動,埠是否開啟</span>
(7)編譯安裝FastDFS
unzip V6.06.zipcd fastdfs-6.06./make.sh./make.sh install 重新載入系統服務指令碼systemctl daemon-reload 準備配置檔案cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf # tracker節點cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf # storage節點cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf # 客戶端檔案,測試用cp /root/fastdfs/fastdfs-6.06/conf/http.conf /etc/fdfs/ # 供nginx訪問使用cp /root/fastdfs/fastdfs-6.06/conf/mime.types /etc/fdfs/ # 供nginx訪問使用
tracker server配置:
vim /etc/fdfs/storage.conf需要修改的內容如下port=23000 # storage服務埠(預設23000,一般不修改)base_path=/data/fastdfs # 資料和日誌檔案儲存根目錄store_path0=/data/fastdfs # 第一個儲存目錄tracker_server=192.168.0.1:22122 # tracker伺服器IP和埠tracker_server=192.168.0.2:22122 # tracker伺服器IP和埠http.server_port=8888 # http訪問檔案的埠(預設8888,看情況修改,和nginx中保持一致) 啟動 fastdfs-storage 服務並加入自動啟動systemctl start fdfs_storagedsystemctl enable fdfs_storaged# centos 可以使用 systemctl enable 命令,但kylin作業系統執行會報錯,需要# 安裝 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 來設定自動啟動(將# fdfs_storaged 的 2,3,4,5項啟用即可)。 netstat -tulnp # 檢視服務是否啟動,埠是否開啟
storage server 配置
vim /etc/fdfs/storage.conf需要修改的內容如下port=23000 # storage服務埠(預設23000,一般不修改)base_path=/data/fastdfs # 資料和日誌檔案儲存根目錄store_path0=/data/fastdfs # 第一個儲存目錄tracker_server=192.168.0.1:22122 # tracker伺服器IP和埠tracker_server=192.168.0.2:22122 # tracker伺服器IP和埠http.server_port=8888 # http訪問檔案的埠(預設8888,看情況修改,和nginx中保持一致) 啟動 fastdfs-storage 服務並加入自動啟動systemctl start fdfs_storagedsystemctl enable fdfs_storaged# centos 可以使用 systemctl enable 命令,但kylin作業系統執行會報錯,需要# 安裝 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 來設定自動啟動(將# fdfs_storaged 的 2,3,4,5項啟用即可)。 netstat -tulnp # 檢視服務是否啟動,埠是否開啟
檢視叢集狀態
# fdfs_monitor /etc/fdfs/storage.conf list
Client配置
# vim /etc/fdfs/client.conf
#需要修改的內容如下
base_path=/data/fastdfstracker_server=192.168.0.1:22122 # tracker伺服器IP和埠tracker_server=192.168.0.2:22122 # tracker伺服器IP和埠
上傳檔案測試:
# fdfs_upload_file /etc/fdfs/client.conf testfile.zip
測試返回檔案路徑和 ID 則表示成功,如:group1/M00/00/00/xxxxxx.zip
2 部署 nginx 和 fastdfs-nginx-module(1)編譯安裝
參考編譯安裝 nginx 的文章 https://www.yuque.com/liling-rpu83/qtgq0i/wkplwm ,在編譯過程中加入 fastdfs-nginx-module 模組即可:
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-openssl=../openssl-OpenSSL_1_1_1g --with-pcre=../pcre-8.44 --with-zlib=../zlib-1.2.11 --add-module=../fastdfs-nginx-module-1.22/src
# make
# make install
注意要先安裝 libfastcommon,否則編譯時會報錯。
(2)配置執行
配置 fastdfs-nginx-module 配置檔案:
# cp /root/fastdfs/nginx/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs# vim /etc/fdfs/mod_fastdfs.conf需要修改的內容如下:注意此處容易漏掉 tracker server 配置,導致 nginx 啟動後異常,可檢視 nginx 錯誤日誌解決。tracker_server = 192.168.0.1:22122 # tracker伺服器IP和埠tracker_server = 192.168.0.2:22122 # tracker伺服器IP和埠url_have_group_name=truebase_path=/data/fastdfsstore_path0=/data/fastdfs
配置 nginx.conf:
# vim /usr/local/nginx/conf/nginx.conf 增加如下內容:server { listen 8888; ## 該埠為storage.conf中的http.server_port相同 server_name localhost; location ~/group[0-9]/ { root /data/fastdfs; ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
測試下載,用外部瀏覽器訪問剛才已傳過的檔案,引用返回的 ID
http://xx.xx.xx.xx:8888/group1/M00/00/00/rBFSDV7zFCmAW-KFAA3wT-06qHQ.06.zip
彈出下載則目前 nginx 已經 OK。
3 配置檔案訪問的負載均衡和高可用在192.168.0.100和101上安裝nginx、keepalived
yum install -y nginx keepalived
nginx 關鍵配置檔案如下:
upstream fdfs_group01 { server 192.168.0.10:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.0.11:8888 weight=1 max_fails=2 fail_timeout=30s;}server { listen 80; server_name localhost; location /group01{ proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_pass http://fdfs_group01; expires 30d; }}
keepalived 關鍵配置檔案如下:
global_defs { router_id LVS_DEVEL} vrrp_script chk_ngx { script "/etc/keepalived/check_nginx.sh" interval 2 weight -5 fall 3 rise 2} vrrp_instance VI_1 { interface eno16777984 state MASTER priority 100 virtual_router_id 11 advert_int 1 authentication { auth_type PASS auth_pass 1111 } unicast_src_ip 192.168.0.100 unicast_peer { 192.168.0.101 } virtual_ipaddress { 192.168.0.200 } track_script { chk_ngx } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault"}
nginx 監測指令碼如下:
check_nginx.sh
#!/bin/bash counter=$(ps -C nginx --no-heading|wc -l)if [ "${counter}" = "0" ]; then exit 1else exit 0fi