このチュートリアルでは、GlusterFSを使用する2つのストレージサーバー(CentOS 7.2)を使用して高可用性ストレージをセットアップする方法を示します。各ストレージサーバーは他のストレージサーバーのミラーになり、ファイルは両方のストレージサーバーに自動的に複製されます。クライアントシステム(CentOS 7.2も)は、ローカルファイルシステムであるかのようにストレージにアクセスできます。 GlusterFSは、数ペタバイトに拡張できるクラスター化されたファイルシステムです。 InfinibandRDMAまたはTCP/IP相互接続を介してさまざまなストレージブリックを1つの大規模な並列ネットワークファイルシステムに集約します。ストレージブリックは、SATA-IIRAIDおよびInfinibandHBAを備えたx86_64サーバーなどの任意のコモディティハードウェアで作成できます。
1予備メモ
このチュートリアルでは、3つのシステム、2つのサーバー、およびクライアントを使用します。
- server1.example.com:IPアドレス192.168.0.100(サーバー)
- server2.example.com:IPアドレス192.168.0.101(サーバー)
- client1.example.com:IPアドレス192.168.0.102(クライアント)
3つのシステムすべてが、他のシステムのホスト名を解決できる必要があります。 DNSを介してこれを実行できない場合は、3つのシステムすべてで次のようになるように/ etc/hostsファイルを編集する必要があります。
nano /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 192.168.0.100 server1.example.com server1 192.168.0.101 server2.example.com server2 192.168.0.102 client1.example.com client1 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
(次の設定では、ホスト名の代わりにIPアドレスを使用することもできます。IPアドレスを使用する場合は、ホスト名を解決できるかどうかを気にする必要はありません。)
2追加のリポジトリを有効にする
server1.example.com/server2.example.com/client1.example.com:
まず、ソフトウェアパッケージのGPGキーをインポートします:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
次に、CentOSシステムでEPEL7リポジトリを有効にします。
yum -y install epel-release
yum -y install yum-priorities
/etc/yum.repos.d/epel.repoを編集します...
nano /etc/yum.repos.d/epel.repo
...そして[epel]セクションにpriority=10という行を追加します:
[epel] name=Extra Packages for Enterprise Linux 7 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch failovermethod=priority enabled=1 priority=10 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [...]
次に、システム上の既存のパッケージを更新します。
yum -y update
3GlusterFSサーバーのセットアップ
server1.example.com/server2.example.com:
GlusterFSは、CentOSストレージの分科会のリポジトリで利用できます。次のコマンドでリポジトリをインストールします:
yum -y install centos-release-gluster
次に、次のようにGlusterFSサーバーをインストールします。
yum -y install glusterfs-server
Glusterデーモンのシステム起動リンクを作成して起動します:
systemctl enable glusterd.service
systemctl start glusterd.service
コマンド
glusterfsd --version
インストールしたばかりのGlusterFSバージョン(この場合は3.7.12)が表示されます:
[[email protected] ~]# glusterfsd --version
glusterfs 3.7.12 built on Jun 24 2016 14:11:19
Repository revision: git://git.gluster.com/glusterfs.git
Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
ファイアウォールを使用する場合は、TCPポート111、24007、24008、24009-(24009 +すべてのボリュームにわたるブリックの数)がserver1.example.comおよびserver2.example.comで開いていることを確認してください。
次に、server2.example.comを信頼できるストレージプールに追加する必要があります(server1.example.comからすべてのGlusterFS構成コマンドを実行していることに注意してください。ただし、構成のため、server2.example.comから実行することもできます。はGlusterFSノード間で複製されます-正しいホスト名またはIPアドレスを使用していることを確認してください):
server1.example.com:
server1.example.comで、
を実行しますgluster peer probe server2.example.com
[[email protected] ~]# gluster peer probe server2.example.com
peer probe: success.
これで、信頼できるストレージプールのステータスは次のようになります。
gluster peer status
[[email protected] ~]# gluster peer status
Number of Peers: 1
Hostname: server2.example.com
Uuid: 582e10da-aa1b-40b8-908c-213f16f57fe5
State: Peer in Cluster (Connected)
次に、server1.example.comとserver2.example.comに2つのレプリカを持つtestvolという名前の共有を作成します(この場合、ミラーリングを設定するため、レプリカの数はサーバーの数と同じであることに注意してください)。 / dataディレクトリ(存在しない場合は作成されます):
gluster volume create testvol replica 2 transport tcp server1.example.com:/data server2.example.com:/data force
[[email protected] ~]# gluster volume create testvol replica 2 transport tcp server1.example.com:/data server2.example.com:/data force
volume create: testvol: success: please start the volume to access data
[[email protected] ~]#
ボリュームを開始します:
gluster volume start testvol
結果は次のようになります:
[[email protected] ~]# gluster volume start testvol
volume start: testvol: success
[[email protected] ~]#
上記のコマンドは、アクションが成功しなかったことを示している可能性があります:
[[email protected] ~]# gluster volume start testvol
Starting volume testvol has been unsuccessful
[[email protected] ~]#
この場合、...
の出力を確認する必要があります。server1.example.com/server2.example.com:
netstat -tap | grep glusterfsd
両方のサーバーで。
このような出力が得られたら...
[[email protected] ~]# netstat -tap | grep glusterfsd
tcp 0 0 0.0.0.0:49152 0.0.0.0:* LISTEN 22880/glusterfsd
tcp 0 0 server1.example.c:49152 server2.example.c:49148 ESTABLISHED 22880/glusterfsd
tcp 0 0 server1.example.c:49152 server1.example.c:49148 ESTABLISHED 22880/glusterfsd
tcp 0 0 server1.example.c:49150 server1.example.c:24007 ESTABLISHED 22880/glusterfsd
tcp 0 0 server1.example.c:49152 server2.example.c:49142 ESTABLISHED 22880/glusterfsd
tcp 0 0 server1.example.c:49152 server1.example.c:49149 ESTABLISHED 22880/glusterfsd
[[email protected] ~]#
...すべて問題ありませんが、出力が得られない場合は...
[[email protected] ~]# netstat -tap | grep glusterfsd
[[email protected] ~]#
...対応するサーバー(この場合はserver2.example.com)でGlusterFSデーモンを再起動します:
server2.example.com:
systemctl restart glusterd.service
次に、...
の出力を確認しますnetstat -tap | grep glusterfsd
...再びそのサーバー上で-これで次のようになります:
[[email protected] ~]# netstat -tap | grep glusterfsd
tcp 0 0 0.0.0.0:49152 0.0.0.0:* LISTEN 10971/glusterfsd
tcp 0 0 server2.example.c:49152 server1.example.c:49140 ESTABLISHED 10971/glusterfsd
tcp 0 0 server2.example.c:49152 server2.example.c:49149 ESTABLISHED 10971/glusterfsd
tcp 0 0 server2.example.c:49152 server2.example.c:49143 ESTABLISHED 10971/glusterfsd
tcp 0 0 server2.example.c:49152 server1.example.c:49142 ESTABLISHED 10971/glusterfsd
tcp 0 0 server2.example.c:49150 server2.example.c:24007 ESTABLISHED 10971/glusterfsd
[[email protected] ~]#
ここでserver1.example.comに戻ります:
server1.example.com:
コマンドでボリュームのステータスを確認できます
gluster volume info
[[メール保護]〜]#glusterボリューム情報
Volume Name: testvol
Type: Replicate
Volume ID: e1f825ca-c9d9-4eeb-b6c5-d62c4aa02376
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data
Brick2: server2.example.com:/data
Options Reconfigured:
performance.readdir-ahead: on
[[email protected] ~]#
デフォルトでは、すべてのクライアントがボリュームに接続できます。 client1.example.com(=192.168.1.102)のみへのアクセスを許可する場合は、次を実行します。
gluster volume set testvol auth.allow 192.168.1.102
IPアドレスにワイルドカードを使用することが可能であり(192.168. *など)、カンマで区切って複数のIPアドレスを指定できることに注意してください(例:192.168.1.102,192.168.1.103)。
ボリューム情報に更新されたステータスが表示されます:
gluster volume info
[[email protected] ~]# gluster volume info
Volume Name: testvol
Type: Replicate
Volume ID: e1f825ca-c9d9-4eeb-b6c5-d62c4aa02376
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1.example.com:/data
Brick2: server2.example.com:/data
Options Reconfigured:
auth.allow: 192.168.1.102
performance.readdir-ahead: on
[[email protected] ~]#
4GlusterFSクライアントのセットアップ
client1.example.com:
クライアントでは、次のようにGlusterFSクライアントをインストールできます。
yum -y install glusterfs-client
次に、次のディレクトリを作成します。
mkdir /mnt/glusterfs
それでおしまい!これで、次のコマンドを使用してGlusterFSファイルシステムを/ mnt/glusterfsにマウントできます。
mount.glusterfs server1.example.com:/testvol /mnt/glusterfs
(server1.example.comの代わりに、上記のコマンドでserver2.example.comを使用することもできます!)
これで、出力に新しいシェアが表示されるはずです...
mount
[[email protected] ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=930336k,nr_inodes=232584,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=34,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=188060k,mode=700)
server1.example.com:/testvol on /mnt/glusterfs type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
[[email protected] ~]#
...そして...
df -h
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 28G 1.3G 27G 5% /
devtmpfs 909M 0 909M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 8.6M 910M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/sda1 497M 192M 306M 39% /boot
tmpfs 184M 0 184M 0% /run/user/0
server1.example.com:/testvol 28G 12G 17G 41% /mnt/glusterfs
[[email protected] ~]#
GlusterFS共有をクライアントに手動でマウントする代わりに、mountコマンドを/etc/rc.localファイルに追加します。ネットワークファイルシステムに必要なネットワークの起動後にrc.localが常に実行されるため、/ etc/fstabには追加しません
/etc/rc.localを開き、次の行を追加します:
nano /etc/rc.local
[...] /usr/sbin/mount.glusterfs server1.example.com:/testvol /mnt/glusterfs
(ここでも、server1.example.comの代わりにserver2.example.comを使用することもできます!)
変更した/etc/rc.localが機能しているかどうかをテストするには、クライアントを再起動します。
reboot
再起動後、...
の出力に共有が表示されます。df -h
...そして...
mount
5テスト
それでは、GlusterFS共有にいくつかのテストファイルを作成しましょう:
client1.example.com:
touch /mnt/glusterfs/test1
touch /mnt/glusterfs/test2
次に、server1.example.comとserver2.example.comの/dataディレクトリを確認しましょう。 test1ファイルとtest2ファイルは各ノードに存在する必要があります:
server1.example.com/server2.example.com:
ls -l /data
[[email protected] ~]# ls -l /data
total 0
-rw-r--r--. 2 root root 0 Jul 1 2016 test1
-rw-r--r--. 2 root root 0 Jul 1 2016 test2
[[email protected] ~]
ここで、server1.example.comをシャットダウンし、client1.example.comのGlusterFS共有でいくつかのファイルを追加/削除します。
server1.example.com:
shutdown -h now
client1.example.com:
touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2
Glusterfsがserver1に到達できなくなった後、server2に切り替わるため、コマンドの実行に時間がかかる場合があります。 server1がオフラインの場合でもデータストレージ共有で作業できるため、ここでシステムのフォールトトレランスを確認できます。変更は、server2.example.comの/dataディレクトリに表示されます。
server2.example.com:
ls -l /data
[[email protected] ~]# ls -l /data
total 8
-rw-r--r--. 2 root root 0 Jul 1 15:17 test1
-rw-r--r--. 2 root root 0 Jul 1 15:19 test3
-rw-r--r--. 2 root root 0 Jul 1 15:19 test4
server1.example.comをもう一度起動して、/dataディレクトリを見てみましょう。
server1.example.com:
ls -l /data
[[email protected] ~]# ls -l /data
total 8
-rw-r--r--. 2 root root 0 Jul 1 15:17 test1
-rw-r--r--. 2 root root 0 Jul 1 15:19 test2
[[email protected] ~]#
ご覧のとおり、server1.example.comは変更内容を自動的に同期しました。変更がまだ同期されていない場合、これは簡単に修正できます。必要なのは、client1.example.comのGlusterFS共有で読み取りコマンドを呼び出すことだけです。例:
client1.example.com:
ls -l /mnt/glusterfs/
[[email protected] ~]# ls -l /data
total 8
-rw-r--r--. 2 root root 0 Jul 1 15:17 test1
-rw-r--r--. 2 root root 0 Jul 1 15:19 test3
-rw-r--r--. 2 root root 0 Jul 1 15:19 test4
[[email protected] ~]#
ここで、server1.example.comの/ dataディレクトリをもう一度見てください。変更がそのノードに複製されていることがわかります:
server1.example.com:
ls -l /data
[[email protected] ~]# ls -l /data
total 8
-rw-r--r--. 2 root root 0 Jul 1 15:17 test1
-rw-r--r--. 2 root root 0 Jul 1 15:19 test3
-rw-r--r--. 2 root root 0 Jul 1 15:19 test4
[[email protected] ~]#
6つのリンク
- GlusterFS:http://www.gluster.org/
- GlusterFS 3.2ドキュメント:http://download.gluster.com/pub/gluster/glusterfs/3.2/Documentation/AG/html/index.html
- CentOS:http://www.centos.org/