云原生分布式存儲系統FastCFS 安裝簡明教程

上一篇文章我們對余老師開發的分布式存儲系統FastCFS做了一個簡單的介紹,具體看這個鏈接:http://www.lxweimin.com/p/f09953393b1e

今天我講自己部署FastCFS集群并和k8s集群打通的全過程分享出來,希望能夠幫助到希望嘗試使用FastCFS的同學。

一、快速部署

如果你只是想簡單快速上手體驗 FastCFS,作為學習或者本地測試環境而非生產環境,你可以選擇以下兩種方式部署 FastCFS:

  • 部署本地單節點
  • Docker部署

1. 單機部署

單機部署FastCFS的github和gitee上面已經提供了比較完整的文檔說明。我這里摘抄一些,并做下說明:

  • 前提是安裝的機器必須已經安裝git客戶端。
  • 僅支持Centos7、Centos8兩個Linux發行版本,筆者在Centos7環境親測成功。

一鍵搭建(包括部署和運行)單節點(需要root身份執行):

git clone https://gitee.com/fastdfs100/FastCFS.git; 
cd FastCFS/
./helloWorld.sh

# 注意:helloWorld.sh將更改FastCFS相關配置文件,請不要在多節點集群上執行!

上述操作完成后,執行命令驗證安裝狀態:

df -h /opt/fastcfs/fuse | grep fuse

如果可以看到FastCFS掛載的文件目錄,說明安裝成功,你可以把/opt/fastcfs/fuse 當作本地文件系統訪問該目錄。

如果沒有安裝git客戶端,也沒有問題,只需要下載兩個sh文件并放到同一個文件夾即可,它們是:
helloWorld.sh
fastcfs.sh(值得注意的是fastcfs.sh支持源碼編譯安裝,但是個人覺得并不適合一鍵部署)

安裝命令如下(有git客戶端且已經按上一步安裝成功的可以略過)

mkdir fastcfs
cd fashcfs
wget https://toscode.gitee.com/fastdfs100/FastCFS/raw/master/helloWorld.sh
wget https://toscode.gitee.com/fastdfs100/FastCFS/raw/master/fastcfs.sh
chmod +x helloWorld.sh
chmod +x fastcfs.sh
./helloWorld.sh


一鍵部署的詳細說明,請參見這里一鍵部署詳細說明

2. Docker部署

官方暫時沒有提供Docker鏡像,為了方便大家快速體驗,筆者制作了一個單機版本的鏡像,已經push到Docker Hub,地址為:https://hub.docker.com/r/jerry6290/fastcfs

啟動方式:
docker run --name=fastCFS  --privileged -d jerry6290/fastcfs:v3.1.0

v3.1.0是版本號,可以根據實際情況修改成最新版本號。

注意:由于需要通過fuse把FastCFS作為目錄掛載,所以在docker run時需要增加參數 --privileged,讓容器真正有root權限。

登錄到容器驗證fastCFS
docker exec -it fastCFS sh

# 執行 df -h ,應該能看到 fastCFS的fs pool 被掛載到 /opt/fastcfs/fuse 目錄
df -h
Filesystem               Size  Used Avail Use% Mounted on
overlay                  500G  110G  391G  22% /
tmpfs                     64M     0   64M   0% /dev
tmpfs                     12G     0   12G   0% /sys/fs/cgroup
shm                       64M     0   64M   0% /dev/shm
/dev/mapper/centos-root  500G  110G  391G  22% /etc/hosts
/dev/fuse                342G     0  342G   0% /opt/fastcfs/fuse

# 寫文件
echo 'Hello FastCFS' > /opt/fastcfs/fuse/FastCFS.txt

# 查看文件內容
cat /opt/fastcfs/fuse/FastCFS.txt
Hello FastCFS

當然,你也可以通過-v的方式把/opt/fastcfs/fuse目錄掛載出來,具體做法就不贅述了。

該Dockerfile開源在github,并通過github Actions自動打包并push到docker hub,項目地址:https://github.com/jerry6290/dockerImage-fastCFS-Server

二、集群部署

1. 軟硬件環境準備

FastCFS作為一款開源云原生分布式存儲系統,可以很好的部署和運行在 Intel 架構服務器環境和主流虛擬化環境,并支持絕大多數的主流硬件和網絡, 支持主流的 Linux 操作系統環境。

1.1 操作系統發行版本要求:

Linux 操作系統平臺 版本
Red Hat Enterprise Linux 7.x及以上版本 版本
CentOS 7.x 及以上版本版本
Ubuntu LTS 16.04 及以上的版本

1.2 服務器建議配置


FastCFS有三大組件,FastDIR,FastStore,FastAuth,支持部署和運行在 Intel x86-64 和ARM架構硬件服務器平臺。

對于開發,測試,及生產環境的服務器硬件配置有以下要求和建議:

開發及測試環境:

組件 CPU 內存 硬盤 網絡 實例數量
FastDIR 4核+ 8G+ 無特殊要求 千兆網卡 1(可和FastStore,FastAuth同機器)
FastStore 4核+ 8G+ 無特殊要求,最好是SSD,容量大一些 千兆網卡 1(可和FastDIR,FastAuth同機器)
FastAuth 4核+ 8G+ 無特殊要求 千兆網卡 1(可和FastStore,FastDIR同機器)

生產環境:

組件 CPU 內存 硬盤 網絡 實例數量
FastDIR 8核+ 16G+ 無特殊要求 千兆網卡 3及以上,最好是奇數(可和FastStore,FastAuth同機器)
FastStore 8核+ 16G+ 最好是SSD,容量大一些 千兆網卡 6及以上,可根據需求的容量而定(可和FastDIR,FastAuth同機器)
FastAuth 8核+ 16G+ 無特殊要求 千兆網卡 3及以上,最好是奇數(可和FastStore,FastDIR同機器)

注意:

  • FastStore對服務器和數據均采用分組方式,服務器分組簡稱 SG,服務器分組組內的數據是冗余關系(服務器數即數據副本數)。一個SG可以容納多個數據分組DG,引入DG的主要目的是方便擴容時做數據遷移,因此最好預設得大一些,生產環境至少配置 256,開發測試環境至少配置16個。
  • 生產環境建議建2個以上SG,每個SG有3臺服務器,即3個數據副本,所以存儲數據的組件FastStore建議至少2*3=6臺服務器,以保證數據完整性。
  • FastAuth是可選,如果需要通過CSI集成到k8s,則需要開啟存儲池或訪問權限控制,需要部署FastAuth認證集群。
  • FastDIR啟用存儲插件的話,最好配置SSD。
  • 如果對性能和可靠性有更高的要求,fastDIR,fastStore,fastAuth三大組件應盡可能分開部署。

2. 環境及配置準備

2.1 SSH免密登錄

找一個服務器當中控機,比如:192.168.0.201,以root用戶登錄到中控機,執行以下命令。將 192.168.0.204 替換成你的受控機器 IP,按提示輸入受控機器root用戶密碼,執行成功后即創建好 SSH 互信,其他機器同理。

ssh-keygen -t rsa
# 一路回車
ssh-copy-id 192.168.0.204

驗證ssh免密是否成功,在中控機,通過 ssh 的方式登錄受控機器 IP。如果不需要輸入密碼并登錄成功,即表示 SSH 互信配置成功,如果沒有成功請檢查受控機器的sshd配置和相關安全策略。

ssh 192.168.0.204

2.2 端口準備

  • fastDIR
    • 默認集群端口 11011
    • 默認服務端口 11012
  • fastAuth
    • 默認集群端口 31011
    • 默認服務端口 31012
  • fastStore
    • 默認集群端口 21014
    • 默認副本端口 21015
    • 默認服務端口 21016

需要保證每臺服務器上述的端口是相互能通的,如果是在redhat7、centos7版本及以上版本,可以通過firewall-cmd命令打開服務器之間端口通信。比如在網段192.168.0.1/24,可以通過一下命令打開端口,其中網段和--zone=public需要自行根據自己的zone進行調整:

firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.1/24" port protocol=tcp port=11011-11012 accept'
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.1/24" port protocol=tcp port=21014-21016 accept'
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.1/24" port protocol=tcp port=31011-31012 accept'
firewall-cmd --reload

3. 集群拓撲規劃

FastCFS支持大規模的集群,下面以最為典型的最小化集群拓撲,1個服務器分組,該服務器分組下三臺服務器3個(3個數據副本)。更大規模的安裝方式可參照此過程擴展安裝,服務器的數量及配置參數按上文所述。

本次安裝教程,筆者手頭上的機器有限,準備了4臺機器,已經安裝好centos7.9,對應的端口防火墻已經打開,,集群拓撲規劃如下:

  • 3個FastStore節點、3個FastDir節點、3個FastAuth節點,一個fuse客戶端節點
  • FastStore、FastDir、FastAuth公用3個節點。
組件 服務器IP 個數
FastDir 192.168.0.201,192.168.0.204,192.168.0.205 3
FastStore 192.168.0.201,192.168.0.204,192.168.0.205 3
FastAuth 192.168.0.201,192.168.0.204,192.168.0.205 3
Fast-fuse客戶端 192.168.0.203 1

4. 集群安裝與配置

4.1 yum方式安裝

4.1.1 FastOS.repo yum源

需要在每個節點安裝,命令:

rpm -ivh http://www.fastken.com/yumrepo/el7/x86_64/FastOSrepo-1.0.0-1.el7.centos.x86_64.rpm

4.1.2 安裝FastDIR

分別在192.168.0.201,204,205安裝

yum install fastDIR-server -y

安裝完畢后,在/etc/fastcfs 下可看到FastDIR的配置文件,在/usr/bin/目錄看到fdir_*相關的程序

$ ll /etc/fastcfs/fdir/
total 16
-rw-r--r--. 1 root root  134 Jan 20 23:24 client.conf
-rw-r--r--. 1 root root  291 Jan 20 23:24 cluster.conf
-rw-r--r--. 1 root root 2160 Jan 20 23:24 server.conf
-rw-r--r--. 1 root root  726 Jan 20 23:24 storage.conf


ll /usr/bin/ |grep fdir_*
-rwxr-xr-x.   1 root root      11336 Jan 20 20:51 fdir_cluster_stat
-rwxr-xr-x.   1 root root      11472 Jan 20 20:51 fdir_getxattr
-rwxr-xr-x.   1 root root      11344 Jan 20 20:51 fdir_list
-rwxr-xr-x.   1 root root       7200 Jan 20 20:51 fdir_list_servers
-rwxr-xr-x.   1 root root      11344 Jan 20 20:51 fdir_mkdir
-rwxr-xr-x.   1 root root      11312 Jan 20 20:51 fdir_remove
-rwxr-xr-x.   1 root root      11312 Jan 20 20:51 fdir_rename
-rwxr-xr-x.   1 root root     234208 Jan 20 20:51 fdir_serverd
-rwxr-xr-x.   1 root root      11384 Jan 20 20:51 fdir_service_stat
-rwxr-xr-x.   1 root root      11328 Jan 20 20:51 fdir_setxattr
-rwxr-xr-x.   1 root root      11328 Jan 20 20:51 fdir_stat

4.1.2 安裝FastStore

分別在192.168.0.201,204,205安裝

yum install faststore-server -y

安裝完畢后,在/etc/fastcfs 下可看到FastStore的配置文件,在/usr/bin/目錄看到fs_*相關的程序

ll /etc/fastcfs/fstore/
total 16
-rw-r--r--. 1 root root  147 Jan 20 23:24 client.conf
-rw-r--r--. 1 root root 1739 Jan 20 23:24 cluster.conf
-rw-r--r--. 1 root root 1274 Jan 20 23:24 server.conf
-rw-r--r--. 1 root root  673 Jan 20 23:24 storage.conf



ll /usr/bin/ |egrep " fs_"
-rwxr-xr-x.   1 root root      11488 Jan 13 10:32 fs_cluster_stat
-rwxr-xr-x.   1 root root      11440 Jan 13 10:32 fs_delete
-rwxr-xr-x.   1 root root      11480 Jan 13 10:32 fs_read
-rwxr-xr-x.   1 root root     447336 Jan 13 10:32 fs_serverd
-rwxr-xr-x.   1 root root      11424 Jan 13 10:32 fs_service_stat
-rwxr-xr-x.   1 root root      11456 Jan 13 10:32 fs_write

4.1.3 安裝FastAuth

分別在192.168.0.201,204,205安裝

yum install FastCFS-auth-server -y

安裝完畢后,在/etc/fastcfs 下可看到FastAuth的配置文件

ll /etc/fastcfs/auth/
total 20
-rw-r--r--. 1 root root  411 Jan 21 00:47 auth.conf
-rw-r--r--. 1 root root  134 Jan 21 00:47 client.conf
-rw-r--r--. 1 root root  148 Jan 21 19:18 cluster.conf
drwxr-xr-x. 2 root root   51 Jan 21 15:47 keys
-rw-r--r--. 1 root root 1627 Jan 21 00:47 server.conf
-rw-r--r--. 1 root root  145 Jan 21 00:47 session.conf

4.1.3 安裝Fast-fused客戶端

客戶端只需要在192.168.0.203安裝

yum remove fuse -y
yum install FastCFS-fused -y

說明:

  • centos版本中的fuse為老版本的包(fuse2.x),需要卸載才可以成功安裝FastCFS-fused依賴的fuse3;
  • 第一次安裝才需要卸載fuse包,以后就不用執行了。

安裝完畢后,在/etc/fastcfs 下可看到fcfs的配置文件

 ll /etc/fastcfs/
total 0
drwxr-xr-x 3 root root 113 Feb  3 14:38 auth
drwxr-xr-x 2 root root  23 Feb  3 14:38 fcfs
drwxr-xr-x 2 root root  84 Feb  3 14:38 fdir
drwxr-xr-x 2 root root  84 Feb  3 14:38 fstore

4.1.4 集群配置

FastCFS并沒有統一的配置中心,需要在各個節點上單獨部署配置文件。配置文件分為三大類:集群配置文件、服務配置文件、客戶端配置文件。

  1. 集群配置文件: 指的是描述 FastDir 、 FastStore、FastAuth 的配置文件,入口文件名稱為cluster.conf . 該配置文件中設定是集群的參數,如服務節點的IP、服務端口號、集群同步端口號,服務節點的拓撲結構等。 cluster.conf 文件全局統一,各個節點上的內容是相同的。

  2. 服務配置文件: 指的是服務本身的配置文件,入口文件名稱server.conf 如線程數量、鏈接數量、緩沖區大小、存儲配置、日志配置等。 服務配置文件的內容,可以全局不統一。不過從集群運維方便的角度考慮,服務器配置最好是統一的。

  3. 客戶端配置文件: 指的是fuse或者其他客戶端的配置,比如fuse客戶端需要知道fdir、fstore、fauth的集群情況,所以客戶端需要fdir、fstore和fauth的server服務集群的配置。

下面針對三大組件和客戶端的配置進行詳細說明:

fdir 配置

用root登錄主控機192.168.0.201

  • 修改fdir集群配置文件
    修改/etc/fastcfs/fdir/cluster.conf 文件,修改為上面提到的三個IP地址(修改成你自己對應的IP),[sever-1]為192.168.0.201,[sever-2]為192.168.0.204,[sever-3]為192.168.0.205,如果你有更多fdir節點,增加配置[server-N]即可,修改后的內容如下:
# config the auth config filename
auth_config_filename = ../auth/auth.conf

[group-cluster]
# the default cluster port
port = 11011

[group-service]
# the default service port
port = 11012

[server-1]
host = 192.168.0.201 #節點1

[server-2]
host = 192.168.0.204 #節點2

[server-3]
host = 192.168.0.205 #節點3
  • 修改fdir服務配置文件
    修改/etc/fastcfs/fdir/server.conf 文件,內容如下:
# the base path to store log files
# this path must be exist
base_path = /opt/fastcfs/fdir

# the path to store data files
# can be an absolute path or a relative path
# the relative path for sub directory under the base_path
# this path will be created auto when not exist
# default value is data
data_path = data

# max concurrent connections this server support
# you should set this parameter larger, eg. 10240
# default value is 256
max_connections = 10240

# the data thread count
# these threads deal CUD (Create, Update, Delete) operations
# dispatched by the hash code of the namespace
# if you have only one namespace, you should config this parameter to 1,
# because it is meaningless to configure this parameter greater than 1 in this case
# default value is 1
data_threads = 1


# the cluster id for generate inode
# must be natural number such as 1, 2, 3, ...
#
## IMPORTANT NOTE: do NOT change the cluster id after set because the 64 bits
##                 inode includes the cluster id, and the inode disorder maybe
##                 lead to confusion
cluster_id = 1

# config cluster servers
cluster_config_filename = cluster.conf

# session config filename for auth
session_config_filename = ../auth/session.conf


[storage-engine]
# if enable the storage engine
### false: use binlog directly
### true: use storage engine for massive files
# default value is false,如果設置為true,還需要配置storage.conf
enabled = false

# the config filename for storage
storage_config_filename = storage.conf

# the path to store the data files
# can be an absolute path or a relative path
# the relative path for sub directory under the base_path
# this path will be created auto when not exist
# default value is db
data_path = db

# the interval for lru elimination
# <= 0 for never eliminate
# unit: seconds
# default value is 1
eliminate_interval = 1

# the memory limit ratio for dentry
# the valid limit range is [1%, 99%]
# default value is 80%
memory_limit = 80%


[cluster]
# the listen port
port = 11011

# the network thread count
# these threads deal network io
# dispatched by the incoming socket fd
# default value is 4
work_threads = 2

[service]
port = 11012
work_threads = 4

server.conf基本上用默認配置即可,如果需要開啟存儲插件,需要把[storage-engine]下面的enable=true,同時配置storage.conf。

  • 復制cluster文件到其他節點
    fdir的cluster.conf,server.conf配置完成后,把cluster.conf配置文件通過scp命令復制到其他節點(包括客戶端節點),server.conf不需要復制:
scp /etc/fastcfs/fdir/cluster.conf 192.168.0.204:/etc/fastcfs/fdir/cluster.conf
scp /etc/fastcfs/fdir/cluster.conf 192.168.0.205:/etc/fastcfs/fdir/cluster.conf
scp /etc/fastcfs/fdir/cluster.conf 192.168.0.203:/etc/fastcfs/fdir/cluster.conf
fstore 配置

用root登錄主控機192.168.0.201

  • 修改fstore集群配置文件

非常重要:

fstore是存儲數據的核心組件,修改cluster配置文件,一定要了解fstore存儲的基本原理。了解SG(服務器分組),DG(數據分組),DGC(數據分組數)等幾個名詞的相互關系。上面的拓撲規劃時已經簡單描述過,更詳細查看作者余大的技術文章:https://my.oschina.net/u/3334339/blog/4870261

修改/etc/fastcfs/fstore/cluster.conf 文件,讓fstore的集群拓撲為:1個SG,SG里面包含三臺服務器,DG為2,DGC為128,修改后的內容如下:

# the group count of the servers / instances
server_group_count = 1 # SGC=1

# all data groups must be mapped to the server group(s) without omission.
# once the number of data groups is set, it can NOT be changed, otherwise
# the data access will be confused!
data_group_count = 128 #DGC

# config the auth config filename
auth_config_filename = ../auth/auth.conf

[group-cluster]
# the default cluster port
port = 21014

[group-replica]
# the default replica port
port = 21015

[group-service]
# the default service port
port = 21016

[server-group-1]
server_ids = [1, 3]
data_group_ids = [1, 64]
data_group_ids = [65, 128]

[server-1]
host = 192.168.0.201

[server-2]
host = 192.168.0.204

[server-3]
host = 192.168.0.205

server.conf基本上用默認配置即可,如果需要修改存儲目錄,需要修改storage.conf,如果有多個數據盤可以配置多個目錄,充分利用硬盤空間

# the write thread count per store path
# the default value is 1
write_threads_per_path = 1

# the read thread count per store path
# the default value is 1,如果有多個盤可以配置多個目錄,充分利用硬盤空間
read_threads_per_path = 1

# usually one store path for one disk
# each store path is configurated in the section as: [store-path-$id],
# eg. [store-path-1] for the first store path, [store-path-2] for
#     the second store path, and so on.
store_path_count = 1

# reserved space of each disk for system or other applications.
# the value format is XX%
# the default value is 10%
reserved_space_per_disk = 10%


#### store paths config #####

[store-path-1]
# the path to store the file,如果有多個盤可以配置多個目錄,充分利用硬盤空間
path = /opt/faststore/data

  • 復制cluster文件到其他節點
    fstore的cluster.conf,server.conf,storage.conf配置完成后,把cluster.conf配置文件通過scp命令復制到其他節點,server.conf不需要復制:
scp /etc/fastcfs/fstore/cluster.conf 192.168.0.204:/etc/fastcfs/fstore/cluster.conf
scp /etc/fastcfs/fstore/cluster.conf 192.168.0.205:/etc/fastcfs/fstore/cluster.conf
fauth 配置

用root登錄主控機192.168.0.201

  • 修改fauth集群配置文件
    修改/etc/fastcfs/auth/cluster.conf 文件,修改為上面提到的三個IP地址(修改成你自己對應的IP),[sever-1]為192.168.0.201,[sever-2]為192.168.0.204,[sever-3]為192.168.0.205,如果你有更多fauth節點,增加配置[server-N]即可,修改后的內容如下:
[group-cluster]
# the default cluster port
port = 31011

[group-service]
# the default service port
port = 31012

[server-1]
host = 192.168.0.201

[server-2]
host = 192.168.0.204

[server-3]
host = 192.168.0.205
  • 修改auth.conf開啟認證
    把 /etc/fastcfs/auth/auth.conf 文件里面的auth_enabled = true ,修改后內容:
# enable / disable authentication
# default value is false
auth_enabled = true

# the username for login
# default value is admin
username = admin

# the secret key filename of the user
# variable ${username} will be replaced with the value of username
# default value is keys/${username}.key
secret_key_filename = keys/${username}.key

# the config filename of auth client
client_config_filename = client.conf
  • 復制cluster文件到其他節點
    fauth的cluster.conf,auth.conf配置完成后,把cluster.conf、auth.conf配置文件通過scp命令復制到其他節點,server.conf不需要復制:
scp /etc/fastcfs/auth/cluster.conf 192.168.0.204:/etc/fastcfs/auth/cluster.conf
scp /etc/fastcfs/auth/cluster.conf 192.168.0.205:/etc/fastcfs/auth/cluster.conf
scp /etc/fastcfs/auth/cluster.conf 192.168.0.203:/etc/fastcfs/auth/cluster.conf
scp /etc/fastcfs/auth/auth.conf 192.168.0.204:/etc/fastcfs/auth/auth.conf
scp /etc/fastcfs/auth/auth.conf 192.168.0.205:/etc/fastcfs/auth/auth.conf
scp /etc/fastcfs/auth/auth.conf 192.168.0.203:/etc/fastcfs/auth/auth.conf
集群啟動

集群的配置文件在各個節點已經配置和分發完畢,下面可以開始啟動集群了。
啟動順序如下:

  1. fdir
  2. fauth
  3. fstore
    用root用戶分別登錄到3個節點,執行如下命令:
systemctl restart fastdir
systemctl restart fastauth
systemctl restart faststore

如果啟動有問題,請檢查配置文件,具體啟動日志可以查看/opt/fastcfs/下對應的auth、fdir、fstore三個目錄里面的logs目錄。

客戶端啟動

如果三個節點的所有組件啟動沒有錯誤,在客戶端節點可以啟動客戶端程序,把fastCFS的默認pool fs掛載到相應目錄。
以本次部署為例,root用戶登錄到客戶端節點192.168.0.203,執行命令:

systemctl restart fastcfs

查看日志文件/opt/fastcfs/fcfs/logs/fcfs_fused.log看下啟動是否有誤,如果無誤可以通過df -h查看掛載的目錄 /opt/fastcfs/fuse

df -h
Filesystem               Size  Used Avail Use% Mounted on
overlay                  500G  110G  391G  22% /
tmpfs                     64M     0   64M   0% /dev
tmpfs                     12G     0   12G   0% /sys/fs/cgroup
shm                       64M     0   64M   0% /dev/shm
/dev/mapper/centos-root  500G  110G  391G  22% /etc/hosts
/dev/fuse                342G     0  342G   0% /opt/fastcfs/fuse

4.2 部署工具fastcfs.sh安裝

運維工具fastcfs.sh方式的安裝,請參考官方文檔,這里不贅述:https://github.com/happyfish100/FastCFS/blob/master/docs/fcfs-ops-tool-zh_CN.md

4.3 Ansible方式安裝(推薦、未完成)

4.4 K8S Operator方式安裝(未完成)

5. 驗證集群狀態

5.1 fdir集群狀態

查詢fdir整個集群狀態

fdir_cluster_stat
# 輸出如下
server_id: 1, host: 192.168.0.201:11012, status: 23 (ACTIVE), is_master: 0
server_id: 2, host: 192.168.0.204:11012, status: 23 (ACTIVE), is_master: 0
server_id: 3, host: 192.168.0.205:11012, status: 23 (ACTIVE), is_master: 1

server count: 3

查詢fdir某個節點狀態,1表示是server編號,和cluster.conf里面的server-N相對應

fdir_service_stat 1

# 輸出如下
        server_id: 1
        host: 192.168.0.201:11012
        status: 23 (ACTIVE)
        is_master: false
        connection : {current: 4, max: 4}
        binlog : {current_version: 48}
        dentry : {current_inode_sn: 5000020, ns_count: 2, dir_count: 10, file_count: 4}

5.2 fstore集群狀態

顯示所有狀態

fs_cluster_stat
# 輸出如下:
data_group_id: 1
        server_id: 1, host: 192.168.0.201:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0
        server_id: 2, host: 192.168.0.204:21016, status: 5 (ACTIVE), is_preseted: 1, is_master: 1, data_version: 0
        server_id: 3, host: 192.168.0.205:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0
.... 省略N個
data_group_id: 127
        server_id: 1, host: 192.168.0.201:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0
        server_id: 2, host: 192.168.0.204:21016, status: 5 (ACTIVE), is_preseted: 1, is_master: 1, data_version: 0
        server_id: 3, host: 192.168.0.205:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0

data_group_id: 128
        server_id: 1, host: 192.168.0.201:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0
        server_id: 2, host: 192.168.0.204:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0
        server_id: 3, host: 192.168.0.205:21016, status: 5 (ACTIVE), is_preseted: 1, is_master: 1, data_version: 0

data server count: 384

顯示某個sg狀態,比如sg=1

fs_cluster_stat -g 1

#輸出如下:
data_group_id: 1
        server_id: 1, host: 192.168.0.201:21016, status: 5 (ACTIVE), is_preseted: 1, is_master: 1, data_version: 0
        server_id: 2, host: 192.168.0.204:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0
        server_id: 3, host: 192.168.0.205:21016, status: 5 (ACTIVE), is_preseted: 0, is_master: 0, data_version: 0

data server count: 3

更多查看

fs_cluster_stat -help

5.1 fauth集群狀態

fauth_cluster_stat

#輸出如下:
server_id: 1, host: 192.168.0.201:31012, is_online: 1, is_master: 0
server_id: 2, host: 192.168.0.204:31012, is_online: 1, is_master: 0
server_id: 3, host: 192.168.0.205:31012, is_online: 1, is_master: 1

server count: 3

6. 集群管理

6.1 fdir相關操作

fdir有fdir_list、fdir_mkdir、fdir_rename、fdir_remove、fdir_getxattr、fdir_setxattr等,還有fcfs_pool管理、查看pool相關
比如查看pool fs,可以通過fdir_list,更多的信息查看用-help 查看

fdir_list -n fs /

查看pool列表

fcfs_pool plist

6.2 fstore相關操作

fs_read,fs_write,fs_delete等,相關命令還不熟,研究中...

6.3 fauth相關操作

fcfs_user 查看,新增,刪除,設置用戶權限等
查看用戶列表

fcfs_user list

更多操作

Usage: fcfs_user [-c config_filename=/etc/fastcfs/auth/client.conf]
        [-u admin_username=admin]
        [-k admin_secret_key_filename=/etc/fastcfs/auth/keys/${username}.key]
        [-p priviledges=pool]
        <operation> [username]
        [user_secret_key_filename=keys/${username}.key]

        the operations and parameters are:
          create <username> [user_secret_key_filename]
          passwd | secret-key <username> [user_secret_key_filename] [-y]: regenerate user's secret key
          grant <username>, the option <-p priviledges> is required
          delete | remove <username>
          list [username]

        [user_secret_key_filename]: specify the filename to store the generated secret key of the user
        [priviledges]: the granted priviledges seperate by comma, priviledges:
          user: user management
          pool: create storage pool
          cluster: monitor cluster
          session: subscribe session for FastDIR and FastStore server side
          *: for all priviledges

7. 測試集群性能

更多性能測試查看官方測試結果:https://github.com/happyfish100/FastCFS/blob/master/docs/benchmark.md

8. Kubernetes CSI安裝與配置

終于到了對k8s的支持,作為云原生分布式存儲,對k8s的支持肯定是少不了的。

8.1 用戶和pool準備

CSIDriver必須要求FastCFS 啟用驗證模塊auth_enabled = true,因為k8s的CSI要求支持卷支持定義容量,不同卷是相互獨立的。pool就是為此設計的,在CSI Driver中一個卷就是一個pool,而pool是屬于用戶進行管理的。

為CSI單獨創建一個用戶:k8s,當然可以用admin用戶,但是不推薦。

fcfs_user create k8s
create user k8s success, secret key store to file: keys/k8s.key

新建k8s用戶成功后會在當前目錄下keys目錄生成k8s.key文件,這個文件的內容后面會用到。
查看用戶:

fcfs_user list
  No.                         username                      priviledges
   1.                            admin                                *
   2.                           admin1                                *
   3.                              k8s                             pool

8.2 配置準備

FastCFS CSI是利用fused客戶端來實現的卷的創建、掛載等操作。上面已經說到FastCFS沒有統一的配置中心,而客戶端又需要FastCFS集群相關的配置信息,所以需要把集群的配置讓CSI讀取到。
CSI現在實現的方式是通過http uri來讀取,因此需要把配置文件通過web服務器暴露處理,可以通過nginx、apache等web服務器。

現在CSI需要依賴一個web服務器,其實可以通過configMap掛載文件的方式來實現,已經給官方提供建議并被采納,不依賴uri的新CSI版本應該很快和大家見面。

筆者使用的是nginx,把192.168.0.201的/etc/fastcfs目錄通過nginx暴露出來,具體細節請參考nginx文檔,比如我這里的地址是:http://192.168.0.201:1808/

  • ConfigMap準備
    創建fastcfs-csi-cm.yml文件,并填入以下內容,其中configURL需要修改成你自己的可以獲取fastcfs配置的web服務器地址:
apiVersion: v1
kind: ConfigMap
data:
  config.json: |-
    [
      {
        "clusterID": "virtual-cluster-id-1",
        "configURL": "http://192.168.0.201:1808/"
      }
    ]
metadata:
  name: fcfs-csi-config

執行

kubectl apply -f fastcfs-csi-cm.yml
  • Secret準備
    Secret用來保存剛才創建的用戶的用戶名和密鑰,還是以k8s為例,查看keys/k8s.key文件
cat keys/k8s.key
407f1379637afba188d31a795d0224e8

創建fastcfs-csi-secret.yml,并填入內容,407f1379637afba188d31a795d0224e8 改成你自己的密鑰。

---
apiVersion: v1
kind: Secret
metadata:
  name: csi-fcfs-secret
  namespace: default
stringData:
  # 其實這里并需要admin用戶,先填k8s用戶和密鑰
  adminName: k8s
  adminSecretKey: 407f1379637afba188d31a795d0224e8 
  # use static pv for user
  userName: k8s
  userSecretKey: 407f1379637afba188d31a795d0224e8 

執行

kubectl apply -f fastcfs-csi-secret.yml

8.3 Helm3準備

添加 fastcfs-csi Helm 存儲庫:

helm repo add fastcfs-csi https://happyfish100.github.io/fastcfs-csi
helm repo update

8.4 安裝FastCFS CSI

  • 使用helm chart 安裝驅動程序的版本

注意helm中容器用到了 k8s.gcr.io 下面的image,如果沒有條件,docker hub上面已經有人做了鏡像,可以按下面的步驟修改:

helm pull fastcfs-csi/fcfs-csi-driver
tar -xzvf fcfs-csi-driver-0.3.0.tgz
vi fcfs-csi-driver/values.yaml

把里面相關 k8s.gcr.io/sig-storage開頭的6個image地址修改成如下內容:

sidecars:
  provisionerImage:
    repository: opsdockerimage/sig-storage-csi-provisioner
    tag: "v2.1.1"
  attacherImage:
    repository: opsdockerimage/sig-storage-csi-attacher
    tag: "v3.1.0"
  snapshotterImage:
    repository: opsdockerimage/sig-storage-csi-snapshotter
    tag: "v3.0.3"
  livenessProbeImage:
    repository: opsdockerimage/sig-storage-livenessprobe
    tag: "v2.2.0"
  resizerImage:
    repository: opsdockerimage/sig-storage-csi-resizer
    tag: "v1.0.0"
  nodeDriverRegistrarImage:
    repository: opsdockerimage/sig-storage-csi-node-driver-registrar
    tag: "v2.1.0"

最后執行安裝操作:

helm upgrade --install fastcfs-csi ./fcfs-csi-driver

如果你可以連接,可忽略上面的步驟,直接執行:

helm upgrade --install fastcfs-csi fastcfs-csi/fcfs-csi-driver
  • 創建靜態卷
    創建文件fastcfs-static-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv
spec:
  capacity:
    storage: 1Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  storageClassName: ""
  csi:
    driver: fcfs.csi.vazmin.github.io
    # volumeHandle should be same as FastCFS pool name
    volumeHandle: test-pv
    nodeStageSecretRef:
      # node stage secret name
      name: csi-fcfs-secret
      # node stage secret namespace where above secret is created
      namespace: default
    volumeAttributes:
      # Required options from storage class parameters need to be added in volumeAttributes
      "clusterID": "virtual-cluster-id-1"
      "static": "true"
  persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: fcfs-claim
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: ""
  resources:
    requests:
      storage: 1Gi
  volumeName: test-pv
---

執行:

kubectl apply -f fastcfs-static-pv.yml
  • 創建storageClass和動態卷
    創建fastcfs-storageClass.yml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-fcfs-sc
provisioner: fcfs.csi.vazmin.github.io
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true
parameters:

  # The secrets have to contain admin credentials.
  csi.storage.k8s.io/provisioner-secret-name: csi-fcfs-secret
  csi.storage.k8s.io/provisioner-secret-namespace: default
  csi.storage.k8s.io/controller-expand-secret-name: csi-fcfs-secret
  csi.storage.k8s.io/controller-expand-secret-namespace: default
  csi.storage.k8s.io/node-stage-secret-name: csi-fcfs-secret
  csi.storage.k8s.io/node-stage-secret-namespace: default
  csi.storage.k8s.io/node-publish-secret-name: csi-fcfs-secret
  csi.storage.k8s.io/node-publish-secret-namespace: default

  clusterID: virtual-cluster-id-1

創建fastcfs-dynamic-pv.yml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-fcfs-claim
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: csi-fcfs-sc
  resources:
    requests:
      storage: 1Gi

執行

kubectl apply -f fastcfs-storageClass.yml
kubectl apply -f fastcfs-dynamic-pv.yml

查看生成的pool,說明新建CSI Driver集成成功!

fcfs_pool plist k8s
  No.                                          pool_name      quota (GiB)
   1.   csi-vol-pvc-5722b1ea-548e-4154-95bf-fbef9c4fab8a                1

三、總結

FastCFS支持大規模的集群,對服務器要求不高,但是由于沒有統一配置中心,如果節點比較多的話,配置會稍顯麻煩,雖然官方也可以fcfs.sh運維工具,但是還是不夠好用,可以考慮用ansible等工具來安裝,后來筆者會寫一個ansible的playbook來簡化安裝FastCFS集群。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容