溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

高可用高性能分布式文件系統(tǒng)FastDFS進(jìn)階keepalived+nginx對多tracker進(jìn)行高

發(fā)布時間:2020-07-25 09:22:00 來源:網(wǎng)絡(luò) 閱讀:1701 作者:歡醉 欄目:大數(shù)據(jù)

  在上一篇 分布式文件系統(tǒng)FastDFS如何做到高可用 中已經(jīng)介紹了FastDFS的原理和怎么搭建一個簡單的高可用的分布式文件系統(tǒng)及怎么訪問。

  高可用是實現(xiàn)了,但由于我們只設(shè)置了一個group,如果現(xiàn)在有5臺服務(wù)器那將會出現(xiàn)5臺只有一個group,每臺服務(wù)器內(nèi)的文件內(nèi)容都相同(互備份)如下圖,會造成資源浪費。

高可用高性能分布式文件系統(tǒng)FastDFS進(jìn)階keepalived+nginx對多tracker進(jìn)行高

 因此下面就5臺服務(wù)器進(jìn)行優(yōu)化改造,進(jìn)一步添加keepalived+nginx多tracker 架構(gòu),做到真正的高可用和高性能。

 

 FastDFS集群服務(wù)器分布

高可用高性能分布式文件系統(tǒng)FastDFS進(jìn)階keepalived+nginx對多tracker進(jìn)行高

 

其中keepalived+nginx用作30和31 tracker服務(wù)器作熱備。用虛擬VIP 27作統(tǒng)一入口。

我們將按上面的架構(gòu)分服務(wù)器:

虛擬VIP用192.168.80.27

keepalived+nginx 熱備、負(fù)載均衡 : 28、29 

tracker:

30和31服務(wù)器

storage:

group1:32、33

group2:34、35

雖然每個服務(wù)器上都有Nginx,但這里還是先強調(diào)一下這里Nginx的用途:

  1. 首先所有的Nginx都是用于上傳后的文件訪問用的,跟上傳無關(guān)。

  2. 28、29上面的就是常見的端口負(fù)載,這里是對兩個tracker訪問文件端口8000(自己設(shè)置)負(fù)載。

  3. tracker 上安裝的 nginx 主要為了提供 http 訪問的反向代理、負(fù)載均衡以及緩存服務(wù)。

  4. 每一臺storage服務(wù)器主機上部署Nginx及FastDFS擴(kuò)展模塊,由Nginx模塊對storage存儲的文件提供http下載服務(wù), 僅當(dāng)當(dāng)前storage節(jié)點找不到文件時會向源storage主機發(fā)起redirect或proxy動作。 

注:圖中的tracker可能為多個tracker組成的集群;且當(dāng)前FastDFS的Nginx擴(kuò)展模塊支持單機多個group的情況

 

tracker跟蹤節(jié)點30、31

安裝配置步驟前文一致,配置tracker.conf 和client.conf,主要注意防火墻 開啟端口22122 

記得手動創(chuàng)建兩個文件夾:

/data/fastdfs/tracker

/data/fastdfs/client

兩個節(jié)點內(nèi)容一樣。

 

storage存儲節(jié)點32到35

記得手動創(chuàng)建兩個文件夾:/data/fastdfs/storage

安裝步驟與上文一致,配置:

/etc/fdfs/storage.conf

group_name=group1 # 組名(第一組為group1,第二組為group2,依次類推...)
base_path=/data/fastdfs/storage # 數(shù)據(jù)和日志文件存儲根目錄
store_path0=/data/fastdfs/storage # 第一個存儲目錄,第二個存儲目錄起名為:store_path2=xxx,其它存儲目錄名依次類推...

tracker_server=192.168.80.30:22122# tracker服務(wù)器IP和端口
tracker_server=192.168.80.31:22122# tracker服務(wù)器IP和端口

 注意:

32和33  group_name=group1

34和35  group_name=group2

其他配置一樣默認(rèn),注意防火墻 開啟端口23000。

開啟兩個tracker,并加入開機啟動:

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

chkconfig fdfs_trakcerd on

開啟4個storage,并加入開機啟動:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
chkconfig fdfs_storaged on

查看集群狀態(tài),會顯示整體內(nèi)容:

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

高可用高性能分布式文件系統(tǒng)FastDFS進(jìn)階keepalived+nginx對多tracker進(jìn)行高

測試服務(wù)

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg

以上就是FastDFS的安裝與配置。下面就與Nginx模塊結(jié)合作介紹。

將nginx和fastdfs-nginx-module上傳到 storage存儲節(jié)點32到35

fastdfs-nginx-module的作用已經(jīng)在上篇介紹過,在此主要是配置。

上傳fastdfs-nginx-module.tar.gz到/opt文件夾下


解壓插件壓縮包

unzip fastdfs-nginx-module.zip

nginx編譯安裝

cd nginx

對nginx重新config

./configure \--prefix=/opt/nginx \--pid-path=/opt/nginx/nginx.pid \--lock-path=/opt/nginx.lock \--error-log-path=/opt/nginx/log/error.log \--http-log-path=/opt/nginx/log/access.log \--with-http_gzip_static_module \--http-client-body-temp-path=/opt/nginx/client \--http-proxy-temp-path=/opt/nginx/proxy \--http-fastcgi-temp-path=/opt/nginx/fastcgi \--http-uwsgi-temp-path=/opt/nginx/uwsgi \--http-scgi-temp-path=/opt/nginx/scgi \--add-module=/opt/fastdfs-nginx-module/src

 

再進(jìn)行 make && make install

 

將mod_fastdfs.conf 拷貝到fdfs下進(jìn)行配置

cd fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/ #將mod_fastdfs.conf 拷貝到fdfs下進(jìn)行配置

vim /etc/fdfs/mod_fastdfs.conf

base_path=/data/fastdfs/storage
tracker_server=.:tracker_server=.:storage_server_port=url_have_group_name=store_path0=/data/fastdfs/storage
group_count=[group1]
group_name=group1
storage_server_port=store_path_count=store_path0=/data/fastdfs/storage
[group2]
group_name=group2
storage_server_port=store_path_count=store_path0=/data/fastdfs/storage

 注意:

32和33  group_name=group1

34和35  group_name=group2

配置nginx

vim /opt/nginx/conf/nginx.conf

在nginx的配置文件中添加一個Server:
server {        
        listen       8888;
        server_name  localhost;

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

 

 8888的請求且有g(shù)roup的都轉(zhuǎn)給 ngx_fastdfs_module 插件處理,防火墻什么的就不說了。

啟動Nginx,并加和自啟動

shell> /opt/nginx/sbin/nginx

瀏覽器訪問測試時上傳的文件,應(yīng)該都能正常訪問。
http://192.168.80.32:8888/group1/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
http://192.168.80.34:8888/group2/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg

跟蹤節(jié)點安裝Nginx和ngx_cache_purge模塊

說明:每個節(jié)點執(zhí)行相同的操作
tracker節(jié)點:30,31
在 tracker 上安裝的 nginx 主要為了提供 http 訪問的反向代理、負(fù)載均衡以及緩存服務(wù)。

同樣都上傳nginx和ngx_cache_purge包

解壓文件到/opt文件夾下

tar -zxvf ngx_cache_purge-2.3.tar.gz

然后對nginx進(jìn)行編譯安裝

cd nginx 
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/opt/ngx_cache_purge-2.3make && make install

 

配置Nginx,設(shè)置tracker負(fù)載均衡以及緩存

vi /opt/nginx/conf/nginx.conf

添加以下內(nèi)容

    #設(shè)置緩存
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 300m;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k; #設(shè)置緩存存儲路徑、存儲方式、分配內(nèi)存大小、磁盤最大空間、緩存期限 
    proxy_cache_path /data/fastdfs/cache/nginx/proxy_cache keys_zone=http-cache:100m;#設(shè)置 group1 的服務(wù)器
upstream fdfs_group1 {
server 192.168.80.32:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.80.33:8888 weight=1 max_fails=2 fail_timeout=30s;
}
#設(shè)置 group2 的服務(wù)器
upstream fdfs_group2 {
server 192.168.80.34:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.80.35:8888 weight=1 max_fails=2 fail_timeout=30s;
}

    server {        listen       8000;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
 
        #設(shè)置 group 的負(fù)載均衡參數(shù)
        location /group1/M00 {
            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;            
            proxy_pass http://fdfs_group1;            
            expires 30d;
        }
 
        location /group2/M00 {
            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;
            proxy_pass http://fdfs_group2;            
            expires 30d;
        }
 
        #設(shè)置清除緩存的訪問權(quán)限
        location ~/purge(/.*) {
            allow 127.0.0.1;
            allow 192.168.80.0/24;
            deny all;
            proxy_cache_purge http-cache $1$is_args$args;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root html; 
        }
    }

 

上面配置的是當(dāng)請求8000端口時根據(jù)group1還是group2進(jìn)行選擇到對應(yīng)的服務(wù)器響應(yīng)。

要注意的已標(biāo)色。還要提前創(chuàng)建緩存目錄:/data/fastdfs/cache/nginx/proxy_cache

啟動Nginx

/opt/nginx/sbin/nginx
設(shè)置開機啟動:
vi /etc/rc.local## 加入以下配置
/opt/nginx/sbin/nginx
chmod +x /etc/rc.local #centos7

 

文件訪問測試

前面直接通過訪問Storage節(jié)點中的Nginx訪問文件:
http://192.168.80.32:8888/group1/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
http://192.168.80.34:8888/group2/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
現(xiàn)在可以通過Tracker中的Nginx來進(jìn)行訪問:
(1)、通過 Tracker1 中的 Nginx 來訪問
http://192.168.80.30:8000/group1/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
http://192.168.80.30:8000/group2/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
(2)、通過 Tracker2 中的 Nginx 來訪問
http://192.168.80.31:8000/group1/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
http://192.168.80.31:8000/group2/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg

高可用高性能分布式文件系統(tǒng)FastDFS進(jìn)階keepalived+nginx對多tracker進(jìn)行高

  每一個Tracker中的Nginx都單獨對后端的Storage組做了負(fù)載均衡,但整套FastDFS集群,如果想對外提供統(tǒng)一的文件訪問地址,還需要對兩個Tracker中的Nginx進(jìn)行HA集群

配置Tracker服務(wù)器高可用、反向代理與負(fù)載均衡

其實上面可以通過30或31的8000端口進(jìn)行文件訪問了,下面統(tǒng)一端口,對30和31再進(jìn)行一次負(fù)載均衡。

使用Keepalived + Nginx組成的高可用負(fù)載均衡集群,做兩個Tracker節(jié)點中Nginx的負(fù)載均衡。

這里Nginx也可以用Haproxy代替。關(guān)于Keepalived和 Haproxy的安裝和介紹,在 備胎的養(yǎng)成記KeepAlived實現(xiàn)熱備負(fù)載 和 入坑系列之HAProxy負(fù)載均衡 中作過詳細(xì)描述。

這里使用Nginx,將Keepalived 和 Nginx 安裝到 28和29上,VIP為27。

vi /opt/nginx/conf/nginx.conf

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
## FastDFS Tracker Proxy
upstream fastdfs_tracker {
server 192.168.80.30:8000 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.80.31:8000 weight=1 max_fails=2 fail_timeout=30s;}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500502503504/50x.html;
location = /50x.html {
root html;
}
## FastDFS Proxy
location /dfs {
root html;
index index.html index.htm;
proxy_pass  
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
}
} 
}

 

啟動Nginx

/opt/nginx/sbin/nginx
設(shè)置開機啟動:
vi /etc/rc.local## 加入以下配置
/opt/nginx/sbin/nginx
chmod +x /etc/rc.local #centos7

通過VIP訪問文件

http://192.168.80.27:8000/dfs/group1/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg
http://192.168.80.27:8000/dfs/group2/M00/00/00/CgNXGVpddOKANpzbAABdrZgsqUU369_big.jpg

   以上就是整個配置過程,看起來是非常的繁雜,所以一定要先弄清整個的部署架構(gòu),然后每個插件是用來做什么的都要清楚,后面如果要擴(kuò)展的話就有個清晰的思路。

  環(huán)境搭建只是開始,真正的使用、優(yōu)化才是重點,所以耐心的看吧。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI