構成
・3ノード
・OS:CentOS7
・gluster41
2018年11月時点
Hadoop用ファイルシステム作成
・ディスク確認
[root@glusterfs-node1 ~]# lsblk -a
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
sda1 8:1 0 500M 0 part /boot
sda2 8:2 0 49.5G 0 part
centos-root 253:0 0 45.6G 0 lvm /
centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sr0 11:0 1 1024M 0 rom
・パーティション作成
[root@glusterfs-node1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xdea6092b.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
・ディスク確認
[root@glusterfs-node1 ~]# lsblk -a
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
sda1 8:1 0 500M 0 part /boot
sda2 8:2 0 49.5G 0 part
centos-root 253:0 0 45.6G 0 lvm /
centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sdb1 8:17 0 50G 0 part
sr0 11:0 1 1024M 0 rom
・デバイスをフォーマット
[root@glusterfs-node1 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=3276736 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=13106944, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=6399, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
・マウント
[root@glusterfs-node1 ~]# mkdir /data
[root@glusterfs-node1 ~]# mount /dev/sdb1 /data
[root@glusterfs-node1 ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root xfs 47781076 1439964 46341112 4% /
devtmpfs devtmpfs 1928504 0 1928504 0% /dev
tmpfs tmpfs 1940480 0 1940480 0% /dev/shm
tmpfs tmpfs 1940480 8980 1931500 1% /run
tmpfs tmpfs 1940480 0 1940480 0% /sys/fs/cgroup
/dev/sda1 xfs 508588 301556 207032 60% /boot
tmpfs tmpfs 388096 0 388096 0% /run/user/1000
/dev/sdb1 xfs 52402180 32944 52369236 1% /data
・OS再起動時もmountされるように
「/etc/fstab」ファイルに
/dev/sdb1 /data xfs defaults 0 0
を追記
OS設定
・Firewall,SELinux無効化
systemctl stop firewalld
systemctl disable firewalld
vi /etc/selinux/config ←「disabled」に変更
・hosts設定
「/etc/hosts」ファイルに以下を追記
192.168.11.110 glusterfs-node1.vsphere.local
192.168.11.111 glusterfs-node2.vsphere.local
192.168.11.112 glusterfs-node3.vsphere.local
GlusterFSインストール
・インストール
yum install -y centos-release-gluster
yum install -y glusterfs-server
・起動設定
[root@glusterfs-node1 ~]# systemctl enable glusterd
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.
[root@glusterfs-node1 ~]# systemctl start glusterd
[root@glusterfs-node1 ~]# systemctl status glusterd
● glusterd.service - GlusterFS, a clustered file-system server
Loaded: loaded (/usr/lib/systemd/system/glusterd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2018-11-26 11:54:36 JST; 9s ago
Process: 1556 ExecStart=/usr/sbin/glusterd -p /var/run/glusterd.pid --log-level $LOG_LEVEL $GLUSTERD_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 1557 (glusterd)
CGroup: /system.slice/glusterd.service
mq1557 /usr/sbin/glusterd -p /var/run/glusterd.pid --log-level INFO
Nov 26 11:54:36 glusterfs-node1.vsphere.local systemd[1]: Starting GlusterFS, a clustered file-system server...
Nov 26 11:54:36 glusterfs-node1.vsphere.local systemd[1]: Started GlusterFS, a clustered file-system server.
信頼済みサーバープールの作成(node1)
[root@glusterfs-node1 ~]# gluster peer probe glusterfs-node2.vsphere.local
peer probe: success.
[root@glusterfs-node1 ~]# gluster peer probe glusterfs-node3.vsphere.local
peer probe: success.
[root@glusterfs-node1 ~]# gluster peer status
Number of Peers: 2
Hostname: glusterfs-node2.vsphere.local
Uuid: 3af57bc4-9f3b-44fe-b9f6-59f06db9af85
State: Peer in Cluster (Connected)
Hostname: glusterfs-node3.vsphere.local
Uuid: f1419efb-1e7f-4ee6-98ad-90c4fea01736
State: Peer in Cluster (Connected)
ボリューム作成
・ボリュームがないことを確認
[root@glusterfs-node1 ~]# gluster vol info
No volumes present
・レプリカボリューム作成
2ノードに同一のデータを保持するレプリカボリューム「vol_replica」を作成する
[root@glusterfs-node1 ~]# gluster volume create vol_replica replica 2 glusterfs-node1.vsphere.local:/data/vol_replica glusterfs-node2.vsphere.local:/data/vol_replica
Replica 2 volumes are prone to split-brain. Use Arbiter or Replica 3 to avoid this. See: http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/.
Do you still want to continue?
(y/n) y
volume create: vol_replica: success: please start the volume to access data
3ノードでのレプリカボリューム作成を推奨されたが、今回は無視して作成
・確認
[root@glusterfs-node1 ~]# gluster vol info
Volume Name: vol_replica
Type: Replicate
Volume ID: 0766f185-4b61-457f-ae11-4f12b9ed08cc
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs-node1.vsphere.local:/data/vol_replica
Brick2: glusterfs-node2.vsphere.local:/data/vol_replica
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
・分散ボリューム作成
[root@glusterfs-node1 ~]# gluster vol create vol_distribute glusterfs-node1.vsphere.local:/data/vol_distribute gluste
rfs-node2.vsphere.local:/data/vol_distribute glusterfs-node3.vsphere.local:/data/vol_distribute
volume create: vol_distribute: success: please start the volume to access data
・確認
[root@glusterfs-node1 ~]# gluster vol info
Volume Name: vol_distribute
Type: Distribute
Volume ID: fd2bcde8-11e1-4915-9236-6a869ebe21cd
Status: Created
Snapshot Count: 0
Number of Bricks: 3
Transport-type: tcp
Bricks:
Brick1: glusterfs-node1.vsphere.local:/data/vol_distribute
Brick2: glusterfs-node2.vsphere.local:/data/vol_distribute
Brick3: glusterfs-node3.vsphere.local:/data/vol_distribute
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
Volume Name: vol_replica
Type: Replicate
Volume ID: 0766f185-4b61-457f-ae11-4f12b9ed08cc
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs-node1.vsphere.local:/data/vol_replica
Brick2: glusterfs-node2.vsphere.local:/data/vol_replica
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
※参考:https://sites.google.com/site/glusterfstech/volumes/create
・ボリュームスタート
[root@glusterfs-node1 ~]# gluster volume start vol_distribute
volume start: vol_distribute: success
[root@glusterfs-node1 ~]# gluster volume start vol_replica
volume start: vol_replica: success
テスト(レプリカボリューム)
サーバーの1つを使用してボリュームをマウントする。
通常、「クライアント」と呼ばれる外部のマシンから行うが、その方法ではクライアントマシンに追加のパッケージをインストールする必要があるため、最初にテストする簡単な場所としてサーバーを使用する。
・ボリュームのマウント
mount -t glusterfs glusterfs-node1.vsphere.local:/vol_replica /mnt
・テストファイル作成
touch /mnt/test.txt
・ファイル確認
[root@glusterfs-node1 ~]# ls -l /data/vol_replica
total 0
-rw-r--r-- 2 root root 0 Nov 26 12:26 test.txt
[root@glusterfs-node2 ~]# ls -l /data/vol_replica
total 0
-rw-r--r-- 2 root root 0 Nov 26 12:26 test.txt
・アンマウント
umount /mnt
テスト(分散ボリューム)
・ボリュームのマウント
mount -t glusterfs glusterfs-node1.vsphere.local:/vol_distribute /mnt
・マウント確認
[root@glusterfs-node1 ~]# df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 49G 1.5G 48G 4% /
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 9.3M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sdb1 xfs 54G 34M 54G 1% /data
/dev/sda1 xfs 521M 309M 213M 60% /boot
tmpfs tmpfs 398M 0 398M 0% /run/user/1000
tmpfs tmpfs 398M 0 398M 0% /run/user/0
glusterfs-node1.vsphere.local:/vol_distribute fuse.glusterfs 161G 1.8G 160G 2% /mnt
・テストファイル作成
for i in
seq -w 1 100; do cp -rp /var/log/messages /mnt/copy-test-$i; done
・ファイル確認
[root@glusterfs-node1 mnt]# find /mnt -name "copy*" | wc -l
100
[root@glusterfs-node1 mnt]# find /data/vol_distribute/ -name "copy*" | wc -l
39
[root@glusterfs-node2 ~]# find /data/vol_distribute/ -name "copy*" | wc -l
38
[root@glusterfs-node3 ~]# find /data/vol_distribute/ -name "copy*" | wc -l
23
参考
https://wiki.centos.org/SpecialInterestGroup/Storage/gluster-Quickstart
https://qiita.com/Yuki-Inamoto/items/2ea1efe862aeba34019c
https://dev.classmethod.jp/cloud/aws/glusterfs-on-ec2/