FastDFS6.0.6搭建集羣

前面一篇文章在搭建FastDFS集羣的時候因爲採用的是5.11版本,在ECS上部署一直無法實現文件的同步,還會一直在選舉:INFO - file: tracker_relationship.c, line: 389, selecting leader…。
看到官網更新了6.0.6版本的雙ip特性可以解決這個外網和跨雲的問題,所以馬上更換到了最新版本,相匹配的軟件也需要更新不同版本。
創建目錄的步驟就不記錄了,和前面一篇FastDFS一樣的路徑,所以沒有重新建路徑。裏面ip爲隨意修改的,注意更改。因爲外網環境不安全,所以需要做一些安全方面的工作,比如防盜鏈,以及端口限制訪問,不要全部暴露在外網環境中,可通過程序來中轉訪問。

Fastdfs6.0.6最新版搭建:
https://github.com/happyfish100/fastdfs-nginx-module/releases
https://github.com/happyfish100/libfastcommon/releases
https://github.com/happyfish100/fastdfs/releases
http://nginx.org/en/download.html
解壓文件

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

cd libfastcommon-1.0.43
# 編譯安裝
./make.sh && ./make.sh install 

檢查

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

出現libfastcommon.so即成功

編譯安裝 fastdfs
進入fastdfs-6.0.6目錄下

cd  fastdfs-6.06

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

檢查

ls /usr/bin|grep fdfs
cd /etc/fdfs/

cp storage.conf.sample storage.conf

cp client.conf.sample client.conf

cp tracker.conf.sample tracker.conf

配置 tracker

vim /etc/fdfs/tracker.conf
# 需要修改的內容如下
 
# 注意服務器是 NAT 方式所以此處綁定的是內網 IP 可以在阿里雲後臺看到
# 可以使用命令查看 ifconfig -a 沒有公網的IP
bind_addr = 172.xxx.xxx.xxx
 
# tracker 服務器端口(默認22122,一般不修改)
port=22122
 
# 存儲日誌和數據的根目錄 
base_path=/home/dfs 
 
# use_storage_id 設置爲 true 後需要在 storage_ids.conf 設置雙 IP 
# 原註釋如下:
# if use storage server ID instead of IP address
# if you want to use dual IPs for storage server, you MUST set
# this parameter to true, and configure the dual IPs in the file
# configured by following item "storage_ids_filename", such as storage_ids.conf
# default value is false
# since V4.00
use_storage_id = true

配置 storage_ids.conf

# <id>  <group_name>  <ip_or_hostname[:port]>
#
# id is a natural number (1, 2, 3 etc.),
# 6 bits of the id length is enough, such as 100001
#
# storage ip or hostname can be dual IPs seperated by comma,
# one is an inner (intranet) IP and another is an outer (extranet) IP,
# or two different types of inner (intranet) IPs
# for example: 192.168.2.100,122.244.141.46
# another eg.: 192.168.1.10,172.17.4.21
#
# the port is optional. if you run more than one storaged instances
# in a server, you must specified the port to distinguish different instances.
# 一個內網 IP 一個公網 IP
100001   group1  172.XXX.XXX.XXX,123.XXX.XXX.XXX
100002   group1  172.XXX.XXX.XXX,123.XXX.XXX.XXX

配置 storage

vim /etc/fdfs/storage.conf
# 需要修改的內容如下
 
# storage服務端口(默認23000,一般不修改)
port=23000
 
# 數據和日誌文件存儲根目錄  
base_path=/home/dfs
 
# 第一個存儲目錄  
store_path0=/home/dfs  
 
# 重點是這個,一定注意格式     內網,外網:端口號
# 重點是這個,一定注意格式     內網,外網:端口號
# 重點是這個,一定注意格式     內網,外網:端口號
# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122
tracker_server = 192.168.2.100,122.244.111.111:22122
tracker_server = 192.158.2.100,123.244.222.222:22122
 
# http訪問文件的端口(默認8888,看情況修改,和nginx中保持一致)
http.server_port=8888

fastdfs-nginx-module模塊解壓出來供nginx編譯即可:需要修改文件

cd fastdfs-nginx-module-1.20/src/

編輯fastdfs-nginx-module-1.22/src/目錄下的config文件(沒前綴,沒後綴,就叫config),主要修改以下兩處地方,否則會有報錯,而且報錯是不可預料的,不要問爲什麼,反正就是幹。

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

拷貝fastdfs-nginx-module模塊的配置文件mod_fastdfs.conf到/etc/fdfs目錄中並編輯

cp /usr/local/bak/nginx/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
cd /etc/fdfs/

修改內容如下,,此處的store_path0應該與storage.conf中的store_path0一致,這樣nginx才能夠找到資源的正確路徑:

base_path=/data/fastdfs/nginx
store_path0=/data/fastdfs/storage
tracker_server=47.103.111.111:22122 	# 公網 IP
storage_server_port=23000(默認配置爲23000)
url_have_group_name = true
group_name=group1(默認配置爲group1)

進入到nginx解壓後的文件中,

cd nginx-1.18.0

./configure --prefix=/usr/local/nginx18   --conf-path=/usr/local/nginx18/conf/nginx.conf --sbin-path=/usr/local/nginx18/sbin --add-module=/usr/local/bak/nginx/fastdfs-nginx-module-1.22/src
進入到nginx解壓後的文件中:
make && make install

配置 nginx

vim /etc/fdfs/mod_fastdfs.conf

#需要修改的內容如下

tracker_server=123.XXX.XXX.XXX:22122  # 公網 IP
url_have_group_name=true
store_path0=/home/dfs

#配置nginx.config

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

#添加如下配置

server {
    listen       8888;    #該端口爲storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}

進入fastdfd源碼conf目錄

cd /root/download/fastdfs-6.06/conf/

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

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

再啓動nginx
使用client上傳文件,在nginx裏可以訪問到,即成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章