GlusterFS FileLock Test
確認すること
2クライアントで同じファイルに書き込みしようとしたとき、
後から書き込みしようとしたクライアントで遅延が発生し、ロックが機能していることを確認。
結果
ロックが効いており、後から書き込みをしようとしたクライアントは、
先に書き込みをしているクライアントが完了するのを待ってから書き込みを完了する。
Glusterfsの構成
- GlusterfsのマウントはFUSEを使っているGluster Native Client を使用する(NFSやCIFSは実施しない)
- Glusterfsサーバ側のファイルフォーマットはext3
- Glusterfsクライアント2台
- Glusterfsサーバ4台
- Gluster Volume用のディスクは一台10GB
- サーバはすべてVMwareのゲストOS
- OSはUbuntu10.04 LTS 64bit
- Glusterfs 3.2.3を使用
- インストールはオフィシャルで用意されているglusterfs_3.2.3-1_amd64.debを使用
- Glusterfsサーバボリュームは「Distributed Volume」と「Distributed Replicated Volume」の2つで確認。(他にはStripedなどがある)
確認パターン
一台のサーバ上でターミナルを2つ起動して、ローカルファイルに対して書き込み。
一台のGlusterfsクライアント上からターミナルを2つ起動して、Glusterfsサーバ上のファイルに対して書き込み。
二台のGlusterfsクライアント上から、Glusterfsサーバ上のファイルに対して書き込み。
一台のGlusterfsクライアント上と、Glusterfsサーバ上から、Glusterfsサーバ上のファイルに対して書き込み。
結果
Distributed Volume
はじめにアクセスしたクライアントを待ってから後のクライアントが書き込みをするのでロックが効いている。
はじめにアクセスしたクライアントを待ってから後のクライアントが書き込みをするのでロックが効いている。
はじめにアクセスしたクライアントを待ってから後のクライアントが書き込みをするのでロックが効いている。
遅延しなかった。
Distributed Replicated Volume
上記と同じ結果になった。
書き込み実行シェル
テストは以下シェルを実行。時間はtimeコマンドで計測。
ファイルパスはローカルとGlusterfs上とで変更する。
file_write.pyを実行したあとでfile_write2.pyを実行する。
file_write.py
#!/usr/sbin/env python
import time
import fcntl
def file_write():
str = """ at file_write\n """
f = open('/mnt/glusterfs/test.txt', 'w')
fcntl.flock(f.fileno(),fcntl.LOCK_EX)
time.sleep(30.0)
f.write(str)
fcntl.flock(f.fileno(),fcntl.LOCK_UN)
f.close()
file_write()
file_write2.py
#!/usr/sbin/env python
import time
import fcntl
def file_write():
str = """ at file_write2\n """
f = open('/mnt/glusterfs/test.txt', 'a')
fcntl.flock(f.fileno(),fcntl.LOCK_EX)
time.sleep(0.0)
f.write(str)
fcntl.flock(f.fileno(),fcntl.LOCK_UN)
f.close()
file_write()
glusterfs 3.2.3 Install
- Gluserfs Client sakabuntu07,sakabuntu08
- Glusterfs Server sakabuntu03,sakabuntu04,sakabuntu05,sakabuntu06
install package
# apt-get install nfs-common portmap libevent-1.4-2 libgssglue1 libnfsidmap2 librpcsecgss3
# dpkg -i glusterfs_3.2.3-1_amd64.deb
# /etc/init.d/glusterd start
Storage Server Setting
To add a server to the storage pool
# gluster peer probe sakabuntu03
# gluster peer probe sakabuntu04
# gluster peer probe sakabuntu05
# gluster peer probe sakabuntu06
ex) Remove a server from the storage pool
# gluster peer detach sakabuntu03
Creating Distributed Volumes
Create the volume
# gluster volume create test-volume transport tcp sakabuntu03:/data sakabuntu04:/data sakabuntu05:/data sakabuntu06:/data
Creation of volume test-volume has been successful. Please start the volume to access data.
display the volume information
# gluster volume info
Volume Name: test-volume
Type: Distribute
Status: Created
Number of Bricks: 4
Transport-type: tcp
Bricks:
Brick1: sakabuntu03:/data
Brick2: sakabuntu04:/data
Brick3: sakabuntu05:/data
Brick4: sakabuntu06:/data
Start the volume
# gluster volume start test-volume
Starting volume test-volume has been successful
Display information about all volumes
# gluster volume info all
Volume Name: test-volume
Type: Distribute
Status: Started
Number of Bricks: 4
Transport-type: tcp
Bricks:
Brick1: sakabuntu03:/data
Brick2: sakabuntu04:/data
Brick3: sakabuntu05:/data
Brick4: sakabuntu06:/data
To manually mount a Gluster volume
# mkdir /mnt/glusterfs
# mount -t glusterfs sakabuntu03:/test-volume /mnt/glusterfs
# df -h
ファイルシステム サイズ 使用 残り 使用% マウント位置
/dev/sda1 29G 1.2G 26G 5% /
none 496M 164K 495M 1% /dev
none 500M 0 500M 0% /dev/shm
none 500M 80K 500M 1% /var/run
none 500M 0 500M 0% /var/lock
none 500M 0 500M 0% /lib/init/rw
sakabuntu03:/test-volume
40G 603M 37G 2% /mnt/glusterfs
To test mounted volumes
# mount
sakabuntu03:/test-volume on /mnt/glusterfs type fuse.glusterfs (rw,allow_other,default_permissions,max_read=131072)
Creating Distributed Replicated Volumes
Create the volume
# gluster volume create test-volume replica 2 transport tcp sakabuntu03:/data sakabuntu04:/data sakabuntu05:/data sakabuntu06:/data
Creation of volume test-volume has been successful. Please start the volume to access data.
Display information about all volumes
# gluster volume info all
Volume Name: test-volume
Type: Distributed-Replicate
Status: Created
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: sakabuntu03:/data
Brick2: sakabuntu04:/data
Brick3: sakabuntu05:/data
Brick4: sakabuntu06:/data
Start the volume
# gluster volume start test-volume
Starting volume test-volume has been successful
Display information about all volumes
# gluster volume info all
Volume Name: test-volume
Type: Distributed-Replicate
Status: Started
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: sakabuntu03:/data
Brick2: sakabuntu04:/data
Brick3: sakabuntu05:/data
Brick4: sakabuntu06:/data
To manually mount a Gluster volume
# mkdir /mnt/glusterfs
# mount -t glusterfs sakabuntu03:/test-volume /mnt/glusterfs
# df -h
ファイルシステム サイズ 使用 残り 使用% マウント位置
/dev/sda1 29G 1.2G 26G 5% /
none 496M 164K 495M 1% /dev
none 500M 0 500M 0% /dev/shm
none 500M 84K 500M 1% /var/run
none 500M 0 500M 0% /var/lock
none 500M 0 500M 0% /lib/init/rw
sakabuntu03:/test-volume
20G 302M 19G 2% /mnt/glusterfs
To test mounted volumes
# mount
sakabuntu03:/test-volume on /mnt/glusterfs type fuse.glusterfs (rw,allow_other,default_permissions,max_read=131072)
Delete Volume
umount glusterfs volume
# umount /mnt/glusterfs
Gluster volume stop test-volume
# gluster volume stop test-volume
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
Stopping volume test-volume has been successful
Display information about all volumes
# gluster volume info all
Volume Name: test-volume
Type: Distribute
Status: Stopped
Number of Bricks: 4
Transport-type: tcp
Bricks:
Brick1: sakabuntu03:/data
Brick2: sakabuntu04:/data
Brick3: sakabuntu05:/data
Brick4: sakabuntu06:/data
Gluster volume delete
# gluster volume delete test-volume
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
Deleting volume test-volume has been successful
Display information about all volumes
# gluster volume info all
No volumes present
Failure Test
Distributed Volume
Distributed Replicated Volume
マウント時にport24009ですべてのGlusterfsサーバにセッションを貼ってヘルスチェックを実施しているため、指定したサーバが落ちても問題ない。
すべてのボリュームにまたがっているbrickの数だけ、24009から順にportが割当てられる。
参考文献
Glusterfs 3.2 Administration Guide