一張圖講解最少機器搭建FastDFS高可用分布式集群安裝說明


 很幸運參與零售雲快消平台的公有雲搭建及孵化項目。零售雲快消平台源於零售雲家電3C平台私有項目,是與公司業務強耦合的。為了適用於全場景全品類平台,集團要求項目平台化,我們搶先並承擔了此任務。並由我來主要負責平台建設及項目落地。

 今天講解在零售雲快消平台中使用的圖片服務FastDFS集群搭建說明,此集群模式是根據單機版的安裝說明,在之前已經分享過一篇 一張圖講解單機FastDFS圖片服務器安裝步驟(修訂版),改造成最少機器分布式集群安裝說明。

FastDFS是什么?

 FastDFS是一個開源的輕量級分布式文件系統,它對文件進行管理,功能包括:文件存儲、文件同步、文件訪問(文件上傳、文件下載)等,解決了大容量存儲和負載均衡的問題。特別適合以文件為載體的在線服務,如相冊網站、視頻網站等等。
 FastDFS為互聯網量身定制,充分考慮了冗余備份、負載均衡、線性擴容等機制,並注重高可用、高性能等指標,使用FastDFS很容易搭建一套高性能的文件服務器集群提供文件上傳、下載等服務。
--- 來源於百度百科

FastDFS 簡介

FastDFS分兩部分,跟蹤器(tracker)和存儲節點(storage)。

 Tracker是FastDFS的協調者,負責管理所有的storage server和group,每個storage在啟動后會連接Tracker,告知自己所屬的group等信息,並保持周期性的心跳,tracker根據storage的心跳信息,建立group==>[storage server list]的映射表。

 Storage 是以組(卷,group或volume)為單位組織,一個group內包含多台storage機器,數據互為備份,存儲空間以group內容量最小的storage為准,所以建議group內的多個storage盡量配置相同,以免造成存儲空間的浪費。

FastDFS是由2008年開始采用C語言研發致今在維護更新,已經廣泛使用,創始人余慶 現以有他自己的公眾號: 微信號: fastdfs100 , FastDFS官方 github https://github.com/happyfish100/ 已經有多個相關組件

最少機器高可用總覽圖

file

在以下配置中沒有說明VIP的配置,后面會對VIP詳細說明。
VIP的目的是統一負載storageserver,storageserver的伸縮性不影響使用方的。

一、環境准備

軟件版本說明:

libfastcommon 請采用最新版本, 本次使用最新版本: libfastcommon-1.0.42.tar.gz

FastDFS 請采用最新版本, 本次使用最新版本: fastdfs-6.04.tar.gz

fastdfs-nginx-module 請采用最新版本, 本次使用最新版本:fastdfs-nginx-module-1.22.tar.gz

nginx 請采用最新版本, 本次使用最新版本: nginx-1.16.1.tar.gz

操作系統:CentOS 7.X

最低高可用

四台機器 分配情況:

TrackerServer1 :192.168.0.1

TrackerServer2 :192.168.0.2

StorageServer1:192.168.0.3

StorageServer2:192.168.0.4

Tracker服務器准備上傳文件

准備上傳/opt/apps 目錄下:

libfastcommon-1.0.42.tar.gz
fastdfs-6.04.tar.gz

Storage服務器准備上傳文件

准備上傳/opt/apps 目錄下:

libfastcommon-1.0.42.tar.gz
fastdfs-6.04.tar.gz
fastdfs-nginx-module-1.22.tar.gz
 nginx-1.16.1.tar.gz

二、安裝過程

TrackerServer1安裝過程

1、安裝 libfastcommon-1.0.42.tar.gz

tar -zxvf libfastcommon-1.0.42.tar.gz
cd libfastcommon-1.0.42/
./make.sh
./make.sh install

2、安裝 FastDFS

tar -zxvf  fastdfs-6.04.tar.gz
cd fastdfs-6.04/
./make.sh
./make.sh install
#配置文件准備
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
Tracker Server 配置
vim /etc/fdfs/tracker.conf

修改配置如下:

#tracker server端口號
port=22122
#存儲日志和數據的根目錄
base_path=/opt/fastdfs/tracker

3、開放防火牆端口

1)打開跟蹤端口
vim /etc/sysconfig/iptables
2)添加以下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
3)重啟防火牆
service iptables restart

4、啟動Tracker

/etc/init.d/fdfs_trackerd start

TrackerServer2安裝過程

安裝步驟同TrackerServer1

StorageServer1安裝過程

1、安裝 libfastcommon-1.0.42.tar.gz

tar -zxvf libfastcommon-1.0.42.tar.gz
cd libfastcommon-1.0.42/
./make.sh
./make.sh install

2、安裝 FastDFS

tar -zxvf  fastdfs-6.04.tar.gz
cd fastdfs-6.04/
./make.sh
./make.sh install
#配置文件准備
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cd /opt/apps/fastdfs-6.04/conf
cp http.conf mime.types /etc/fdfs/

Storage Server 配置
vim /etc/fdfs/storage.conf

修改配置如下:

#storage server端口號
port=23000
#數據和日志文件存儲根目錄
base_path=/opt/fastdfs/storage
#第一個存儲目錄
store_path0=/opt/fastdfs/storepath0
#tracker服務器IP和端口
tracker_server=192.168.0.1:22122
tracker_server=192.168.0.2:22122
#http訪問文件的端口(默認8888,看情況修改,和nginx中保持一致)
http.server_port=8888

3、安裝Nginx和 fastdfs-nginx-module

1)安裝fastdfs-nginx-module
#解壓fastdfs-nginx-module
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
cd fastdfs-nginx-module-1.22/
cp ./src/mod_fastdfs.conf /etc/fdfs

2)安裝Nginx
#解壓nginx
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
#安裝nginx_http_image_filter_module
yum -y install gd-devel
#安裝依賴組件
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
#關聯模塊配置
./configure --add-module=../fastdfs-nginx-module-1.22/src --prefix=/usr/local/nginx --with-http_image_filter_module
#編譯nginx
make
#安裝nginx
make install

3)查看是否安裝成功
/usr/local/nginx/sbin/nginx -V

查看插件是否安裝成功

[root@FastDFS nginx-1.16.1]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) 
configure arguments: --add-module=../fastdfs-nginx-module-1.22/src --prefix=/usr/local/nginx --with-http_image_filter_module
[root@FastDFS nginx-1.16.1]#

4)修改Nginx配置

修改nginx.conf配置

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

修改配置如下:

user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
  sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8888;
        server_name  localhost;

        location ~/group1/M00 {
            ngx_fastdfs_module;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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;
        }
    }

    upstream storage_server_group1 {
        server 192.168.0.3:8888 weight=10;
        server 192.168.0.4:8888 weight=10;
    }
}

修改mod_fastdfs.conf配置

vim /etc/fdfs/mod_fastdfs.conf

修改配置如下:

#
connect_timeout=10
#tracker服務器IP和端口
tracker_server=192.168.0.1:22122
tracker_server=192.168.0.2:22122
#是否啟用group組名
url_have_group_name=true
#
store_path0=/opt/fastdfs/storepath0

5、開放防火牆端口

1)打開跟蹤端口
vim /etc/sysconfig/iptables

2)添加以下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT

3)重啟防火牆
service iptables restart

4、啟動Storage

/etc/init.d/fdfs_storaged start

5、啟動Nginx

#啟動
/usr/local/nginx/sbin/nginx
#停止
/usr/local/nginx/sbin/nginx -s stop
#重啟
/usr/local/nginx/sbin/nginx -s reload

StorageServer2安裝過程

安裝步驟同StorageServer1安裝過程

測試上傳圖片

使用TrackerServer1機器進行測試

1、Client配置
vim /etc/fdfs/client.conf

修改配置如下:

#
base_path=/opt/apps/fastdfs/client
#tracker服務器IP和端口
tracker_server=192.168.0.1:22122 
tracker_server=192.168.0.2:22122 

2、准備上傳的圖片
3、上傳圖片
 fdfs_upload_file /etc/fdfs/client.conf test.jpg

或使用以下命令測試

fdfs_test  /etc/fdfs/client.conf upload test.jpg

測試結果

[root@ecsf-toj5rfb9 apps]# fdfs_test  /etc/fdfs/client.conf upload test.jpg
This is FastDFS client test program v6.04

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.

[2019-11-13 17:53:15] DEBUG - base_path=/opt/fastdfs/client, connect_timeout=10, 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

tracker_query_storage_store_list_without_group: 
	server 1. group_name=, ip_addr=6.0.36.217, port=23000
	server 2. group_name=, ip_addr=6.0.36.218, port=23000

group_name=group1, ip_addr=192.168.0.4, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/BgAk2l3L0oSAAhsuAAHf-RXvI9M055.jpg
source ip address: 192.168.0.4
file timestamp=2019-11-13 17:53:08
file size=122873
file crc32=367993811
example file url: http://192.168.0.4/group1/M00/00/00/BgAk2l3L0oSAAhsuAAHf-RXvI9M055.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/BgAk2l3L0oSAAhsuAAHf-RXvI9M055_big.jpg
source ip address: 192.168.0.4
file timestamp=2019-11-13 17:53:08
file size=122873
file crc32=367993811
example file url: http://192.168.0.4/group1/M00/00/00/BgAk2l3L0oSAAhsuAAHf-RXvI9M055_big.jpg

本文由博客一文多發平台 OpenWrite 發布!

再次感謝!!! 您已看完全文,歡迎關注微信公眾號猿碼 ,你的支持是我持續更新文章的動力!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM