主頁 > 作業系統 > 分布式FastDFS集群部署

分布式FastDFS集群部署

2020-10-07 02:18:13 作業系統

FastDFS

FastDFS的作者余慶在其 GitHub 上是這樣描述的:“FastDFS is an open source high performance distributed file system. It's major functions include: file storing, file syncing and file accessing (file uploading and file downloading), and it can resolve the high capacity and load balancing problem. FastDFS should meet the requirement of the website whose service based on files such as photo sharing site and video sharing site” ,意思說,FastDFS是一個開源的高性能分布式檔案系統,其主要功能包括:檔案存盤、檔案同步和檔案訪問(檔案上傳和檔案下載),它可以解決高容量和負載平衡問題,FastDFS應滿足基于照片共享站點和視頻共享站點等檔案的網站的服務要求,

FastDFS 有兩個角色:跟蹤器(Tracker)和存盤器(Storage),Tracker 負責檔案訪問的調度和負載平衡,Storage 存盤檔案及其功能是檔案管理,包括:檔案存盤、檔案同步、提供檔案訪問介面,它還管理元資料,這些元資料是表示為檔案的鍵值對的屬性,TrackerStorage 節點都可以由一臺或多臺服務器構成,這些服務器均可以隨時增加或下線而不會影響線上服務,當然各個節點集群至少需要一臺服務 Running,注意,其中 Tracker 集群中的所有服務器都是對等的(P2P),可以根據服務器的壓力情況隨時增加或減少,

此外,官網還存盤系統做了詳盡的說明,為了支持大容量,Storage 節點采用了分卷(或分組)的組織方式,存盤系統由一個或多個卷組成,卷與卷之間的檔案是相互獨立的,所有卷的檔案容量累加就是整個存盤系統中的檔案容量,一個卷可以由一臺或多臺 Storage 服務器組成,一個卷下的存盤服務器中的檔案都是相同的,卷中的多臺存盤服務器起到了冗余備份和負載均衡的作用,在卷中增加服務器時,同步已有的檔案由系統自動完成,同步完成后,系統自動將新增服務器切換到線上提供服務,當存盤空間不足或即將耗盡時,可以動態添加卷,只需要增加一臺或多臺服務器,并將它們配置為一個新的卷,這樣就擴大了存盤系統的容量,關于卷或組的概念暫且不要過多深入,后面的安裝部署中會后詳細的說明,

在FastDFS中,檔案的標識由兩部分組成:卷名和檔案名,

環境說明

  • 作業系統:Centos Linux release 7.2.1511
  • 系統磁盤: 274G
  • 掛在磁盤:3.7T * 12
  • CPU:32 (Intel(R) Xeon(R) )
  • Memory:8G

架構設計

圖1 DFS架構圖

作業方式:客戶端向 tracker 發出請求,然后 tracker 從 storage 節點拿到源資料,返還給客戶端,然后客戶端根據源資料再去請求 storage 節點,

高可用FasfDFS結構圖

圖2 高可用DFS架構圖(紅色虛線部分另外討論)

概要精簡

1.核心系統只有兩個角色,tracker server和storage server,

2.所有跟蹤器服務器都是對等的,不存在 Master-Slave 關系(圖中 Tracker-leader 需另行討論,目前只需要明白 tracker 是 P2P),

3.存盤服務器采用分組方式,同組記憶體儲服務器上的檔案完全相同,

4.不同組的 storage server 之間不會相互通信,相同組之間會進行同步,

5.由 storage server 主動向 tracker server 報告狀態資訊,每個 tracker server 都會記錄 storage server 的資訊,

6.如果開啟了 trunk 功能,tracker 服務協調 storage 選舉 trunk-server,

集群部署

準備環境

表1 軟體串列及版本

名稱 說明 鏈接
CentOS 7.x(安裝系統)
libfastcommon FastDFS分離出的一些公用函式包 libfastcommon V1.0.39
FastDFS FastDFS本體 FastDFS V5.11
fastdfs-nginx-module FastDFS和nginx的關聯模塊,解決組內同步延遲問題 fastdfs-nginx-module V1.20
nginx nginx 1.12.2(CentOS 7 下YUM可以安裝的最新版本) nginx 1.12.2

Note: 在google瀏覽器中,點擊上面鏈接下載和復制鏈接下載的檔案名稱不相同,google會根據上面的文本資訊重命名,

表2 服務器IP、服務分配、埠規劃表

名稱 IP地址 應用服務
A機器
10.58.10.136 tracker 22122
10.58.10.136 storage-group1 23000
10.58.10.136 storage-group2 33000
10.58.10.136 libfastcommon -
10.58.10.136 nginx 8888
10.58.10.136 fastdfs-nginx-module -
B機器
10.58.10.137 tracker 22122
10.58.10.137 storage-group1 23000
10.58.10.137 storage-group3 43000
10.58.10.137 libfastcommon -
10.58.10.137 nginx 8888
10.58.10.137 fastdfs-nginx-module -
C機器
10.58.10.138 tracker 22122
10.58.10.138 storage-group2 33000
10.58.10.138 storage-group23 43000
10.58.10.138 libfastcommon -
10.58.10.138 nginx 8888
10.58.10.138 fastdfs-nginx-module -

在安裝之前必須說明:

1.記得給下面用到的存盤目錄(日志、資料、pid檔案等)授權可讀可寫權限;

2.下面所有的組態檔中由于說明,加了注釋,請務必在配置的時候把配置項后面以“#”開頭的注釋刪掉,

初始化環境

# 安裝編譯環境
$ yum groups install Development Tools -y
$ yum install perl -y
$ yum -y install redhat-rpm-config.noarch
$ yum -y install gd-devel
$ yum -y install perl-devel perl-ExtUtils-Embed
$ yum -y install pcre-devel
$ yum -y install openssl openssl-devel
$ yum -y install gcc-c++ autoconf automake
$ yum install -y zlib-devel
$ yum -y install libxml2 libxml2-dev
$ yum -y install libxslt-devel
$ yum -y install GeoIP GeoIP-devel GeoIP-data
$ yum install gperftools -y

安裝libfastcommon

在A、B、C三臺機器上分別執行下面的操作:

$ tar -zxvf libfastcommon-1.0.39.tar.gz
$ cd libfastcommon-1.0.39/
$ ./make.sh
$ ./make.sh install

libfastcommon 安裝在了 /usr/lib64/libfastcommon.so,需要注意新老版本,新版本在安裝之后自動會將 libfastcommon.so 通過軟連接鏈接到 /usr/local/lib 目錄下面,如果是老版本,則需要手動建立:

ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so   ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

如果有 libfdfsclient.so,則也可以把libfdfsclient.so加入到 /usr/local/lib 中:

ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so   ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so 

Note:最好自己通過命令 ls | grep libfastcommon/usr/lib//usr/local/lib 查看確認是否鏈接成功,

安裝tracker

在 A、B、C 三臺機器上分別執行下面操作:

$ mkdir -p /data/fastdfs/tracker
$ tar -zxvf fastdfs-5.11.tar.gz
$ cd fastdfs-5.11/
$ ./make.sh
$ ./make.sh install
$ # 組態檔準備
$ cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf #tracker節點

修改tracker的組態檔:

$ vim /etc/fdfs/tracker.conf
$ #需要修改的內容如下
max_connections=1024 #默認256,最大連接數
port=22122 # tracker 服務器埠(默認 22122,一般不修改)
base_path=/data/fastdfs/tracker # 存盤日志和資料的根目錄

增加 tracker.service 服務,可使用 systemctl 執行服務的啟動、重啟、停止等操作,也可設定開機自動重啟,

$ #編輯啟動檔案
$ vim /usr/lib/systemd/system/fastdfs-tracker.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
ExecStop=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
ExecRestart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

[Install]
WantedBy=multi-user.target

保存 /usr/lib/systemd/system/fastdfs-tracker.service 檔案并退出 vim 編輯器,我們執行下面操作啟動 Fastdfs Tracker 服務:

$ systemctl daemon-reload
$ systemctl enable fastdfs-tracker.service
$ systemctl start fastdfs-tracker.service

tracker 服務啟動結束后,我們通過下面命令查看埠是否正常:

$ netstat -tulnp|grep 22122 #查看服務是否啟動,埠是否打開

安裝sorage

安裝 tracker 的時候已經解壓過了則可以不執行此步驟,

$ tar -zxvf fastdfs-5.11.tar.gz  
$ cd fastdfs-5.11/
$ ./make.sh
$ ./make.sh install
A 機器(group1/group2)

在 fastdfs-5.11 目錄下面復制 storage 的組態檔(復制兩份):

$ sudo mkdir -p /data/fastdfs/storage/group1
$ sudo mkdir -p /data/fastdfs/storage/group2
$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group1.conf #storage節點的group1組
$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group2.conf #storage節點的group1組
$ sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端檔案,測驗用

根據架構設計,我們依次修改上面的三個檔案:

  • 修改 group1 的組態檔:/etc/fdfs/storage-group1.conf
$ sudo vim /etc/fdfs/storage-group1.conf
#需要修改的內容如下
group_name=group1
port=23000 # storage 服務埠(默認 23000)
base_path=/data/fastdfs/storage/group1 # 資料和日志檔案存盤根目錄
store_path_count=6
store_path0=/data01/fastdfs # group1 的第一個存盤目錄
store_path1=/data02/fastdfs # group1 的第二個存盤目錄
store_path2=/data03/fastdfs # group1 的第三個存盤目錄
store_path3=/data04/fastdfs # group1 的第四個存盤目錄
store_path4=/data05/fastdfs # group1 的第五個存盤目錄
store_path5=/data06/fastdfs # group1 的第六個存盤目錄
tracker_server=10.58.10.136:22122 # tracker 服務器IP和埠
tracker_server=10.58.10.137:22122 # tracker 服務器IP和埠
tracker_server=10.58.10.138:22122 # tracker 服務器IP和埠
http.server_port=8888  # http 訪問檔案的埠(默認 8888,看情況修改,和nginx 中保持一致)
  • 修改 group2 的組態檔:/etc/fdfs/storage-group2.conf
$ sudo vim /etc/fdfs/storage-group2.conf
#需要修改的內容如下
group_name=group2
port=33000 # storage 服務埠(默認 23000,修改為 33000)
base_path=/data/fastdfs/storage/group2 # 資料和日志檔案存盤根目錄
store_path_count=6
store_path0=/data07/fastdfs # group2 的第一個存盤目錄
store_path1=/data08/fastdfs # group2 的第二個存盤目錄
store_path2=/data09/fastdfs # group2 的第三個存盤目錄
store_path3=/data10/fastdfs # group2 的第四個存盤目錄
store_path4=/data11/fastdfs # group2 的第五個存盤目錄
store_path5=/data12/fastdfs # group2 的第六個存盤目錄
tracker_server=10.58.10.136:22122 # tracker 服務器 IP 和埠
tracker_server=10.58.10.137:22122 # tracker 服務器 IP 和埠
tracker_server=10.58.10.138:22122 # tracker 服務器 IP 和埠
http.server_port=8888 # http 訪問檔案的埠(默認 8888,看情況修改,和nginx 中保持一致)
  • 修改client的組態檔:/etc/fdfs/client.conf
$ sudo vim /etc/fdfs/client.conf
#需要修改的內容如下
base_path=/data/fastdfs/client
tracker_server=10.58.10.136:22122 # tracker 服務器 IP 和埠
tracker_server=10.58.10.137:22122 # tracker 服務器 IP 和埠
tracker_server=10.58.10.138:22122 # tracker 服務器 IP 和埠
  • 修改好以上三個組態檔之后,我們制作啟動 service:

fastdfs-storage-group1.service

$ vim /usr/lib/systemd/system/fastdfs-storage-group1.service
# 編輯啟動檔案
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf restart

[Install]
WantedBy=multi-user.target

fastdfs-storage-group2.service

$ vim /usr/lib/systemd/system/fastdfs-storage-group2.service
# 編輯啟動檔案
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf restart

[Install]
WantedBy=multi-user.target

  • Storage 的 service 制作好只好,我們啟動 Storage 的兩個服務:
$ systemctl daemon-reload
$ systemctl enable fastdfs-storage-group1.service
$ systemctl start fastdfs-storage-group1.service

啟動程序可能因為某些權限或配置書寫錯誤的問題,會出現啟動失敗的情況,可通過 systemctl status fastdfs-storage-group1.service 查看該服務的狀態,同時結合logs(日志檔案在 /data/fastdfs/storage/group1/logs/目錄下面)排查,可以快速定位問題,如果出現一些例外情況,也可以看看后面的采坑部分,看看有沒有期望的結果,

$ netstat -tulnp #查看服務是否啟動,埠是否打開(23000,33000)
  • 服務起來之后,我們可以查看Fastdfs的集群狀態:
#查看集群狀態
$ fdfs_monitor /etc/fdfs/storage-group1.conf list

控制臺列印出如下資訊,說明成功了:

[2018-11-06 00:00:00] DEBUG - base_path=/data/fastdfs/storage/group1, connect_timeout=30, network_timeout=60, tracker_server_count=2, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
server_count=3, server_index=0
tracker server is 10.58.10.136:22122,10.58.10.137:22122,10.58.10.138:22122
group count: 2
Group 1:
...
  • 通過客戶端測驗上傳檔案
#保存后測驗,回傳 ID 表示成功 如:group1/M00/00/00/xx.txt
$ fdfs_upload_file /etc/fdfs/client.conf test.txt
B 機器(group1/group3)

配置程序與 A 機器類似,需要修改以下幾個點:

  • 創建目錄及復制組態檔,
$ sudo mkdir -p /data/fastdfs/storage/group1
$ sudo mkdir -p /data/fastdfs/storage/group3
$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group1.conf #storage節點的group1組
$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group3.conf #storage節點的group3組
$ sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端檔案,測驗用
  • 修改 group3 的組態檔/etc/fdfs/storage-group3.conf,group1 的配置內容和 A 的保持一致,
$ sudo vim /etc/fdfs/storage-group3.conf
#需要修改的內容如下
group_name=group3
port=43000 # storage服務埠(默認23000,修改為43000)
base_path=/data/fastdfs/storage/group3 # 資料和日志檔案存盤根目錄
store_path_count=6
store_path0=/data07/fastdfs # group3的第一個存盤目錄
store_path1=/data08/fastdfs # group3的第二個存盤目錄
store_path2=/data09/fastdfs # group3的第三個存盤目錄
store_path3=/data10/fastdfs # group3的第四個存盤目錄
store_path4=/data11/fastdfs # group3的第五個存盤目錄
store_path5=/data12/fastdfs # group3的第六個存盤目錄
tracker_server=10.58.10.136:22122 # tracker服務器IP和埠
tracker_server=10.58.10.137:22122 # tracker服務器IP和埠
tracker_server=10.58.10.138:22122 # tracker服務器IP和埠
http.server_port=8888 # http訪問檔案的埠(默認8888,看情況修改,和nginx中保持一致)
  • client 的組態檔和 A 機器一致,此處不做重復,
  • 制作啟動 group3 的 service,fastdfs-storage-group1.service和 A 機器一致,復制即可,
$ vim /usr/lib/systemd/system/fastdfs-storage-group3.service
# 編輯啟動檔案
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group3.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage-group3.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group3.conf restart

[Install]
WantedBy=multi-user.target

  • 執行啟動腳本,直到 fastdfs-storage-group1.servicefastdfs-storage-group3.service 服務起來即可,
C 機器(group2/group3)

配置程序與 A 機器類似,需要修改以下幾個點:

  • 創建目錄及復制組態檔,
$ sudo mkdir -p /data/fastdfs/storage/group2
$ sudo mkdir -p /data/fastdfs/storage/group3
$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group2.conf #storage節點的group1組
$ sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group3.conf #storage節點的group3組
$ sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端檔案,測驗用
  • 修改 group2 的組態檔/etc/fdfs/storage-group2.conf,group3 的配置內容和 B 機器的保持一致,
$ sudo vim /etc/fdfs/storage-group2.conf
#需要修改的內容如下
group_name=group2
port=33000 # storage服務埠(默認23000,修改為33000)
base_path=/data/fastdfs/storage/group2 # 資料和日志檔案存盤根目錄
store_path_count=6
store_path0=/data01/fastdfs # group2的第一個存盤目錄
store_path1=/data02/fastdfs # group2的第二個存盤目錄
store_path2=/data03/fastdfs # group2的第三個存盤目錄
store_path3=/data04/fastdfs # group2的第四個存盤目錄
store_path4=/data05/fastdfs # group2的第五個存盤目錄
store_path5=/data06/fastdfs # group2的第六個存盤目錄
tracker_server=10.58.10.136:22122 # tracker服務器IP和埠
tracker_server=10.58.10.137:22122 # tracker服務器IP和埠
tracker_server=10.58.10.138:22122 # tracker服務器IP和埠
http.server_port=8888 # http訪問檔案的埠(默認8888,看情況修改,和nginx中保持一致)
  • client 的組態檔和 A 機器一致,此處不做重復,
  • 制作啟動 group2 和 group3 的 service,上面已有,直接復制即可,
  • 執行啟動腳本,直到fastdfs-storage-group2.servicefastdfs-storage-group3.service服務起來即可,

安裝nginx和fastdfs的nginx模塊

step1 在 fastdfs 的目錄中,將 http.confmime.types 檔案拷貝到 /etc/fdfs 目錄下面,支持 nginx 訪問 storage 服務,

# 在三臺機器上都需要執行
$ cp ./conf/http.conf /etc/fdfs/ #供 nginx 訪問使用
$ cp ./conf/mime.types /etc/fdfs/ #供 nginx 訪問使用

step2 安裝 fastdfs 的 nginx 模塊:

# 在三臺機器上都需要執行
$ tar -zxvf V1.20.tar.gz
$ cp fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf

step3 然后修改 fastdfs-nginx-module-1.20/src/config 檔案,找到 ngx_module_incsCORE_INCS 兩處,修改如下:

ngx_module_incs=”/usr/include/fastdfs /usr/include/fastcommon/”
CORE_INCS=”$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/”

如果不修改,在編譯 nginx 的時候,會出這種錯誤:/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory

step4 之后我們解壓 nginx,安裝 nginx 服務:

$ tar -zxvf nginx-1.12.2.tar.gz
$ cd nginx-1.12.2
$ ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=${YOUR_PATH}/fastdfs-nginx-module-1.20/src
$ make
$ make install

注意,上面 ${YOUR_PATH} 改為 fastdfs-nginx-module-1.20 的父目錄,保證路徑正確,

  • 修改A機器 /etc/fdfs/mod_fastdfs.conf 組態檔:
connect_timeout=2
network_timeout=30
base_path=/data/fastdfs/ngx_mod
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=10.58.10.136:22122 # tracker服務器IP和埠
tracker_server=10.58.10.137:22122 # tracker服務器IP和埠
tracker_server=10.58.10.138:22122 # tracker服務器IP和埠
group_name=group1/group2  # 全域
url_have_group_name = true
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 2
[group1]
group_name=group1   #group中
storage_server_port=23000
store_path_count=6
store_path0=/data01/fastdfs 
store_path1=/data02/fastdfs 
store_path2=/data03/fastdfs 
store_path3=/data04/fastdfs 
store_path4=/data05/fastdfs
store_path5=/data06/fastdfs 
[group2]
group_name=group2
storage_server_port=33000
store_path_count=6
store_path0=/data07/fastdfs 
store_path1=/data08/fastdfs 
store_path2=/data09/fastdfs 
store_path3=/data10/fastdfs 
store_path4=/data11/fastdfs
store_path5=/data12/fastdfs 
  • 配置 nginx 的組態檔,以便訪問 storage
$ sudo vim /etc/nginx/nginx.conf
user nginx;
worker_prosesses on;
worker_rlimit_nofile 65535;

error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 65535;
    use epoll;
    accept_mutex off;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    gzip                on;

    server_names_bucket_hash_size 128;
    client_header_buffer_size 32k;
    larger_client_header_buffers 4 32k;
    client_max_body_size 300m;

    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header HOST $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connet_timeout 90;
    proxy_send_timeout   90;
    proxy_read_timeout   90;
    proxy_buffer_size 16k;
    proxy_buffers 8 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;


    proxy_cache_path /data/fastdfs/cache/nginx/proxy_cache levels=1:2
    keys_zone=http-cache:200m max_size=1g inactive=30d;
    proxy_temp_path /data/fastdfs/cache/nginx/proxy_cache/temp;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        #include /etc/nginx/default.d/*.conf;

        location ~ ^/ok(\..*)?$ {
            return 200 "OK";
        }

        location /nginx {
            stub_status on;
        }

        location /healthcheck {
            check_status on;
        }

        location ^~ /group1/ {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_cache http-cache;
            proxy_cache_valid 200 304 12h;
            proxy_cache_key $uri$is_args$args;

            add_header 'Access-Control-Allow-Origin' $http_origin;
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header "Access-Control-Allow-Methods" "GET, POST, HEAD, PUT, DELETE, OPTIONS, PATCH";
            add_header "Access-Control-Allow-Headers" "Origin, No-Cache, Authorization, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type";
            if ($request_method = 'OPTIONS') {
                return 200 'OK';
            }

            proxy_pass http://fdfs_group1;
            expire 30d;
        }
        location ^~ /group2/ {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_cache http-cache;
            proxy_cache_valid 200 304 12h;
            proxy_cache_key $uri$is_args$args;

            add_header 'Access-Control-Allow-Origin' $http_origin;
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header "Access-Control-Allow-Methods" "GET, POST, HEAD, PUT, DELETE, OPTIONS, PATCH";
            add_header "Access-Control-Allow-Headers" "Origin, No-Cache, Authorization, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type";
            if ($request_method = 'OPTIONS') {
                return 200 'OK';
            }

            proxy_pass http://fdfs_group2;
            expire 30d;
        }
        location ^~ /group3/ {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_cache http-cache;
            proxy_cache_valid 200 304 12h;
            proxy_cache_key $uri$is_args$args;

            add_header 'Access-Control-Allow-Origin' $http_origin;
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header "Access-Control-Allow-Methods" "GET, POST, HEAD, PUT, DELETE, OPTIONS, PATCH";
            add_header "Access-Control-Allow-Headers" "Origin, No-Cache, Authorization, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type";
            if ($request_method = 'OPTIONS') {
                return 200 'OK';
            }

            proxy_pass http://fdfs_group3;
            expire 30d;
        }

        location ~/purge(/.*) {
            allow 127.0.0.1;
            allow 192.168.1.0/24;
            allow 10.58.1.0/24;
            deny all;
            proxy_cache_purge http-cache $1$is_args$args;
        }
    }

    server {
        listen 8888;
        server_name localhost;
        
        location /ok.htm {
            return 200 "OK";
        }

        location ~/group[0-9]/ {
            ngx_fastdfs_module;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }

    upstream fdfs_group1 {
        server 10.58.10.136:8888 max_fails=0;
        server 10.58.10.137:8888 max_fails=0;

        keepalive 10240;
        check interval=2000 rise=2 fall=3 timeout=1000 type=http default_down=false;
        check_http_send "GET /ok.htm HTTP/1.0\r\nConnection:keep-alive\r\n\r\n";
        check_keepalive_requests 100;
    }

    upstream fdfs_group2 {
        server 10.58.10.136:8888 max_fails=0;
        server 10.58.10.138:8888 max_fails=0;

        keepalive 10240;
        check interval=2000 rise=2 fall=3 timeout=1000 type=http default_down=false;
        check_http_send "GET /ok.htm HTTP/1.0\r\nConnection:keep-alive\r\n\r\n";
        check_keepalive_requests 100;
    }

    upstream fdfs_group3 {
        server 10.58.10.137:8888 max_fails=0;
        server 10.58.10.138:8888 max_fails=0;

        keepalive 10240;
        check interval=2000 rise=2 fall=3 timeout=1000 type=http default_down=false;
        check_http_send "GET /ok.htm HTTP/1.0\r\nConnection:keep-alive\r\n\r\n";
        check_keepalive_requests 100;
    }

}
  • 啟動 nginx 服務:
sudo nginx -c /etc/nginx/nginx.conf

訪問http://localhost/ok.htm看看是否回傳 200 的狀態,并有 OK 內容,如果啟動失敗,可以查看nginx的日志,日志在/var/log/nginx/error.log檔案中,這個也是 nginx 在 Centos 中的默認錯誤日志路徑,如果修改過 error_log,那么在 error_log 指定的檔案中查看錯誤資訊,

  • B 和 C 機器的配置基本一樣,nginx 的組態檔完全一樣,唯一需要修改的是/etc/fdfs/mod_fastdfs.conf,在 group_name 中根據節點中 storage 的配置修改對應的名字即可,但是需要注意的是方括號[groupX]中X一定是順序遞增的,從1開始,

問題總結

遇到問題,第一,我們通過 Console 列印的資訊排查服務啟動失敗的原因;第二,通過日志排查,大多數時候,日志是最有效的排查方式,沒有之一,tracker 或 storage 服務的日志存放在其服務對應組態檔中 base_path 配置項指定路徑的 logs 目錄下面, nginx的日志,如果開啟了自己指定日志路徑,那么就是自己指定的路徑下查找,如果默認,在 Centos 下面大多數在 /var/log/nginx/ 目錄下面,當然,在這種環境中我們排查的不單單是 nginx,還有 fastdfs 的對 nginx 的擴展模塊,這時候,要考慮 fastdfs-nginx-module 的日志的排查,其日志存放路徑為 /etc/fdfs/mod_fastdfs.conf 配置中 base_path 指定的路徑,

集群中多個 group 配置埠

每個 group 都需要獨立一個 storage 服務,因此同一臺主機上 storage group 的埠不能沖突,這里我把 group1 的規劃為 23000,group2 的規劃為 33000,group3 的規劃為43000.

相同名稱的 group 不能在同一臺機器上,因為 tracker 調度時,相同名稱的 group 之間會自動進行同步,需要相同的埠號,故此,兩臺主機上統一名稱的 group 必須保證 storage 的埠一致,

集群中多個group存盤路徑的配置

同一主機不同的 group 存盤路徑不要放在一起,需要分開配置,

不同主機相同的 group 存盤路徑可以不一致,但是數量必須保證相同,大小也應該基本一致,

同一節點多個 storage 的配置

在同一個機器上,我們部署了兩個 group,三臺機器組成的集群,每個 group 在另外一個節點中保存一份副本,使用命令systemctl start fastdfs-storage-groupx.service啟動的時候,另外一個 group 無法啟動(groupx 為 group1、group2、group3),一直顯示為 Loaded: loaded (/usr/lib/systemd/system/fastdfs-storage-group1.service; enabled; vender preset: disabled),直到最好失敗 Active: inactive 變為 Active: exited (下圖為tracker的,storage 的問題類似),

![](https://img2018.cnblogs.com/blog/1844824/201910/1844824-20191024163722170-1129664866.png)
圖3 storage_group無法啟動

當時的解決方法:每個 storage 啟動時都需要 systemctl daemon-reload 一下,然后啟動即可,
假如要啟動A機器中的 fastdfs-storage-group1.servicefastdfs-storage-group2.service,則需要執行如下操作:

  • 先啟動 fastdfs-storage-group1.service
sudo systemctl daemon-reload
sudo systemctl enable fastdfs-storage-group1.service
sudo systemctl start fastdfs-storage-group1.service
  • 觀察 fastdfs-storage-group1.service 的狀態:
systemctl status fastdfs-storage-group1.service
  • 當看到 active 為 running 的時候,說明啟動成功了,然后啟動 fastdfs-storage-group2.service;否則沒啟動成功,查看日志尋找問題即可:
sudo systemctl daemon-reload
sudo systemctl enable fastdfs-storage-group2.service
sudo systemctl start fastdfs-storage-group3.service

  • 觀察 fastdfs-storage-group2.service 的狀態,直到起來為止,

可能會出現 Unkown lvalue 'ExecRestart' in section 'Service' 的警告日志,目前未找到解決方法,當時執行了 yum install systemd-* 的命令,也沒能解決這個問題(有知道解決方案的朋友麻煩告知一下),

fastdfs的nginx模塊配置

在所有 storage 機器上,修改 /etc/fdfs/mod_fastdfs.conf 時,根據不同的 storage 中的 group 修改 group_name 中的值,但是需要注意兩個配置專案,下面就 group2 和 group3 為例說明一下:

  • 全域的 group_name

全域配置中的 group_name 必須用”/“分割,值為區域中的 group_name 的值,比如:

group_name=group2/group3,
  • group 中的 group_name
    group 標識一定是從 group1 開始,依次為 group2,這里的標識就是方括號中的字串,類似 mysql 組態檔中的 [Mysql],
group_name=group2/group3  # 全域
...
group_count = 2
[group1]  # 一定要注意這個地方
group_name=grou2   #group中
storage_server_port=33000
store_path_count=6
......
[group2]  # 還有這個地方,都是有序的
group_name=group3
storage_server_port=43000
store_path_count=6
......

最后,個人理解,錯誤在所難免,歡迎各位朋友批評指正,如有不對的地方,煩請指出,后續我就 FastDFS 的 Tracker 和 Storage 之間的關系做一個詳細的解釋,


該文首發《虛懷若谷》個人博客,轉載前請務必署名,轉載請標明出處,

古之善為道者,微妙玄通,深不可識,夫唯不可識,故強為之容:

豫兮若冬涉川,猶兮若畏四鄰,儼兮其若客,渙兮若冰之釋,敦兮其若樸,曠兮其若谷,混兮其若濁,

孰能濁以靜之徐清?孰能安以動之徐生?

保此道不欲盈,夫唯不盈,故能敝而新成,

請關注我的微信公眾號:下雨就像彈鋼琴,Thanks?(?ω?)?
微信二維碼

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/160490.html

標籤:Linux

上一篇:Windows系統下安裝VirtualBox及安裝Ubuntu16.04

下一篇:Linux的一些常用命令(一)

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more