GlusterFS學習手記(轉自Tim的Blog)


對於分佈式存儲已經被越來越多的公司所應用,對於這方面的學習自然不能忽略,之前就也看過相關的內容,像紅帽的GFS,google的googlefs,開源的現在也越來越多,像Fastdfs,ZFS,Lustre,Hadoop,GlusterFS。
大概的也都接觸了一下,Fastdfs號稱小巧,速度快佔用資源小,但據我瞭解他是提供api來進行操作的,而目前我還是希望可以像NFS一樣,直接mount來使用,並且提供高的可用性,和文件的容錯功能,一路掃下來,瞄準了glusterfs。
Glusterfs是一個具有可以擴展到幾個PB數量級的集羣文件系統。它可以把多個不同類型的存儲塊通過Infiniband RDMA或者TCP/IP匯聚成一個大的並行網絡文件系統。
http://www.gluster.org/可以瞭解到更多並可以下載到最新的安裝包,glusterfs使用了fuse,fuse可以到http://fuse.sourceforge.net/進行下載

首先是fuse的安�
wget http://ftp.zresearch.com/pub/gluster/glusterfs/fuse/fuse-2.7.4glfs11.tar.gz
tar zxvf fuse-2.7.4glfs11.tar.gz
cd fuse-2.7.4glfs11
./configure –enable-dependency-tracking –enable-lib –enable-util –enable-kernel-module –prefix=/usr
make
make install

如果沒有什麼錯誤,就是安裝完畢了,接下來是glusterfs的安�
wget http://ftp.gluster.com/pub/gluster/glusterfs/2.0/2.0.1/glusterfs-2.0.1.tar.gz
tar -zxvf glusterfs-2.0.1.tar.gz
cd glusterfs-2.0.1
[wget http://ftp.gluster.com/pub/gluster/gluster-platform/3.0/3.0.3/glusterfs-client/3.0.2/glusterfs-3.0.2.tar.gz
tar zxvf glusterfs-3.0.2.tar.gz
cd glusterfs-3.0.2]注:gluster3不支持unify
./configure –prefix=
make
make install

如果沒有報錯就是安裝完畢了
然後執行ldconfig
執行完畢後執行
glusterfs –version 可以看到

glusterfs 2.0.0rc1 built on Feb 10 2009 11:39:40
Repository revision: glusterfs–mainline–3.0–patch-844
Copyright (c) 2006, 2007, 2008 Z RESEARCH Inc. <http://www.zresearch.com/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GlusterFS under the terms of the GNU General Public License.

說明glusterfs已經正確安裝完畢了

下面來做個簡單的配置,類似NFS的配置

環境:vmware6.0 模擬兩個linux,ip分別Server:192.168.0.160 client:192.168.0.161,軟件都已經安裝完畢

server端的配置

先建立需要share的文件夾
mkdir -p /home/dir1
chmod 1777 /home/dir1
然後建立配置文件
vi /etc/glusterfs/server.vol
### file: server-volume.vol.sample

#####################################
### GlusterFS Server Volume File ##
#####################################

#### CONFIG FILE RULES:
### “#” is comment character.
### – Config file is case sensitive
### – Options within a volume block can be in any order.
### – Spaces or tabs are used as delimitter within a line.
### – Multiple values to options will be : delimitted.
### – Each option should end within a line.
### – Missing or commented fields will assume default values.
### – Blank/commented lines are allowed.
### – Sub-volumes should already be defined above before referring.

### Export volume “brick” with the contents of “/home/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /home/dir1 # Export this directory
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.0.160 # Default is to listen on all interfaces
option listen-port 6996 # Default is 6996
subvolumes brick
option auth.addr.brick.allow * # Allow access to “brick” volume
end-volume

client端的配置

modprobe -i fuse
vi /usr/local/etc/glusterfs/client.vol

### file: client-volume.vol.sample

#####################################
### GlusterFS Client Volume File ##
#####################################

#### CONFIG FILE RULES:
### “#” is comment character.
### – Config file is case sensitive
### – Options within a volume block can be in any order.
### – Spaces or tabs are used as delimitter within a line.
### – Each option should end within a line.
### – Missing or commented fields will assume default values.
### – Blank/commented lines are allowed.
### – Sub-volumes should already be defined above before referring.

### Add client feature and attach to remote subvolume
volume client0
type protocol/client
option transport-type tcp/client
option remote-host 192.168.0.160 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume brick # name of the remote volume
end-volume

這樣兩臺機器就都配置完畢了

首先在server上啓動服務
glusterfsd -f /usr/local/etc/glusterfs/server.vol

[root@contos5-1-1 etc]# ps ax|grep -v grep |grep gluster
2028 ? Ssl 0:00 glusterfsd -f ./server.vol

看到這個證明服務器端就啓動了

接下來是client端的啓動
glusterfs -l /tmp/glustfs.log -f /etc/glusterfs/client.vol /mnt/

[root@contos5-1-4 glusterfs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.1G 2.5G 4.3G 37% /
/dev/sda1 190M 11M 170M 7% /boot
tmpfs 125M 0 125M 0% /dev/shm
glusterfs 7.1G 2.9G 3.9G 43% /mnt

看到這個了,就說明client端mount正常,如果沒有請查看/tmp/glusterfs.log文件.我剛開始在df的時候出現“/mnt”: 傳輸端點尚未連接 的錯誤,umount /mnt然後再掛glustergfs就可以了。

到此,一個簡單的1存儲1客戶端的配置就完成了,這篇文章僅僅是個開始,glusterfs還有很多的功能,我也會在以後的時間進行深入的研究,希望有相同興趣的朋友一起討論。

上 次的學習已經對glusterfs這個系統有了初步的認識,這次繼續,上次只是簡單的實現了一個類似NFS的配置,但這個並不是glusterfs出現的 主要目的,而且也不是我們應用glusterfs的主要目的,我們要是實現的是分佈式存儲,另外一個最簡單的想法就是,如何能把多臺server目前空餘 的硬盤空間利用起來。這其實就是glusterfs最主要的功能之一,多存儲空間的聚合。

實現目的:3存儲節點,1clinet,3存儲節點使用round-robin的方式進行存儲
試驗環境:vmware6.0 linux2個,分別server:192.168.211.128 client:192.168.211.129

軟件安裝這裏不在概述
先來看看server端的配置
首先在home目錄下建立4個用於共享出來的文件夾,其中一個是用於namespace的

mkdir -p /home/{dir1,dir2,dir3,dir4}
chmod 1777 /home/dir[1-4]

然後看下3個glusterfs-server的配置文件
cat /etc/glusterfs/server1.vol

### Export volume “brick” with the contents of “/home/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /home/dir1 # Export this directory
end-volume

 

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.211.128 # Default is to listen on all interfaces
option listen-port 6996 # Default is 6996
subvolumes brick
option auth.addr.brick.allow * # Allow access to “brick” volume
end-volume

cat /etc/glusterfs/server2.vol

### Export volume “brick” with the contents of “/home/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /home/dir2 # Export this directory
end-volume

 

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.211.128 # Default is to listen on all interfaces
option listen-port 6997 # Default is 6996
subvolumes brick
option auth.addr.brick.allow * # Allow access to “brick” volume
end-volume

cat /etc/glusterfs/server3.vol

### Export volume “brick” with the contents of “/home/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /home/dir3 # Export this directory
end-volume

 

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.211.128 # Default is to listen on all interfaces
option listen-port 6998 # Default is 6996
subvolumes brick
option auth.addr.brick.allow * # Allow access to “brick” volume
end-volume

cat /etc/glusterfs/server4.vol

### Export volume “brick” with the contents of “/home/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /home/dir4 # Export this directory
end-volume

 

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.211.128 # Default is to listen on all interfaces
option listen-port 6999 # Default is 6996
subvolumes brick
option auth.addr.brick.allow * # Allow access to “brick” volume
end-volume

接下來看下client的配置
cat /etc/glusterfs/client.vol

### Add client feature and attach to remote subvolume
volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume brick # name of the remote volume
end-volume

 

volume client2
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128
option remote-port 6997
option remote-subvolume brick
end-volume

volume client3
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128
option remote-port 6998
option remote-subvolume brick
end-volume

volume namespacenode
type protocol/client
option transport-type tcp
option remote-host 192.168.211.128
option remote-port 6999
option remote-subvolume brick
end-volume

volume bricks
type cluster/unify
subvolumes client1 client2 client3
option scheduler rr
option namespace namespcenode
end-volume

### Add writeback feature
volume writeback
type performance/write-behind
option block-size 1MB
option cache-size 2MB
option flush-behind off
subvolumes bricks
end-volume

### Add readahead feature
volume readahead
type performance/read-ahead
option page-size 1MB # unit in bytes
option page-count 2 # cache per file = (page-count x page-size)
subvolumes writeback
end-volume

這樣所有準備工作就做完了,接下來啓動服務
server端

glusterfsd -f /etc/glusterfs/server1.vol
glusterfsd -f /etc/glusterfs/server2.vol
glusterfsd -f /etc/glusterfs/server3.vol
glusterfsd -f /etc/glusterfs/server4.vol
如果啓動沒有報錯,可以執行
ps fax|grep gluseterfs進行查看
1762 tty6 Ss+ 0:00 /sbin/mingetty tty6
1858 ? Ssl 0:00 glusterfsd -f ./server1.vol
1861 ? Ssl 0:00 glusterfsd -f ./server2.vol
1864 ? Ssl 0:00 glusterfsd -f ./server3.vol
1867 ? Ssl 0:00 glusterfsd -f ./server4.vol
當然還可以通過端口進行查看
netstat -ln
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.211.128:6996 0.0.0.0:* LISTEN
tcp 0 0 192.168.211.128:6997 0.0.0.0:* LISTEN
tcp 0 0 192.168.211.128:6998 0.0.0.0:* LISTEN
tcp 0 0 192.168.211.128:6999 0.0.0.0:* LISTEN

到此,服務器端啓動完畢
然後啓動client端

modprobe fuse 先掛着fuse模塊
glusterfs -l /tmp/glusterfs.log -f /etc/glusterfs/client.vol /mnt
執行完畢後可以使用df -h進行查看是否mount成功,如果成功結果如下
[root@contos5-1-4 glusterfs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.1G 2.5G 4.3G 37% /
/dev/sda1 190M 11M 170M 7% /boot
tmpfs 125M 0 125M 0% /dev/shm
glusterfs 22G 8.7G 12G 43% /mnt
如果沒有如上顯示,則說明掛載沒有成功,可以查看tmp下建立的日誌進行排錯

接下來就準備進行測試工作了
測試目的很簡單,就是對round-robin進行測試,主要使用touch命令

在client端的/mnt目錄下
touch {1,2,3,4,5,6,7,8,9}
然後執行ls查看結果如下
[root@contos5-1-4 mnt]# ls
1 2 3 4 5 6 7 8 9
現在在到server端去查看
cd到/home目錄
執行ls *進行查看,結果如下
[root@contos5-1-1 home]# ls *
dir1:
1 4 7

 

dir2:
2 5 8

dir3:
3 6 9

dir4:
1 2 3 4 5 6 7 8 9

由上面看到,9個新的文件是依次創建到了dir1 dir2 dir3中,dir4就是我們配置的namespace,用於交換空間

到此,我的試驗就算完成了,而且試驗目的也達成了
但到此我卻發現了幾個問題
1,交換空間也就是namespace需要設置多大,是應該每個存儲空間之和還是和一個空間大小一樣就行
2,如果其中一個節點down機,上面的數據如何處理

對於以上幾個問題,我會再之後的學習中進行研究,並實現glusterfs的其他功能,對於其中的參數下次一併討論吧

今天主要把我學習的文件複製功能寫出來

Replicate

type cluster/replicate

Replicate(前身是AFR)爲glusterfs提供了類似RAID-1的功能。Replicate會複製文件或者文件夾到各個 subvolumes裏。因此,如果replicate部分設置了4個subvolume,那就會4分的文件或者文件夾的拷貝副本。replicate同 樣提供了高可用,比如如果其中的一個subvolume down掉了(或者說一臺存儲服務器壞了,網絡連接出現問題)replicate依然可以使用冗餘的拷貝副本來提供服務。
Replicate同樣提供了自動修復功能,比如,如果一臺crash掉的服務器恢復了,這臺服務器上存儲的過期的文件或者文件夾就會被更新成最新的版本。Replicate使用了後端文件系統的擴展功能來跟蹤文件或者文件夾的版本來提供自動恢復的功能

volume replicate-example
type cluster/replicate
subvolumes brick1 brick2 brick3
end-volume

上面的例子將會把所有文件都複製到brick1 brick2 brick3中

所有讀的操作都會從第一臺活着的sbuvolume進行。如果三個sub-volume都是啓用的狀態,就從brick1讀;如果brick1 down了,就從brick2讀。如果讀的操作剛剛完成brick1就down了,複製就會傳遞給brick2.

概念講完了,下面就來說下配置吧

模擬環境:
vmware6.0 兩個linux server:192.168.211.128 client:192.168.211.129
兩個存儲node,一個client

先來看看server上的配置
cat /etc/glusterfs/glusterfs-server0.vol

### Export volume “brick” with the contents of “/home/export” directory.

 

volume brick
type storage/posix # POSIX FS translator
option directory /home/dir1 # Export this directory
end-volume

volume locker
type features/posix-locks
subvolumes brick
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.211.128 # Default is to listen on all interfaces
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to “brick” volume
option auth.addr.locker.allow *
end-volume

cat /etc/glusterfs/glusterfs-server1.vol

### Export volume “brick” with the contents of “/home/export” directory.
volume brick
type storage/posix # POSIX FS translator
option directory /home/dir2 # Export this directory
end-volume

 

volume locker
type features/posix-locks
subvolumes brick
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option bind-address 192.168.211.128 # Default is to listen on all interfaces
option listen-port 6997 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to “brick” volume
option auth.addr.locker.allow *
end-volume

然後是client端的配置
cat /etc/glusterfs/replicate-client.vol

### Add client feature and attach to remote subvolume
volume client0
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume locker # name of the remote volume
end-volume

 

volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128
option remote-port 6997
option remote-subvolume locker
end-volume

volume bricks
type cluster/replicate
subvolumes client0 client1
end-volume

到此,配置就都完成了
接下來啓動服務
server端

glusterfsd -f /etc/glusterfs/glusterfs-server0.vol
glusterfsd -f /etc/glusterfs/glusterfs-server1.vol
當然啓動的時候可以加上-l /dir/glusterfs.log參數,把日誌加入
然後通過ps fax查看進程如下
2206 ? Ssl 0:00 glusterfsd -f /etc/glusterfs/glusterfs-server1.vol
2396 ? Ssl 0:00 glusterfsd -f /etc/glusterfs/glusterfs-server0.vol
說明,服務正常啓動起來了

client端

modprobe fuse
glusterfs -l /tmp/glustfs.log -f /etc/glusterfs/replicate-client.vol /mnt
通過df -h查看是否服務正常啓動,如下
[root@contos5-1-4 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.1G 2.5G 4.3G 37% /
/dev/sda1 190M 11M 170M 7% /boot
tmpfs 125M 0 125M 0% /dev/shm
glusterfs 7.1G 2.9G 3.9G 43% /mnt
如果沒有如上紅色標記的,請查看日誌然後進行排查

接下來就是測試階段
首先在/mnt目錄下touch 1空文件
然後在server端ls /home/*查看如下

[root@contos5-1-1 home]# ls *
dir1:
1

 

dir2:
1

可以看到dir2中已經同步了1這個文件
然後現在我麼在server上把dir1這個進程kill掉

2206 ? Ssl 0:00 glusterfsd -f /etc/glusterfs/glusterfs-server1.vol
2396 ? Ssl 0:00 glusterfsd -f /etc/glusterfs/glusterfs-server0.vol
kill -9 2396
這時client端/mnt應該只會掛載dir2了

這是/mnt中的文件是0字節的

[root@contos5-1-4 mnt]# ll
total 0
-rw-r–r– 1 root root 0 Feb 17 12:42 1

 

現在我們echo “123456789″ >1中
cat 1返回如下
[root@contos5-1-4 mnt]# cat 1
123456789

再來看下server上dir1中的1
[root@contos5-1-1 home]# ll /home/dir1
total 8
-rw-r–r– 1 root root 0 Feb 17 12:42 1
可以發現是0字節

dir2中的1
[root@contos5-1-1 home]# ll /home/dir2/
total 8
-rw-r–r– 1 root root 10 Feb 17 12:42 1
可以看到是10字節

如此看來,dir1被我們模擬down機後,修改等請求都已經傳送到dir2上了,現在讓我們來恢復dir1,看下效果

glusterfsd -f /etc/glusterfs/glusterfs-server0.vol
在client上cat 1的內容
[root@contos5-1-4 mnt]# cat 1
123456789
然後看下server上dir1的情況
[root@contos5-1-1 home]# ll /home/dir1/
total 8
-rw-r–r– 1 root root 10 Feb 17 12:42 1
dir1上已經同步成10字節了

由以上測試可以證明,複製操作是正常進行的,至於性能方面還需要進一步的測試,這個放到稍後進行

開頭概念解釋屬於自己翻譯的官方文檔

具體請參看 http://www.gluster.org/docs/index.php/User_Guide中的replicate部分

performance translaters(高性能轉換器)

Read Ahead 預讀

配置文件寫法 預讀轉換器在每次

type performace/read-ahead

讀取操作前就預先抓取數據。這個有利於應用頻繁持續性的訪問文件,當應用完成當前數據塊讀取的時候,下一個數據塊就已經準備好了。
額外的,預讀轉換器也可以扮演讀聚合器,許多小的讀操作被綁定起來,當成一個大的讀請求發送給服務器
預讀處理有page-size和page-count來定義,page-size定義了,一次預讀取的數據塊大小,page-count定義的是被預讀取的塊的數量
預讀最好被使用在使用InfiniBand卡(或使用ib-verbs傳輸)的系統上。在快速以太網或者千兆以太網絡環境中,就算不使用預讀,Glusterfs也可以達到網卡最大連接的吞吐量,所以使用預讀配置就是多餘的

需要注意的是,預讀操作只會發生在讀的請求是完全連續的。如果應用訪問數據很隨機,那使用預讀實際上將造成性能的損失,因爲預讀操作會拿一些應用並不會用到的數據塊。

Options:
page-size <n> (256KB) #每次預讀取的數據塊大小
page-count <n> (2) #每次預讀取數據塊的數量
force-atime-update [on|off|yes|no] (off|no)
#是否強制在每次讀操作時更新文件的訪問時間,不設置這個,訪問時間將有些不精確,這個將影響預讀轉換器讀取數據時的那一時刻而不是應用真實讀到數據的那一時刻。

Write Behind(後寫)

type performance/write-behind

後寫轉換器改善了了寫操作的延時。它會先把寫操作發送到後端存儲,同時返回給應用寫操作完畢,而實際上寫的操作還正在執行。使用後寫轉換器就可以像流水線一樣把寫請求持續發送。這個後寫操作模塊更適合使用在client端,以期減少應用的寫延遲。

後寫轉換器同樣可以聚合寫請求。如果aggregate-size選項設置了的話,當連續的寫入大小累積起來達到了設定的值,就通過一個寫操作寫入到存儲上。這個操作模式適合應用在服務器端,以爲這個可以在多個文件並行被寫入磁盤時降低磁頭動作。

aggregate-size選項的默認值是128KB。儘管這個默認值對於大多數的用戶來講已經可以很好的工作了,但還是希望你根據實際環境經過不斷調整數值試驗,以達到最大的性能。這是因爲後寫的性能依賴於你的連接情況,RAM的大小以及工作的負載情況

aggregate-size <n> (128KB) #當累積達到這個值才進行實際的寫操作
flush-behind [on|yes|off|no] (off|no)

IO Threads(IO 線程)

type performance/io-threads

IO線程轉換器試圖增加服務器後臺進程對文件元數據讀寫I/O的處理能力。由於GlusterFS服務是單線程的,使用IO線程轉換器可以較大的提高性能。這個轉換器最好是被用於服務器端,而且是在服務器協議轉換器後

面被加載。

IO線程操作會將讀和寫操作分成不同的線程。同一時刻存在的總線程是恆定的並且是可以配置的

thread-cout <n> (1) #線程使用的數量
cache-size <n> (64MB) #被允許放置在一個線程中的最大數據量

IO Cache(IO緩存)

type performance/io-cache

IO緩存轉換器可以緩存住已經被讀過的數據。這個對於多個應用對同一個數據多次訪問,並且如果讀的操作遠遠大於寫的操作的話是很有用的(比如,IO緩存很適合用於提供web服務的環境,大量的客戶端只會進行簡單的讀取文件的操作,只有很少一部分會去寫文件)。

IO緩存轉換器讀數據一次讀page-size設置的大小的數據,並把讀到的數據緩存起來指到cache-size設置的大小。緩存以以最新近被訪問的列表來作爲優先保持的,cache文件的優先級是可以通過user-specified參數來配置的。

當IO緩存轉換器檢測到有寫操作的時候,它就會把相應的文件從緩存中刪除。

IO緩存轉換器會定期的根據文件的修改時間來驗證緩存中相應文件的一致性。驗證超時時間是可以配置的。

page-size <n> (128KB) #一條記錄的大小
cache-size (n) (32MB) #可以緩存的最大數據量
force-revalidate-timeout <n> (1) #強制緩存一致性檢測超時時間,單位秒
priority <pattern> (*:0) #文件匹配列表及其設置的優先級

Booster(加速器)

type performance/booster

加速器給應用和GlusterFS間的對寫請求提供了一個快速通道。不適用加速器的情況,應用到GlusterFS的所有請求都會先經過FUSE。 使用加速器模塊之後使得Glusterfs和加速器的共享庫相結合,應用就可以直接把讀寫的請求發給Glusterfs的子進程而跳過FUSE。

Booster結構由兩部分組成:Booster translator和booster共享庫,bootster translator最好是在客戶端加載,通常被配置在translator樹的根上。booster共享庫被應用以LD_PRELOADed的方式使用。

以上翻譯均來自Glusterfs user guide,本人水平有限,請參考原文http://www.gluster.org/docs/index.php/User_Guide中相應的部分

對於Glusterfs學習也有了幾天了,但對於性能上的評價目前關注的比較少,今天主要才測測Glusterfs和NFS的性能比,但由於手頭上條件有限,只能通過虛擬機來測試,數據僅供參考,如有人可以在真實環境測試,還希望發出來供大家參考

我的環境
vmware6.0模擬兩個linux

linux01 256MB內存,8G硬盤,centos5,ip:192.168.211.128,用作NFSserver端和Glusterfs的server端
linux02 256MB內存,8G硬盤,centos5,ip:192.168.211.129,用作client

下面就來看下我的測試結果

這張圖是NFS的讀取測試結果

下面這張是NFS的寫入測試結果

然後我把兩臺虛擬機重啓,並啓用Glusterfs模式

第一張圖是Glusterfs的讀取結果

第二張圖是寫入的測試結果

由上面的結果看,Glusterfs僅僅用於NFS這種模式的情況下,寫入速度並不太理想

但Glusterfs的功能不僅僅提供共享存儲來用,而是一個存儲的聚合,當然以上測試結果未必就很準確,畢竟我的測試條件不行,不過也僅僅是給各位一個啓示,請有條件的同志繼續完成測試工作吧

官方的glusterfs和NFS的測試結果請看
http://www.gluster.org/docs/index.php/GlusterFS_1.2.1-BENKI_Aggregated_I/O_vs_NFSv4_Benchmark

看glusterfs的東西也有段時間了,不過一直一來也是停留在對這個分佈式系統的學習,當然對於一個軟件的學習不能僅僅停留在對這個軟件的熟 悉,還要考慮它所適用的範圍。最近就在思考,到底對於我們的什麼應用合適,我這邊接觸的比較多的結構就是N臺Web+單個NFS。我就再想,既然 glusterfs是個聚合分佈式文件系統,而且支持HA的功能,是不是可以使用glusterfs來替換NFS,既可以達到共享文件的用途,有可以解決 了單點的問題。

先來看下我預計的拓撲結構

下面來解釋一下這個拓撲,前端的web應用,每臺web上的應用都放置在glusterfs共享出來的硬盤上,儘管我圖上畫的是一個 diskpool,但實際的容量大小是幾臺web中glusterfs共享空間最小的那個大小。而且對於上面這個拓撲的應用,我並不需要獨立的NAS來做 共享,完全可以使用每臺web服務器上未用的硬盤空間(注:當然你可以選擇使用NAS來進行存儲,在存儲量很大的情況下)。

接下來就來看下實現的方式:
web01:192.168.220.128 共享出來的地址:/var/app
web02:192.168.220.129 共享出來的地址:/var/app
兩臺機器都事先安裝好glusterfs和fuse(安裝方法可以參考我前幾篇文章)
首先來配置web01的server端

cat /etc/glusterfs/server.vol

volume brick
type storage/posix # POSIX FS translator
option directory /var/app # Export this directory
end-volume

 

volume locker
type features/posix-locks
subvolumes brick
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to “brick” volume
option auth.addr.locker.allow *
end-volume

web02上的server端配置相同
cat /etc/glusterfs/server.vol
volume brick
type storage/posix # POSIX FS translator
option directory /var/app # Export this directory
end-volume

 

volume locker
type features/posix-locks
subvolumes brick
end-volume

### Add network serving capability to above brick.
volume server
type protocol/server
option transport-type tcp/server
option listen-port 6996 # Default is 6996
subvolumes locker
option auth.addr.brick.allow * # Allow access to “brick” volume
option auth.addr.locker.allow *
end-volume

服務器端配置完畢,接下來就是client端的配置,因爲兩臺機器互爲對方的sever又同時是自己的server所以兩臺上都需要配置client端。
首先看下web01上的配置
cat /etc/glusterfs/replicate.vol

 

volume client0
type protocol/client
option transport-type tcp/client
option remote-host 127.0.0.1 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume locker # name of the remote volume
end-volume

 

volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.129
option remote-port 6996
option remote-subvolume locker
end-volume

volume bricks
type cluster/replicate
subvolumes client0 client1
option read-subvolume client0
end-volume

再來看下web02上的配置
cat /etc/glusterfs/replicate.vol
volume client0
type protocol/client
option transport-type tcp/client
option remote-host 127.0.0.1 # IP address of the remote brick
option remote-port 6996 # default server port is 6996
option remote-subvolume locker # name of the remote volume
end-volume

 

volume client1
type protocol/client
option transport-type tcp/client
option remote-host 192.168.211.128
option remote-port 6996
option remote-subvolume locker
end-volume

volume bricks
type cluster/replicate
subvolumes client0 client1
option read-subvolume client0
end-volume

到此,配置就已經完成了,接下來就可以測試咯,首先兩臺機器上需要加載fuse
modprobe fuse
如果沒有報錯,說明fuse模塊加載完畢,然後在兩臺機器上啓動server端和client端
web01上執行
啓動服務端
glusterfsd -f /etc/glusterfs/server.vol

 

啓動client端
glusterfs -f /etc/glusterfs/replicate.vol /usr/local/nginx/html/blog

web02上如法炮製
然後就可以在web01上的/mnt上放置web的內容了,web02上可以自動的看到相應的內容,並不需要人爲的干預,沒臺機器上都會有一份 web應用的拷貝,這樣無論那臺web宕機,web的提供的服務是不會中斷,也不會受到影響的,從而避免了,單點NFS故障導致服務中斷,同時避免了,雙 NFS數據同步的問題。同時每臺web優先讀取自己硬盤上的copy,所以可以減少網絡負載。

但這個方案還不是最完美的,因爲這種方案對於寫頻繁的應用來說是存在問題的,如果出現同時寫一個文件的情況,就會造成數據的不一致,所以如果 web應用是讀頻繁的話,還是很有優勢的,而且如果後臺人員需要對應用進行更新,只需要更新第一臺server的就行,默認情況下replicate的應 用,subvolumes client0 client1 中的一個就是主server,這裏只要對於client0上的數據進行更新就可以做到同步了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章