天天學五分鐘 Liunx 0000 | 存儲篇:GlusterFS


GlusterFS

GlusterFS,是一個分佈式文件系統,它經過 TCP/IP 或 IB(InfiniBand RDMA)網絡將多個存儲資源整合在一塊兒,提供存儲服務,具備很強的可擴展能力。
 

GlusterFS 工做原理

 
如上圖所示。GlusterFS 的 server 端共享存儲資源,client 端經過 TCP 或 IB 鏈接到 server,而後將 server 端的存儲資源掛載到本地目錄。應用(Application) 對本地目錄文件的讀寫請求會轉交給內核的 VFS,而後到 FUSE 文件系統,FUSE 將此請求轉交給設備 /dev/fuse,設備 /dev/fuse 再遞交給 GlusterFS 的 client 端,client 經過比對 GlusterFS client 端的配置文件,根據配置文件的定義作一些處理,最後去 server 上讀取存儲資源的數據,實現應用讀寫文件的操做。
 
從上圖也能夠看出,無論是 GlusterFS 和 Application 都須要通過 VFS,它是相當重要的存在。 VFS(Virtual File System,虛擬文件系統)是管理整個 Liunx 文件系統的文件系統,用戶再訪問文件目錄的時候,不須要管這個目錄用的是什麼文件系統,是 ext4 仍是 GlusterFS 等等,這些都是 VFS 來判斷處理的,由於它不像 ext4 / GlusterFS 這種文件系統是實際存在的,因此叫虛擬文件系統。
VFS 示意圖以下:
 

GlsterFS 部署

GlusterFS 部署流程:
1. GlusterFS 環境準備;
2. GlsuterFS 軟件包安裝,啓動 GlusterFS 服務;
3. server 端建立文件系統;
4. 建立 GlusterFS volume;
5. client 端掛載 volume;
 
1. GlusterFS 環境準備
主機名
ip
硬盤
NFS
server1.local
192.168.4.141
/dev/vdb
LV:5000M lianhua, 1000M huasheng
server2.local
192.168.4.59
/dev/vdb
LV:5000M lianhua, 1000M huasheng
server3.local
192.168.4.105
/dev/vdb
LV:5000M lianhua, 1000M huasheng
client1.local
192.168.4.144
/dev/vdb
 
 
配置 hosts 文件,將主機信息寫到 /etc/hosts 中,每臺機器都要寫:
[root@server1:/root]
# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 
192.168.4.141      server1.local
192.168.4.59       server2.local
192.168.4.105      server3.local

 

關閉 iptables 和 SELiunx,確保 server 之間能相互訪問,而且 client 能訪問到 server。
 
 
2. GlusterFS 軟件包安裝
[root@server1:/root] wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo  
[root@server1:/root] yum  -y  install centos-release-gluster312.noarch
[root@server1:/root] yum -y --enablerepo=centos-gluster*-test install glusterfs-server glusterfs-cli glusterfs-geo-replication
[root@server1:/root] yum -y --enablerepo=centos-gluster*-test install glusterfs-server glusterfs-cli glusterfs-geo-replication
[root@server1:/root] systemctl start glusterd.service
[root@server1:/root] systemctl enable glusterd.service
[root@server1:/root] systemctl status glusterd.service
# systemctl status glusterd.service
● glusterd.service - GlusterFS, a clustered file-system server
   Loaded: loaded (/etc/systemd/system/glusterd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-03-28 14:27:24 CST; 6h ago
Main PID: 4519 (glusterd)
    Tasks: 188 (limit: 4915)
   Memory: 324.8M
 
[root@server1:/root] glusterfs -V
glusterfs 3.12.15
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
 
3. server 端建立文件系統
這裏硬盤只有一塊 vdb ,因此用 LVM 的方式建立兩個 LV lianhua 和 huasheng 做爲 GlusterFS 的磁盤。
<LVM 的介紹可看這裏>
 
在每臺 server 上,將 lianhua 和 huasheng 格式化爲 ext4 文件系統,而後分別掛載到 /mnt/bricks/lianhua 和 /mnt/bricks/huasheng 目錄。直接 show 結果:
[root@server1:/root]
# df -hT
Filesystem                                                               Type            Size  Used Avail Use% Mounted on
/dev/vda1                                                                ext4             40G  4.7G   33G  13% /
tmpfs                                                                    tmpfs           8.9G  3.9M  8.9G   1% /tmp
/dev/mapper/server1--vol-lianhua                                         ext4            4.6G   23M  4.3G   1% /mnt/bricks/lianhua
/dev/mapper/server1--vol-huasheng                                        ext4            4.6G   20M  4.3G   1% /mnt/bricks/huasheng
 
4. 建立 GlusterFS volume
建立 GlusterFS volume 以前,在任意一臺主機中將其它 server 主機加入到 glusterFS 主機池中:
[root@server1:/root]
# gluster peer probe server2
[root@server1:/root]
# gluster peer probe server3
 
[root@server1:/root]
# gluster peer status
Number of Peers: 2
 
Hostname: server2.local
Uuid: 72a5f725-1436-46e9-8ae3-404e30fc5eac
State: Peer in Cluster (Connected)
 
Hostname: server3.local
Uuid: 4b2472bc-44a6-4e92-b3fa-6746c599c5d0
State: Peer in Cluster (Connected)

 

在任意一臺主機上建立 GlusterFS volume,volume 的類型是複製式(Replicated)卷:
[root@server1:/root]
# df -hT
Filesystem                                                               Type            Size  Used Avail Use% Mounted on
/dev/vda1                                                                ext4             40G  4.7G   33G  13% /
tmpfs                                                                    tmpfs           8.9G  3.9M  8.9G   1% /tmp
/dev/mapper/server1--vol-lianhua                                         ext4            4.6G   23M  4.3G   1% /mnt/bricks/lianhua
/dev/mapper/server1--vol-huasheng                                        ext4            4.6G   20M  4.3G   1% /mnt/bricks/huasheng
 
[root@server1:/root]
# gluster volume create lianhuasheng replica 3 server1:/mnt/bricks/lianhua server2:/mnt/bricks/lianhua server3:/mnt/bricks/lianhua force
volume create: lianhuasheng: success: please start the volume to access data
[root@server1:/root]
# gluster volume start lianhuasheng
[root@server1:/root]
# gluster volume info lianhuasheng
 
Volume Name: lianhuasheng
Type: Replicate
Volume ID: 895f24cb-cf45-4cba-b50d-55422aff0909
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: server1.local:/mnt/bricks/lianhua/brick
Brick2: server2.local:/mnt/bricks/lianhua/brick
Brick3: server3.local:/mnt/bricks/lianhua/brick
Options Reconfigured:
performance.client-io-threads: off
nfs.disable: on
transport.address-family: inet
cluster.server-quorum-type: none
cluster.quorum-type: auto
cluster.quorum-reads: true
cluster.consistent-metadata: on
server.allow-insecure: on
network.ping-timeout: 42
cluster.favorite-child-policy: mtime
cluster.heal-timeout: 60
cluster.server-quorum-ratio: 51%
 
[root@server1:/root]
# mount -t glusterfs server1:/lianhuasheng /mnt/lianhuasheng
 
[root@server1:/root]
# df -hT
/dev/vda1                                                                ext4             40G  4.7G   33G  13% /
tmpfs                                                                    tmpfs           8.9G  3.9M  8.9G   1% /tmp
/dev/mapper/server1--vol-lianhua                                         ext4            4.6G   23M  4.3G   1% /mnt/bricks/lianhua
/dev/mapper/server1--vol-huasheng                                        ext4            4.6G   20M  4.3G   1% /mnt/bricks/huasheng
server1.local:/lianhuasheng                                              fuse.glusterfs  4.6G   24M  4.2G   1% /mnt/lianhuasheng
能夠發現,複製式 volume 的大小等於每一個文件系統的大小,即,都是 4.6G。
 

GlusterFS volume 類型

上面建立的卷類型是複製式 Replicated 的,它的示意圖以下:
存儲文件到 volume 中,文件會同時放到每一個 Brick 中,Brick 便是主機池中每一個 server 的磁盤分區。因此,volume 的容量等於每一個 server 的磁盤分區容量。
 
除了 Replicated 模式外,還有 Distributed 分佈式卷,Striped 條帶式卷,Distributed Striped 分佈式條帶卷和 Distributed Replicated 分佈式複製卷模式。
 

Distributed 分佈式卷

存儲文件到 volume 中,文件會隨機存放到一臺 server 中的 Brick 中。因此,volume 的容量式每一個 Brick 的容量之和。
 

Striped 條帶式卷

存儲文件到 volume 中,文件被分紅數塊,存放到主機池中每臺 server 的 Brick 中。
 

Distributed Striped 分佈式條帶卷

本身看吧,不解釋了,前面幾種模式的排列組合。
 

Distributed Replicated 分佈式複製卷

本身看吧,不解釋了,前面幾種模式的排列組合。
 
5. client 端掛載 volume
使用 mount 命令將 volume 掛載到 client 的 mount point:
[root@client1:/root]
# mount -t glusterfs -o acl -o rw,backupvolfile-server=server1.local server1.local:/lianhuasheng /mnt/lianhuasheng
 
[root@client1:/root]
# df -hT
Filesystem                                                               Type            Size  Used Avail Use% Mounted on
/dev/vda1                                                                ext4             40G  4.7G   33G  13% /
tmpfs                                                                    tmpfs           8.9G  3.9M  8.9G   1% /tmp
server1.local:/lianhuasheng                                              fuse.glusterfs  4.6G  20M   4.2G   8% /mnt/lianhuasheng
 
在 client 寫個文件測試下:
[root@client1:/root]
# cd /mnt/lianhuasheng/
[root@client1:/mnt/lianhuasheng]
# ls
[root@client1:/mnt/lianhuasheng]
# touch GlusterFS.log
[root@client1:/mnt/lianhuasheng]
# ll -h
total 0K
-rw-r--r-- 1 root          root             0 Mar 28 22:38 GlusterFS.log
[root@client1:/mnt/lianhuasheng]
# ssh server1.local
[root@server1:/root]
# cd /mnt/lianhuasheng/
[root@server1:/mnt/lianhuasheng]
# ll -h
-rw-r--r-- 1 root          root             0 Mar 28 22:38 GlusterFS.log
 

GlusterFS 經常使用命令

# 查看 GlusterFS 全部 volume
gluster volume list
 
# 刪除 GlusterFS volume
gluster volume stop <volume_name>
gluster volume delete <volume_name>
 
# 卸載主機池中的主機
gluster peer detach <node_name>
 
# 添加主機到主機池
gluster peer probe <node_name>
 
# 建立 volume
gluster volume create <volume_name> replica <number of replica> <server_name>:<brick_name>
 
GlusterFS 官方文檔:  https://docs.gluster.org/en/latest/
 
 
 
(完)
相關文章
相關標籤/搜索