二、GlusterFS體系結構
注:本文及本系列文章均是翻譯自GlusterFS doc官方英文文檔,除此之外又根據自己翻閱的其它資源對原文檔做了部分補充。
1. 邏輯存儲卷的幾種類型
在GlusterFS中邏輯卷(volume)是一組存儲塊(bricks)的集合,GlusterFS可以支援多種類型的邏輯卷,以實作不同的資料保護級别和存取性能。
1.1 分布存儲卷(Distributed Glusterfs Volume)
分布存儲是Glusterfs 預設使用的存儲卷類型。檔案會被分布得存儲到邏輯卷中的各個存儲塊上去。以兩個存儲塊的邏輯卷為例,檔案file1可能被存放在brick1或brick2中,但不會在每個塊中都存一份。分布存儲不提供資料備援保護。
建立分布存儲的指令格式為:
#gluster volume create NEW-VOLNAME [transport [tcp | rdma | tcp,rdma]] NEW-BRICK...
樣例:
#gluster volume create test-volume server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
Creation of test-volume has been successful Please start the volume to access data
檢視邏輯卷的狀态:
#gluster volume info
Volume Name: test-volume
Type: Distribute
Status: Created
Number of Bricks: 4
Transport-type: tcp
Bricks: Brick1: server1:/exp1 Brick2: server2:/exp2 Brick3: server3:/exp3 Brick4: server4:/exp4
1.2 鏡像存儲卷(Replicated Glusterfs Volume)
在鏡像存儲邏輯卷中,資料至少會在不同的brick上被存儲兩份,具體采取存儲幾份的備援資料則可以在建立鏡像存儲卷時予以設定。鏡像存儲可以有效得預防存儲塊損壞可能引發的資料丢失的風險。
建立鏡像存儲的指令格式為:
#gluster volume create NEW-VOLNAME [replica COUNT] [transport [tcp | rdma | tcp,rdma]] NEW-BRICK...
樣例:
# gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2
Creation of test-volume has been successful Please start the volume to access data
關于鏡像存儲卷的仲裁盤配置:
# gluster volume create <VOLNAME> replica 3 arbiter 1 host1:brick1 host2:brick2 host3:brick3
在鏡像存儲卷中使用一個獨立的brick作為仲裁盤,是為了避免發生腦裂後無法認定資料一緻性的問題。
注:對于任何涉及到鏡像存儲的邏輯卷,在建立時都不能把同一個主機節點上的兩個brick設定到同一組鏡像複制關系中。即使嘗試這樣做,也會建立失敗。
1.3 分布式鏡像存儲卷(Distributed Replicated Glusterfs Volume)
在這種邏輯卷中,檔案是跨鏡像存儲塊的集合(replicated sets of bricks)進行分布式存儲的,即檔案可能被存儲在某一個鏡像存儲塊集合中,但不會同時存儲到多個集合。而在一個鏡像存儲塊的集合内,檔案是在每個存儲塊(brick)上各存一份。
在我們使用指令建立分布式鏡像存儲卷時,需要特别注意在設定需要加入邏輯卷中的brick時,每個brick的順序會決定它與哪一個brick結成鏡像複制的關系。Brick會按照從前至後,選擇與自己鄰近的brick結成鏡像複制的關系。例如,我們有8個bricks,設定的資料複制份數為2,那麼前兩個brick就會成為互為鏡像的關系,緊接着的後兩個結為鏡像關系,以此類推。
建立分布式鏡像存儲的指令格式為:
# gluster volume create NEW-VOLNAME [replica COUNT] [transport [tcp | rdma | tcp,rdma]] NEW-BRICK...
樣例:
# gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
Creation of test-volume has been successful Please start the volume to access data
我們可以看到,鏡像存儲邏輯卷和分布式鏡像存儲邏輯卷,它們的建立指令是相同的。不同點在于,在設定資料複制份數和指定加入到卷中的bricks時,如果剛好隻夠一個鏡像存儲塊集合則是鏡像存儲卷,如果可以組成多個鏡像存儲塊集合,那麼自然就成為分布式鏡像存儲卷。
1.4 分片式存儲卷(Striped Glusterfs Volume)
在分片式存儲卷中,一個檔案會被切分成多份,數量等于brick的數量,然後每個brick中存一份。這種方式不提供資料備援保護。
建立分片式存儲的指令格式為:
#gluster volume create NEW-VOLNAME [stripe COUNT] [transport [tcp | dma | tcp,rdma]] NEW-BRICK...
樣例:
# gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2
Creation of test-volume has been successfulPlease start the volume to access data
1.5 分布式分片存儲卷(Distributed Striped Glusterfs Volume)
這種方式實際上是在分片式存儲卷的基礎上做的擴充,即根據你設定的分片參數(一個檔案分成幾片)和你為邏輯卷加入的bricks數量可以組成多個分片存儲塊集合時,自然就成為了分布式分片存儲卷。每個分片存儲塊集合中存儲的的資料是不同的。
建立分布式分片存儲的指令格式為:
#gluster volume create NEW-VOLNAME [stripe COUNT] [transport [tcp | rdma | tcp,rdma]] NEW-BRICK...
樣例,以下是一個包含8個存儲伺服器在内的分布式分片存儲邏輯卷:
# gluster volume create test-volume stripe 4 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8
Creation of test-volume has been successful Please start the volume to access data.
1.6 分布式分片及鏡像複制存儲卷(Distributed Striped Replicated Volume)
這種方式建立的存儲卷會将資料分片後,分布式地跨多個鏡像bricks集合來存儲。用途為解決大資料的、高并發的、性能敏感的資料存儲和使用場景,例如Map Reduce負載。
# gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8
Creation of test-volume has been successful Please start the volume to access data.
1.7 分片及鏡像複制存儲卷(Striped Replicated Volume)
# gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
Creation of test-volume has been successful Please start the volume to access data.
或是如下:
# gluster volume create test-volume stripe 3 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6
Creation of test-volume has been successful Please start the volume to access data.
同樣地,分片及鏡像複制存儲卷也是用于處理大資料的、高并發的、性能敏感的業務資料。目前看,這種存儲卷僅适合用于Map Reduce負載。
1.8 關于離散存儲卷(Dispersed Volume)
離散存儲卷是基于一種前向糾錯碼技術來實作的,它會對存儲進來的資料進行切分,然後附加一些部分備援的糾錯碼。這種類型的存儲卷要以在實作可接受的資料可靠性的條件下,最大化得避免空間的浪費。
# gluster volume create test-volume disperse 4 server{1..4}:/bricks/test-volume There isn't an optimal redundancy value for this configuration. Do you want to create the volume with redundancy 1 ? (y/n)
又例如:
# gluster volume create test-volume disperse 6 server{1..6}:/bricks/test-volume The optimal redundancy for this configuration is 2. Do you want to create the volume with this value ? (y/n)
其中disperse參數指定的是參與到存儲備援資料的bricks數量。詳情可參見:
http://gluster.readthedocs.org/en/latest/Administrator%20Guide/Setting%20Up%20Volumes/#creating-dispersed-volumes
相應地,你還可以建立分布式的離散存儲卷(Distributed Dispersed Volume)。
2. FUSE使用者空間檔案系統
GlusterFS是一個基于使用者空間實作的檔案系統。其中FUSE作為核心子產品,用于實作核心VFS和非特權的應用使用者的互動。
3. 轉換器
3.1 什麼是轉換器
n 轉換器把來自使用者的請求轉換成對存儲的通路請求。
n 轉換器可以在中途修改使用者請求,包括路徑、辨別甚至資料。
n 轉換器可以阻塞或過濾通路請求。
n 轉換器可以發起新請求。
3.2 轉換器怎麼工作
n 共享對象(Shared Objects)
n 動态加載(Dynamically loaded according to 'volfile')
3.3 轉換器的類型
Translator Type | Functional Purpose |
Storage | Lowest level translator, stores and accesses data from local file system. |
Debug | Provide interface and statistics for errors and debugging. |
Cluster | Handle distribution and replication of data as it relates to writing to and reading from bricks & nodes. |
Encryption | Extension translators for on-the-fly encryption/decryption of stored data. |
Protocol | Extension translators for client/server communication protocols. |
Performance | Tuning translators to adjust for workload and I/O profiles. |
Bindings | Add extensibility, e.g. The Python interface written by Jeff Darcy to extend API interaction with GlusterFS. |
System | System access translators, e.g. Interfacing with file system access control. |
Scheduler | I/O schedulers that determine how to distribute new write operations across clustered systems. |
Features | Add additional features such as Quotas, Filters, Locks, etc. |
3.4 轉換器的通用配置
3.5 關于DHT轉換器
DHT是GlusterFS整合資源以提供跨多節點的存儲服務的核心。它提供的是一個路由功能,為每個檔案找到準确的存儲位置。DHT使用一緻性哈希的算法來管理資訊。在每個brick上都設定了一個長度不大于32bit的哈希值空間,覆寫到了這個存儲塊的整個存儲位址範圍。存儲在brick上的每個檔案的檔案名的哈希值也同樣存儲在這個哈希空間裡。當你通路一個檔案時,DHT轉換器會根據你提供的檔案名和每個brick的哈希空間中存儲的值進行比對,來發現和找到檔案具體的存儲位址。
DHT在縮小尋找的哈希範圍時使用了一個檔案夾的擴充屬性,是以DHT是對檔案夾敏感的。如果一個brick丢失了,那麼就會在哈希空間中留下一個“空洞”,而更糟糕的是如果在下線一個brick時重新計算了存儲的哈希範圍,一部分新的範圍可能會和存儲在那個brick上的哈希範圍(現在已過期)重疊。這也會給找到檔案的存儲位址帶來麻煩。
3.6 自動檔案複制轉換器(AFR(Automatic File Replication) Translator)
在GlusterFS中負責實作跨bricks的資料複制。提供資料複制一緻性的維護,提供資料恢複服務(當有一個brick損壞,而至少還有一個brick上有正确的資料),以及為新資料提供讀檔案、檔案狀态和檔案夾資訊等服務。
3.7 Geo複制(Geo-Replication)
Geo-replication 是面向廣域網環境提供的GlusterFS資料複制解決方案,主要是基于整個的邏輯存儲卷進行資料的複制,而不像AFR轉換器是面向同一個叢集環境内的複制技術。Geo-replication 使用主從模式,主節點需要使用一個GlusterFS邏輯卷,從節點可以是一個本地目錄或一個GlusterFS邏輯卷。主從之間通過SSH隧道進行通信。Geo-replication 可以基于區域網路、廣域網和網際網路環境,提供增量的資料複制功能。
Geo-replication over LAN:
Geo-replication over WAN:
Geo-replication over Internet:
Multi-site cascading Geo-replication:
異步複制資料的過程主要是兩個方面的内容:
n 偵測檔案變化
Entry - create(), mkdir(), mknod(), symlink(), link(), rename(), unlink(), rmdir()
Data - write(), writev(), truncate(), ftruncate()
Meta - setattr(), fsetattr(), setxattr(), fsetxattr(), removexattr(), fremovexattr()
n 複制
主要是使用rsync進行資料傳輸。
4. GlusterFS工作機制
4.1 當在一個主機上安裝了GlusterFS服務後,會自動建立一個gluster management背景程序。這個程序需要在存儲叢集中的每個節點上運作。
4.2 在啟動glusterd程序後,接需來需要建立一個包含了全部存儲節點主機的可信任主機池(TSP)。
4.3 現在,可以在每個存儲主機節點上開始建立存儲塊bricks了。我們可以把來自TSP的bricks按照一定規則形成我們需要的邏輯存儲卷。
4.4 在建立了邏輯存儲卷後,在每個被納入到邏輯卷中的brick節點上都會啟動一個glusterfsd程序。同時,在/var/lib/glusterd/vols目錄下會生成相關的配置檔案(vol files),這些配置檔案中包含關于目前brick在邏輯卷中的較長的描述資訊。此外還會在該路徑下建立一個用戶端程序需要使用到的配置檔案。
到此為止,我們的邏輯卷已經可以挂接使用了。挂接指令格式如下:
#mount.glusterfs `<IP or hostname>`:`<volume_name>` `<mount_point>
注:可以使用在可信任存儲池中建立了這個邏輯卷的任一個主機節點的IP或主機名。
4.5 當我們在一個客戶機上挂接了邏輯卷後,客戶機上的glusterfs程序開始與服務端的glusterd程序通信。Glusterd服務端程序向客戶機發送一個配置檔案(vol file),配置檔案中包含了客戶機端需要使用的轉換器清單資訊和邏輯卷中每個brick的資訊。