自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

面試官:如何實(shí)現(xiàn)文件的大規(guī)模分布式存儲(chǔ)?

存儲(chǔ) 存儲(chǔ)軟件 分布式
在生產(chǎn)環(huán)境中,往往需要對(duì)FastDFS實(shí)現(xiàn)高可用,進(jìn)而實(shí)現(xiàn)文件的大規(guī)模分布式存儲(chǔ)。那么,如何實(shí)現(xiàn)FastDFS的高可用呢?今天,我們就基于CentOS 8服務(wù)器來搭建FastDFS高可用集群環(huán)境。

 [[344018]]

作者個(gè)人研發(fā)的在高并發(fā)場(chǎng)景下,提供的簡(jiǎn)單、穩(wěn)定、可擴(kuò)展的延遲消息隊(duì)列框架,具有精準(zhǔn)的定時(shí)任務(wù)和延遲隊(duì)列處理功能。自開源半年多以來,已成功為十幾家中小型企業(yè)提供了精準(zhǔn)定時(shí)調(diào)度方案,經(jīng)受住了生產(chǎn)環(huán)境的考驗(yàn)。為使更多童鞋受益,現(xiàn)給出開源框架地址:

https://github.com/sunshinelyz/mykit-delay

寫在前面

在生產(chǎn)環(huán)境中,往往需要對(duì)FastDFS實(shí)現(xiàn)高可用,進(jìn)而實(shí)現(xiàn)文件的大規(guī)模分布式存儲(chǔ)。那么,如何實(shí)現(xiàn)FastDFS的高可用呢?今天,我們就基于CentOS 8服務(wù)器來搭建FastDFS高可用集群環(huán)境。

服務(wù)器版本

我們?cè)诜?wù)器的命令行輸入如下命令來查看服務(wù)器的內(nèi)核版本。

  1. [root@localhost lib]# cat /etc/redhat-release  
  2. CentOS Linux release 8.1.1911 (Core)  

可以看到,集群中每臺(tái)服務(wù)器的內(nèi)核版本為:release 8.1.1911 (Core)。

服務(wù)器規(guī)劃

這里,我們總共規(guī)劃了6臺(tái)服務(wù)器,分別為:2臺(tái)tracker服務(wù)器,4臺(tái)storage服務(wù)器,其中2臺(tái)storage服務(wù)器為group1,兩臺(tái)storage服務(wù)器為group2。具體如下所示。

  • tracker服務(wù)器

tranker1:192.168.175.101

tracker2:192.168.175.102

  • storage服務(wù)器

storage1:192.168.175.103 group1

storage2:192.168.175.104 group1

storage3:192.168.175.105 group2

storage4:192.168.175.106 group2

環(huán)境準(zhǔn)備

下載FastDFS

在每臺(tái)服務(wù)器上執(zhí)行如下命令下載FastDFS。

  1. [root@localhost source]# wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz 
  2. [root@localhost source]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz 
  3. [root@localhost source]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz 

安裝環(huán)境依賴

在每臺(tái)服務(wù)器上執(zhí)行如下命令安裝FastDFS所依賴的環(huán)境。

  1. [root@localhost dest]# yum install gcc gcc-c++ 
  2. [root@localhost dest]# yum install libtool zlib zlib-devel openssl openssl-devel 
  3. [root@localhost dest]# yum -y install pcre pcre-devel libevent libevent-devel perl unzip net-tools wget 

安裝FastDFS

安裝libfastcommon

在每臺(tái)服務(wù)器上依次執(zhí)行如下命令。

(1)解壓libfastcommon的壓縮包

  1. [root@localhost source]# tar -zxvf V1.0.43.tar.gz 

(2)編譯并安裝編譯并安裝

  1. [root@localhost source]# cd libfastcommon-1.0.43/ 
  2. [root@localhost libfastcommon-1.0.43]# ./make.sh && ./make.sh install 

(3)檢查執(zhí)行的結(jié)果,看安裝是否成功

  1. [root@localhost libfastcommon-1.0.43]# ls /usr/lib64|grep libfastcommon 
  2. libfastcommon.so 
  3.  
  4. [root@localhost libfastcommon-1.0.43]# ls /usr/lib|grep libfastcommon 
  5. libfastcommon.so 

安裝fastdfs

在每臺(tái)服務(wù)器上依次執(zhí)行如下命令。

(1)解壓fastdfs

  1. [root@localhost source]# tar -zxvf V6.06.tar.gz 

(2)安裝fastdfs

  1. [root@localhost source]# cd fastdfs-6.06/ 
  2. [root@localhost fastdfs-6.06]# ./make.sh && ./make.sh install 

(3)檢查fastdfs是否安裝成功

  1. [root@localhost fastdfs-6.06]# ls /usr/bin|grep fdfs 
  2. fdfs_appender_test 
  3. fdfs_appender_test1 
  4. fdfs_append_file 
  5. fdfs_crc32 
  6. fdfs_delete_file 
  7. fdfs_download_file 
  8. fdfs_file_info 
  9. fdfs_monitor 
  10. fdfs_regenerate_filename 
  11. fdfs_storaged 
  12. fdfs_test 
  13. fdfs_test1 
  14. fdfs_trackerd 
  15. fdfs_upload_appender 
  16. fdfs_upload_file 

安裝部署tracker服務(wù)

復(fù)制tracker的配置文件

在兩臺(tái)tracker服務(wù)器上,依次執(zhí)行如下命令。

  1. [root@localhost fastdfs-6.06]# cd /etc/fdfs/ 
  2. [root@localhost fdfs]# cp client.conf.sample client.conf 
  3. [root@localhost fdfs]# cp tracker.conf.sample tracker.conf 

注意:無須生成storage.conf文件,這兩臺(tái)tracker不做為storage。

安裝Nginx

在兩臺(tái)tracker服務(wù)器上,依次執(zhí)行如下命令。

注意:tracker上不需要安裝fastdfs-nginx-module

(1)解壓Nginx

  1. [root@localhost source]# tar -zxvf nginx-1.17.8.tar.gz 

(2)nginx配置,http_stub_status_module 模塊

  1. [root@localhost fdfs]# cd /usr/local/source/nginx-1.17.8/ 
  2. [root@localhost nginx-1.17.8]# ./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module  

(3)編譯安裝Nginx

  1. [root@localhost nginx-1.17.8]# make && make install 

(4)檢查安裝是否成功

  1. [root@localhost nginx-1.17.8]# ls /usr/local/soft/ | grep nginx 
  2. nginx 

(5)查看指定的編譯參數(shù)是否起作用

  1. [root@localhost fdfs]# /usr/local/soft/nginx/sbin/nginx -V 
  2. nginx version: nginx/1.17.8 
  3. built by gcc 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)  
  4. configure arguments: --prefix=/usr/local/soft/nginx --with-http_stub_status_module  

配置并啟動(dòng)FastDFS

在兩臺(tái)tracker上,配置并啟動(dòng)FastDFS。

(1)創(chuàng)建tracker服務(wù)所需的目錄

  1. [root@localhost fdfs]# mkdir /data/fastdfs 
  2. [root@localhost fdfs]# mkdir /data/fastdfs/tracker 
  3. [root@localhost fdfs]# chmod 777 /data/fastdfs/tracker 

(2)配置tracker服務(wù),修改 tracker.conf 文件

  1. [root@localhost fdfs]# vi /etc/fdfs/tracker.conf 

只修改base_path一項(xiàng)的值為我們?cè)谏厦嫠鶆?chuàng)建的目錄即可

  1. base_path = /data/fastdfs/tracker 

(3)啟動(dòng) tracker 服務(wù)

  1. [root@localhost fdfs]# /etc/init.d/fdfs_trackerd start 

(4)檢查tracker服務(wù)啟動(dòng)是否成功

  1. [root@localhost fdfs]# ps auxfww | grep fdfs 
  2. root      15067  0.0  0.0  12320   964 pts/0    S+   15:14   0:00  |   |           \_ grep --color=auto fdfs 
  3. root      15026  0.0  0.1  90160  5940 ?        Sl   15:13   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 

說明:能看到 fdfs_trackerd,表示tracker服務(wù)啟動(dòng)成功。

(5)檢查tracker服務(wù)是否已綁定端口 22122

  1. [root@localhost dest]# netstat -anp | grep 22122 
  2. tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      15026/fdfs_trackerd  

說明:22122端口是在/etc/fdfs/tracker.conf中定義的,如下所示:

  1. # the tracker server port 
  2. port = 22122 

配置client.conf

兩臺(tái)tracker上,配置client.conf,配置fastdfs的客戶端使用的配置文件。

(1)配置client.conf

  1. [root@localhost fdfs]# vi /etc/fdfs/client.conf 

以下兩項(xiàng)配置用到的tracker目錄和服務(wù)器地址端口

  1. base_path = /data/fastdfs/tracker 
  2. tracker_server = 192.168.175.101:22122 
  3. tracker_server = 192.168.175.102:22122 

說明:兩臺(tái)tracker上的client.conf配置相同

(2)從客戶端的配置可以看到:客戶端只需要了解tracker_server的信息。tracker server作用也正是負(fù)載均衡和調(diào)度

(3)Storage server作用是文件存儲(chǔ),客戶端上傳的文件最終存儲(chǔ)在 Storage 服務(wù)上

測(cè)試文件

用client.conf上傳文件測(cè)試。

(1)從tacker上傳一個(gè)文件

  1. [root@0268c2dc2bf6 ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/a.txt             

注意返回的是group1,我們可以group1下面的兩臺(tái)機(jī)器均找到此txt文件:

  • storage1上
  1. [root@d5d19e99e782 docker_tmp]# ls /data/fastdfs/storage/data/00/00 
  2. rBEABF5aTEeAXHF4AAAABHf4XZU792.txt 
  • storage2上
  1. [root@f201111d0698 docker_tmp]# ls /data/fastdfs/storage/data/00/00 
  2. rBEABF5aTEeAXHF4AAAABHf4XZU792.txt 

(2)指定group上傳文件

如果想指定上傳到某個(gè)group怎么辦?例如:指定上傳到group2

  1. [root@0268c2dc2bf6 ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/a.txt 192.168.175.105:23000 
  2. group2/M00/00/00/rBEABl5aUAqAXLCZAAAABHf4XZU043.txt 

說明:指定group2中任一臺(tái)的ip和端口即可。

(3)查看效果

  • storage3上
  1. [root@494ac47d63f8 fdfs]# ls /data/fastdfs/storage/data/00/00 
  2. rBEABl5aUAqAXLCZAAAABHf4XZU043.txt 
  • storage4上
  1. [root@59fa1efff362 fdfs]# ls /data/fastdfs/storage/data/00/00 
  2. rBEABl5aUAqAXLCZAAAABHf4XZU043.txt 

安裝部署storage服務(wù)

生成默認(rèn)配置文件

四臺(tái)storage上:生成啟動(dòng)fastdfs默認(rèn)的配置文件。

  1. [root@localhost fastdfs-6.06]# cd /etc/fdfs/ 
  2. [root@localhost fdfs]# cp storage.conf.sample storage.conf 
  3. [root@localhost fdfs]# cp client.conf.sample client.conf 

說明:不需要生成tracker.conf,因?yàn)閟torage上不再運(yùn)行tracker服務(wù)

安裝Nginx

四臺(tái)storage上:安裝nginx及fastdfs-nginx-module

(1)解壓nginx

  1. [root@localhost source]# tar -zxvf nginx-1.17.8.tar.gz 

(2)解壓fastdfs-nginx-module

  1. [root@localhost source]# tar -zxvf V1.22.tar.gz 

(3)修改config文件,把/usr/local 替換成 /usr

  1. [root@localhost source]# cd fastdfs-nginx-module-1.22/ 
  2. [root@localhost fastdfs-nginx-module-1.22]# cd src 
  3. [root@localhost src]# vi config 

(4)Nginx配置,添加fastdfs-nginx-module和http_stub_status_module 模塊

  1. [root@localhost fdfs]# cd /usr/local/source/nginx-1.17.8/ 
  2. [root@localhost nginx-1.17.8]# ./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module --add-module=/usr/local/source/fastdfs-nginx-module-1.22/src/ 

(5)編譯安裝nginx

  1. [root@localhost nginx-1.17.8]# make && make install 

(6)檢查安裝是否成功

  1. [root@localhost nginx-1.17.8]# ls /usr/local/soft/ | grep nginx 
  2. nginx 

(7)查看指定的編譯參數(shù)是否起作用

  1. [root@localhost fdfs]# /usr/local/soft/nginx/sbin/nginx -V 
  2. nginx version: nginx/1.17.8 
  3. built by gcc 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)  
  4. configure arguments: --prefix=/usr/local/soft/nginx --with-http_stub_status_module --add-module=/usr/local/source/fastdfs-nginx-module-1.22/src/ 

配置并啟動(dòng)storage服務(wù)

四臺(tái)storage上:配置并啟動(dòng)storage服務(wù)

(1)創(chuàng)建storage服務(wù)所需的目錄

  1. [root@localhost fdfs]# mkdir /data/fastdfs/storage 
  2. [root@localhost fdfs]# chmod 777 /data/fastdfs/storage/ 

(2)配置storage服務(wù)

編輯storage的配置文件:

  1. [root@localhost fdfs]# vi /etc/fdfs/storage.conf 

各配置項(xiàng)包括:

  1. group_name = group1 
  2. #配置base_path為上面所創(chuàng)建的storage目錄 
  3. base_path = /data/fastdfs/storage 
  4. #store_path :存儲(chǔ)所在的目錄,可以設(shè)置多個(gè),注意從0開始 
  5. store_path0 = /data/fastdfs/storage 
  6. #tracker_server的ip和端口 
  7. tracker_server = 192.168.175.101:22122 
  8. tracker_server = 192.168.175.102:22122  
  9. #指定http服務(wù)的端口 
  10. http.server_port = 80 

配置的不同之處:

  1. 192.168.175.103   group_name = group1 
  2. 192.168.175.104   group_name = group1 
  3. 192.168.175.105   group_name = group2 
  4. 192.168.175.106   group_name = group2 

(3)啟動(dòng)storage服務(wù)

  1. [root@localhost fdfs]# /etc/init.d/fdfs_storaged start 
  2. 正在啟動(dòng) fdfs_storaged (via systemctl):                   [  確定  ] 

(4)檢查storage服務(wù)啟動(dòng)是否成功

  1. [root@localhost fdfs]# ps auxfww | grep fdfs 
  2. root      15630  0.0  0.0  12320   972 pts/0    S+   15:46   0:00  |   |           \_ grep --color=auto fdfs 
  3. root      15026  0.0  0.1 155696  6964 ?        Sl   15:13   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
  4. root      15573  2.7  1.7 150736 66292 ?        Sl   15:45   0:02 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf 

說明:看到fdfs_storaged,表示storage服務(wù)啟動(dòng)成功

(5)檢查storage服務(wù)是否已綁定到端口:23000

  1. [root@localhost fdfs]# netstat -anp | grep 23000 
  2. tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      15573/fdfs_storaged  

說明:23000 端口是在配置文件 /etc/fdfs/storage.conf中定義的,如下:

  1. # the storage server port 
  2. port = 23000 

配置fastdfs-nginx-module

四臺(tái)存儲(chǔ)服務(wù)器上:配置fastdfs-nginx-module

(1)生成配置文件

  1. [root@localhost nginx-1.17.8]# cp /usr/local/source/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/ 

(2)編輯配置文件

  1. [root@localhost nginx-1.17.8]# vi /etc/fdfs/mod_fastdfs.conf 

配置以下幾項(xiàng)

  1. group_name=group1 
  2. connect_timeout=10 
  3. tracker_server=192.168.175.101:22122 
  4. tracker_server=192.168.175.102:22122 
  5. url_have_group_name = true 
  6. store_path0=/data/fastdfs/storage 
  7. group_count = 2 
  8.  
  9. [group1] 
  10.  
  11. group_name=group1 
  12. storage_server_port=23000 
  13. store_path_count=1 
  14. store_path0=/data/fastdfs/storage 
  15.  
  16. [group2] 
  17.  
  18. group_name=group2 
  19. storage_server_port=23000 
  20. store_path_count=1 
  21. store_path0=/data/fastdfs/storage 

說明:最上面的group_name:當(dāng)機(jī)器屬于group1這組時(shí),值為group1;當(dāng)機(jī)器屬于group2這組時(shí),值為group2。

說明:url_have_group_name = true。注意:這一項(xiàng)不要漏掉,會(huì)導(dǎo)致nginx不正常工作

(3)復(fù)制另兩個(gè)web訪問用到配置文件到fdfs配置目錄下:

  1. [root@d5d19e99e782 /]# cp /usr/local/source/fastdfs-6.06/conf/http.conf /etc/fdfs/ 
  2. [root@d5d19e99e782 /]# cp /usr/local/source/fastdfs-6.06/conf/mime.types /etc/fdfs/ 

配置Nginx

四臺(tái)存儲(chǔ)服務(wù)器上:配置nginx

編輯nginx的配置文件:

  1. [root@localhost conf]# vi /usr/local/soft/nginx/conf/nginx.conf 

在server listen 80 的這個(gè)server配置下面,

增加一個(gè)location

  1. location ~/group([0-9]) { 
  2.     root  /data/fastdfs/storage/data; 
  3.     ngx_fastdfs_module; 
  4.  

啟動(dòng)nginx

(1)啟動(dòng)Nginx

  1. [root@localhost storage]# /usr/local/soft/nginx/sbin/nginx 

(2)檢查nginx是否已成功啟動(dòng)

  1. [root@localhost storage]# ps auxfww | grep nginx 
  2. root      24590  0.0  0.0  12320   980 pts/0    S+   16:44   0:00  |   |           \_ grep --color=auto nginx 
  3. root      24568  0.0  0.0  41044   428 ?        Ss   16:44   0:00  \_ nginx: master process /usr/local/soft/nginx/sbin/nginx 
  4. nobody    24569  0.0  0.1  74516  4940 ?        S    16:44   0:00      \_ nginx: worker process 

配置tracker服務(wù)

配置tracker服務(wù)

說明:這一步等待四臺(tái)storage server配置完成后再進(jìn)行。使用n=Nginx做upstream負(fù)載均衡的原因:可以通過一個(gè)地址訪問后端的多個(gè)group

(1)文件上傳完成后,從瀏覽器訪問各個(gè)storage的Nginx即可:

例如:

  1. http://192.168.175.103/group1/M00/00/00/rBEABF5aTRiAEuHwAAAABHf4XZU322.txt 
  2. http://192.168.175.104/group1/M00/00/00/rBEABF5aTRiAEuHwAAAABHf4XZU322.txt 
  3. http://192.168.175.105/group2/M00/00/00/rBEABl5aUAqAXLCZAAAABHf4XZU043.txt 
  4. http://192.168.175.106/group2/M00/00/00/rBEABl5aUAqAXLCZAAAABHf4XZU043.txt 

說明:各臺(tái)storage server的ip地址后面跟著上傳時(shí)所返回的地址。注意:只能訪問各臺(tái)機(jī)器所在的group,

  • 如果想通過統(tǒng)一的ip地址進(jìn)行訪問
  • 需要在Nginx中通過upstream訪問到后端的機(jī)器
  • 此Nginx應(yīng)運(yùn)行在tracker上

(2)配置nginx.conf

  1. [root@0268c2dc2bf6 ~]# vi /usr/local/soft/nginx/conf/nginx.conf 

內(nèi)容:

添加 upstream到后端的storage。

  1. upstream fdfs_group1 { 
  2.                 server 192.168.175.103:80 weight=1  max_fails=2 fail_timeout=30s; 
  3.                 server 192.168.175.104:80 weight=1  max_fails=2 fail_timeout=30s; 
  4.    } 
  5.  
  6.    upstream fdfs_group2 { 
  7.                 server 192.168.175.105:80 weight=1 max_fails=2 fail_timeout=30s; 
  8.                 server 192.168.175.106:80 weight=1 max_fails=2 fail_timeout=30s; 
  9.    } 

針對(duì)帶有g(shù)roup的url進(jìn)行處理

  1. location /group1 { 
  2.     proxy_next_upstream http_502 http_504 error timeout invalid_header; 
  3.     proxy_pass http://fdfs_group1; 
  4.     expires 30d; 
  5.   
  6.  location /group2 { 
  7.      proxy_next_upstream http_502 http_504 error timeout invalid_header; 
  8.      proxy_pass http://fdfs_group2; 
  9.      expires 30d; 
  10.  

(3)重啟測(cè)試

  1. [root@0268c2dc2bf6 ~]# /usr/local/soft/nginx/sbin/nginx -s stop 
  2. [root@0268c2dc2bf6 ~]# /usr/local/soft/nginx/sbin/nginx 

在瀏覽器中訪問:

  1. http://192.168.175.101/group1/M00/00/00/rBEABF5aTRiAEuHwAAAABHf4XZU322.txt 
  2. http://192.168.175.101/group2/M00/00/00/rBEABl5aUAqAXLCZAAAABHf4XZU043.txt 

本文轉(zhuǎn)載自微信公眾號(hào)「冰河技術(shù)」,可以通過以下二維碼關(guān)注。轉(zhuǎn)載本文請(qǐng)聯(lián)系冰河技術(shù)公眾號(hào)。   

 

責(zé)任編輯:武曉燕 來源: 冰河技術(shù)
相關(guān)推薦

2017-10-27 08:40:44

分布式存儲(chǔ)剪枝系統(tǒng)

2017-10-17 08:33:31

存儲(chǔ)系統(tǒng)分布式

2024-09-24 16:30:46

分布式鎖Redis數(shù)據(jù)中間件

2022-08-11 18:27:50

面試Redis分布式鎖

2016-01-12 14:59:40

分布式存儲(chǔ)分布式存儲(chǔ)架構(gòu)

2017-09-04 08:49:17

存儲(chǔ)原理架構(gòu)

2021-06-03 08:55:54

分布式事務(wù)ACID

2013-03-22 14:44:52

大規(guī)模分布式系統(tǒng)飛天開放平臺(tái)

2024-06-26 11:55:44

2020-10-15 19:22:09

Menger機(jī)器學(xué)習(xí)強(qiáng)化學(xué)習(xí)

2022-12-02 07:19:46

分布式數(shù)據(jù)庫數(shù)據(jù)分片

2024-10-07 08:52:59

分布式系統(tǒng)分布式 IDID

2024-02-22 17:02:09

IDUUID雪花算法

2023-09-11 11:22:22

分布式數(shù)據(jù)庫數(shù)據(jù)庫

2023-01-12 08:24:45

ZookeeperZK服務(wù)器

2017-09-11 15:19:05

CoCoA機(jī)器學(xué)習(xí)分布式

2024-08-07 08:15:47

2018-12-13 17:49:41

曙光

2022-11-25 17:29:27

分布式事務(wù)

2017-08-17 09:18:29

分布式存儲(chǔ)面試
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)