分佈式存儲-Glusterfs

分佈式文件系統GlusterFS

GlusterFS適合存儲大文件,小文件性能較差。生產上可使用GlusterFS+CinderOpenstack提供塊存儲,存儲虛擬機鏡像。node

7.1 GlusterFS概述

GlusterFSScale-Out存儲解決方案Gluster的核心,它是一個開源的分佈式文件系統,具備強大的橫向擴展能力,經過擴展可以支持數PB存儲容量和處理數千客戶端。GlusterFS藉助TCP/IPInfiniBand RDMA網絡將物理分佈的存儲資源彙集在一塊兒,使用單一全局命名空間來管理數據。GlusterFS基於可堆疊的用戶空間設計,可爲各類不一樣的數據負載提供優異的性能。linux

7.1.1 GlusterFS架構

 

7.1.2 GulsterFS特性

7.2 GlusterFS部署

7.2.1 環境說明

本文使用如下環境進行部署。git

主機名centos

IP地址服務器

角色網絡

備註架構

linux-node1.unixhot.com併發

192.168.56.11異步

ServerClienttcp

 

linux-node2.unixhot.com

192.168.56.12

ServerClient

 

7.2.2 GlusterFS安裝

目前Gluster的最新版本爲3.4.3版本,直接使用官方提供的repo進行安裝。

[root@linux-node2 ~]# yum install centos-release-gluster

[root@linux-node2 ~]# yum install glusterfs-server

 

驗證安裝

[root@linux-node1 yum.repos.d]# glusterfs -V

glusterfs 3.4.3 built on Apr  3 2014 16:02:46

Repository revision: git://git.gluster.com/glusterfs.git

Copyright (c) 2006-2013 Red Hat, Inc. http://www.redhat.com/

啓動Glusterd

[root@linux-node1 yum.repos.d]# /etc/init.d/glusterd start

請安裝並啓動linux-node2

7.3 Trusted Storage Pools建立

在開始建立ClusterFS卷以前,須要建立一個稱之爲Trusted Storage的池,是一個可信的網絡存儲服務器,能夠理解爲集羣。爲卷提供bricks。

gluster peer probe<主機名或者IP地址>,建議是IP地址,或者內網用DNS作主機名解析,或者在/etc/hosts作好綁定。

7.3.1 增長ServerPool

添加成員服務器到Poll中:例

[root@linux-node1 ~]# gluster peer probe 192.168.1.12

peer probe: success

7.3.2 Pool中刪除Server

刪除集羣中的成員服務器:例

[root@linux-node1 ~]# gluster peer detach linux-node2.unixhot.com

peer detach: success

注意不要添加本地的服務器。

[root@linux-node1 ~]# gluster peer probe 10.6.16.1

peer probe: success: on localhost not needed

[root@linux-node1 ~]# gluster peer probe 10.6.16.2

peer probe: success

7.3.3 查看Pool狀態

[root@linux-node1 ~]# gluster peer status

Number of Peers: 3

7.4 GlusterFS Volumes建立

GlusterFS的卷共有三種基本類型,能夠組合共7種類型,其中DistributedReplicatedStrped、爲基本類型。Distributed StripedDistributed ReplicatedDistributed Striped ReplicatedStriped Replicated。爲組合類型。

本文爲了測試7種卷類型,須要在各個服務器分別建立7個目錄。

[root@linux-node1 ~]# mkdir /data && cd /data && mkdir type{1,2,3,4,5,6,7}/exp{1,2,3,4,5,6,7} –p

建立Volumes使用如下命令進行:

gluster volume create NEW-VOLNAME [stripe COUNT | replica COUNT]

[transport [tcp | rdma | tcp,rdma]] NEW-BRICK1 NEW-BRICK2 NEW-BRICK3...

7.4.1 建立分佈式卷

分佈式卷架構示意圖:

[root@linux-node1 data]# gluster volume create test1-volume 10.6.16.1:/data/type1/exp1 10.6.16.2:/data/type1/exp1 10.6.11.31:/data/type1/exp1 10.6.11.32:/data/type1/exp1 force

volume create: test1-volume: success: please start the volume to access data

[root@linux-node1 data]# gluster volume info test1-volume

 

Volume Name: test1-volume

Type: Distribute

Volume ID: 1ed9c3fe-3bc7-4525-b194-219a8e85f7fb

Status: Created

Number of Bricks: 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type1/exp1

Brick2: 10.6.16.2:/data/type1/exp1

Brick3: 10.6.11.31:/data/type1/exp1

Brick4: 10.6.11.32:/data/type1/exp1

7.4.2 建立複製卷

複製卷的架構示意圖。

[root@linux-node1 data]# gluster volume create test2-volume replica 4 10.6.16.1:/data/type2/exp1 10.6.16.2:/data/type2/exp1 10.6.11.31:/data/type2/exp1 10.6.11.32:/data/type2/exp1 force

volume create: test2-volume: success: please start the volume to access data

[root@linux-node1 data]# gluster volume info test2-volume

 

Volume Name: test2-volume

Type: Replicate

Volume ID: 035b6768-2d07-4530-aa91-38571cacc90c

Status: Created

Number of Bricks: 1 x 4 = 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type2/exp1

Brick2: 10.6.16.2:/data/type2/exp1

Brick3: 10.6.11.31:/data/type2/exp1

Brick4: 10.6.11.32:/data/type2/exp1

7.4.3 建立條帶卷

條帶卷架構示意圖:

[root@linux-node1 ~]# gluster volume create test3-volume stripe 4 10.6.16.1:/data/type3/exp1 10.6.16.2:/data/type3/exp1 10.6.11.31:/data/type3/exp1 10.6.11.32:/data/type3/exp1 force

volume create: test3-volume: success: please start the volume to access data

[root@linux-node1 ~]# gluster volume info test3-volume

 

Volume Name: test3-volume

Type: Stripe

Volume ID: 6d754a08-c0e9-4fb8-bc8e-54c8f1f3cbe4

Status: Created

Number of Bricks: 1 x 4 = 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type3/exp1

Brick2: 10.6.16.2:/data/type3/exp1

Brick3: 10.6.11.31:/data/type3/exp1

Brick4: 10.6.11.32:/data/type3/exp1

7.4.4 建立分佈式+條帶卷

分佈式條帶卷架構示意圖:

 

[root@linux-node1 ~]# gluster volume create test4-volume stripe 2 10.6.16.1:/data/type4/exp1 10.6.16.2:/data/type4/exp1 10.6.11.31:/data/type4/exp1 10.6.11.32:/data/type4/exp1 force

volume create: test4-volume: success: please start the volume to access data

[root@linux-node1 ~]# gluster volume info test4-volume

 

Volume Name: test4-volume

Type: Distributed-Stripe

Volume ID: 2b14574c-79c6-4329-91b9-8dc036969f2f

Status: Created

Number of Bricks: 2 x 2 = 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type4/exp1

Brick2: 10.6.16.2:/data/type4/exp1

Brick3: 10.6.11.31:/data/type4/exp1

Brick4: 10.6.11.32:/data/type4/exp1

7.4.5 建立分佈式+複製卷

分佈式複製卷架構示意圖:

 

[root@linux-node1 ~]# gluster volume create test5-volume replica 2 10.6.16.1:/data/type5/exp1 10.6.16.2:/data/type5/exp1 10.6.11.31:/data/type5/exp1 10.6.11.32:/data/type5/exp1 force

volume create: test5-volume: success: please start the volume to access data

[root@linux-node1 ~]# gluster volume info test5-volume

 

Volume Name: test5-volume

Type: Distributed-Replicate

Volume ID: fc94f6f7-a3e4-471b-82b0-4e74d5a529b9

Status: Created

Number of Bricks: 2 x 2 = 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type5/exp1

Brick2: 10.6.16.2:/data/type5/exp1

Brick3: 10.6.11.31:/data/type5/exp1

Brick4: 10.6.11.32:/data/type5/exp1

7.4.6 建立分佈式+條帶+複製卷

[root@linux-node1 ~]# gluster volume create test6-volume stripe 2 replica 2 10.6.16.1:/data/type6/exp1 10.6.16.1:/data/type6/exp2 10.6.16.2:/data/type6/exp1 10.6.16.2:/data/type6/exp2 10.6.11.31:/data/type6/exp1 10.6.11.31:/data/type6/exp2 10.6.11.32:/data/type6/exp1 10.6.11.32:/data/type6/exp2 force

Multiple bricks of a replicate volume are present on the same server. This setup is not optimal.

Do you still want to continue creating the volume?  (y/n) y

volume create: test6-volume: success: please start the volume to access data

[root@linux-node1 ~]# gluster volume info test6-volume

 

Volume Name: test6-volume

Type: Distributed-Striped-Replicate

Volume ID: e6d681e3-b006-41ce-a466-c4c16cf03cce

Status: Created

Number of Bricks: 2 x 2 x 2 = 8

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type6/exp1

Brick2: 10.6.16.1:/data/type6/exp2

Brick3: 10.6.16.2:/data/type6/exp1

Brick4: 10.6.16.2:/data/type6/exp2

Brick5: 10.6.11.31:/data/type6/exp1

Brick6: 10.6.11.31:/data/type6/exp2

Brick7: 10.6.11.32:/data/type6/exp1

Brick8: 10.6.11.32:/data/type6/exp2

7.4.7 建立條帶+複製卷

 

[root@linux-node1 ~]# gluster volume create test7-volume stripe 2 replica 2 10.6.16.1:/data/type7/exp1 10.6.16.2:/data/type7/exp1 10.6.11.31:/data/type7/exp1 10.6.11.32:/data/type7/exp1 force

volume create: test7-volume: success: please start the volume to access data

[root@linux-node1 ~]# gluster volume info test7-volume

 

Volume Name: test7-volume

Type: Striped-Replicate

Volume ID: 3f007e9e-3c42-4dd3-935e-60da041659d1

Status: Created

Number of Bricks: 1 x 2 x 2 = 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type7/exp1

Brick2: 10.6.16.2:/data/type7/exp1

Brick3: 10.6.11.31:/data/type7/exp1

Brick4: 10.6.11.32:/data/type7/exp1

7.4.8 啓動卷

在開始掛載使用卷以前,必需先啓動卷。使用如下命令啓動卷。

[root@linux-node3 yum.repos.d]# gluster volume start

Usage: volume start <VOLNAME> [force]

7.5 客戶端掛載

GlusterFS支持三種客戶端類型。Gluster Native ClientNFSCIFS。官方推薦使用Native Client,可使用GlusterFS的所有功能。

7.5.1 Gluster Native Client

Gluster Native Client是基於FUSE的,因此須要保證客戶端安裝了FUSE。這個是官方推薦的客戶端,支持高併發和高效的寫性能。

[root@linux-node4 ~]# yum -y install glusterfs-client

[root@linux-node4 ~]# mkdir /mnt/glusterfs

[root@linux-node4 ~]# mount.glusterfs 10.6.16.1:/test1-volume /mnt/glusterfs/

[root@linux-node4 ~]# mount

/dev/sda3 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

10.6.16.1:/test1-volume on /mnt/glusterfs type fuse.glusterfs (rw,default_permissions,allow_other,max_read=131072)

掛載參數

當使用mount –t glusterfs的使用,能夠執行相關的參數以下:

backupvolfile-server=server-name

volfile-max-fetch-attempts=number of attempts

log-level=loglevel

log-file=logfile

transport=transport-type

direct-io-mode=[enable|disable]

For example:

 

 # mount -t glusterfs -o backupvolfile-server=volfile_server2 --volfile-max-fetch-attempts=2 log-level=WARNING,log-file=/var/log/gluster.log server1:/test-volume /mnt/glusterfs

 

If  backupvolfile-server  option is added while mounting fuse client, when the first volfile server fails, then the server specified in  backupvolfile-server  option is used as volfile server to mount the client.

 

In  --volfile-max-fetch-attempts=X  option, specify the number of attempts to fetch volume files while mounting a volume. This option is useful when you mount a server with multiple IP addresses or when round-robin DNS is configured for the server-name..

7.5.2 NFS 掛載

 

NFS默認是使用的UDP進行通訊,因爲GlusterFS不支持UDP。因此須要設置爲TCP的方式掛載。

mount -o mountproto=tcp -t nfs server1:/test-volume /mnt/glusterfs

 

 

 

7.5.3 CIFS掛載

 

 

 

7.5.4 測試各個卷類型

 

 

 

7.6 管理GlusterFS卷

7.6.1 中止卷

[root@linux-node1 ~]# gluster volume stop test1-volume

7.6.2 刪除卷

[root@linux-node1 ~]# gluster volume delete test1-volume

7.6.3 擴展卷

GlusterFS支持在線進行卷的擴展。

[root@linux-node3 data]# gluster peer probe 10.6.11.21

peer probe: success

[root@linux-node3 data]# gluster volume add-brick test1-volume 10.6.11.21:/data/type1/exp1 force

volume add-brick: success

[root@linux-node3 data]# gluster volume info test1-volume

 

Volume Name: test1-volume

Type: Distribute

Volume ID: 1ed9c3fe-3bc7-4525-b194-219a8e85f7fb

Status: Stopped

Number of Bricks: 5

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type1/exp1

Brick2: 10.6.16.2:/data/type1/exp1

Brick3: 10.6.11.31:/data/type1/exp1

Brick4: 10.6.11.32:/data/type1/exp1

Brick5: 10.6.11.21:/data/type1/exp1

7.6.4 收縮卷

收縮卷和擴展卷類似據以Brick爲單位。

[root@linux-node3 data]# gluster volume remove-brick test1-volume 10.6.11.21:/data/type1/exp1 start

volume remove-brick start: success

ID: 15764d05-5675-46b5-8467-b9eb12570e61

[root@linux-node3 data]# gluster volume remove-brick test1-volume 10.6.11.21:/data/type1/exp1 status

[root@linux-node3 data]# gluster volume remove-brick test1-volume 10.6.11.21:/data/type1/exp1 commit

Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y

volume remove-brick commit: success

[root@linux-node3 data]# gluster volume info test1-volume

 

Volume Name: test1-volume

Type: Distribute

Volume ID: 1ed9c3fe-3bc7-4525-b194-219a8e85f7fb

Status: Started

Number of Bricks: 4

Transport-type: tcp

Bricks:

Brick1: 10.6.16.1:/data/type1/exp1

Brick2: 10.6.16.2:/data/type1/exp1

Brick3: 10.6.11.31:/data/type1/exp1

Brick4: 10.6.11.32:/data/type1/exp1

7.6.5 遷移卷

進行卷遷移前須要確保遷移目標已經加入集羣。或者遷移的Brick目錄存在。遷移卷能夠執行暫停和停止的操做。

[root@linux-node3 data]# gluster volume replace-brick test1-volume 10.6.16.1:/data/type1/exp1 10.6.16.1:/data/type1/exp2 commit force

All replace-brick commands except commit force are deprecated. Do you want to continue? (y/n) y

暫停遷移

gluster volume replace-brick test1-volume 10.6.16.1:/data/type1/exp1 10.6.16.1:/data/type1/exp2 pause

停止遷移

gluster volume replace-brick test1-volume 10.6.16.1:/data/type1/exp1 10.6.16.1:/data/type1/exp2 abort

 

 

 

 

2.3.3.3替換Brick

 

    # gluster volume replace-brick VOLNAME BRICKNEW-BRICK start/pause/abort/status/commit

 

    #gluster volume replace-brick dht_vol server0:/mnt/sdb1 server0:/mnt/sdc1 start

 

//如上,執行replcace-brick卷替換啓動命令,使用start啓動命令後,開始將原始Brick的數據遷移到即將須要替換的Brick上。

 

    #gluster volume replace-brick dht_vol server0:/mnt/sdb1 server0:/mnt/sdc1 status

 

//在數據遷移的過程當中,能夠查看替換任務是否完成。

 

    #gluster volume replace-brick dht_vol server0:/mnt/sdb1 server0:/mnt/sdc1 abort

 

//在數據遷移的過程當中,能夠執行abort命令終止Brick替換。

 

    #gluster volume replace-brick dht_vol server0:/mnt/sdb1 server0:/mnt/sdc1 commit

 

//在數據遷移結束以後,執行commit命令結束任務,則進行Brick替換。使用volume info命令能夠查看到Brick已經被替換。

 

1.1.1 系統配額

開啓/關閉系統配額

 

    # gluster volume quota VOLNAME enable/disable

 

//在使用系統配額功能時,須要使用enable將其開啓;disable爲關閉配額功能命令。

設置(重置)目錄配額

 

    # gluster volume quota VOLNAME limit-usage /directory limit-value

    #gluster volume quota dht_vol limit-usage /quota 10GB

//如上,設置dht_vol卷下的quota子目錄的限額爲10GB

 

PS:這個目錄是以系統掛載目錄爲根目錄」/,因此/quota即客戶端掛載目錄下的子目錄quota

配額查看

    # gluster volume quota VOLNAME list

    # gluster volume quota VOLNAME list /directory name

 

//可使用如上兩個命令進行系統卷的配額查看,第一個命令查看目的卷的全部配額設置,第二個命令則是執行目錄進行查看。

 

//能夠顯示配額大小及當前使用容量,若無使用容量(最小0KB)則說明設置的目錄多是錯誤的(不存在)

地域複製(geo-replication)

 

    # gluster volume geo-replication MASTER SLAVE start/status/stop

 

地域複製是系統提供的災備功能,可以將系統的所有數據進行異步的增量備份到另外的磁盤中。

 

    #gluster volume geo-replication dht_vol 192.168.2.104:/mnt/sdb1 start

 

//如上,開始執行將dht_vol卷的全部內容備份到2.104下的/mnt/sdb1中的task,須要注意的是,這個備份目標不能是系統中的Brick

 

1.1.2  I/O信息查看

 Profile Command 提供接口查看一個卷中的每個brickIO信息。

    #gluster volume profile VOLNAME start

//啓動profiling,以後則能夠進行IO信息查看

    #gluster volume profile VOLNAME info

//查看IO信息,能夠查看到每個BrickIO信息

    # gluster volume profile VOLNAME stop

//查看結束以後關閉profiling功能

 

 

1.1.3 Top監控

Top command 容許你查看bricks的性能例如:read, write, file open calls, file read calls, file write calls, directory open calls, and directory real calls

全部的查看均可以設置top數,默認100

    # gluster volume top VOLNAME open [brick BRICK-NAME] [list-cnt cnt]

//查看打開的fd

    #gluster volume top VOLNAME read [brick BRICK-NAME] [list-cnt cnt]

//查看調用次數最多的讀調用

    #gluster volume top VOLNAME write [brick BRICK-NAME] [list-cnt cnt]

 

//查看調用次數最多的寫調用

    # gluster volume top VOLNAME opendir [brick BRICK-NAME] [list-cnt cnt]

    # gluster volume top VOLNAME readdir [brick BRICK-NAME] [list-cnt cnt]

 

//查看次數最多的目錄調用

    # gluster volume top VOLNAME read-perf [bs blk-size count count] [brick BRICK-NAME] [list-cnt cnt]

//查看每一個Brick的讀性能

    # gluster volume top VOLNAME write-perf [bs blk-size count count] [brick BRICK-NAME] [list-cnt cnt]

//查看每一個Brick的寫性能

相關文章
相關標籤/搜索