ストレージ · 5 min read · Nov 29, 2025
CentOS 7でのGlusterFSによる高可用性ストレージ - 2つのストレージサーバー間のミラー
このチュートリアルでは、GlusterFSを使用した2つのストレージサーバー(CentOS 7.2)で高可用性ストレージを設定する方法を示します。各ストレージサーバーは他のストレージサーバーのミラーとなり、ファイルは自動的に両方のストレージサーバーに複製されます。クライアントシステム(CentOS 7.2も同様)は、ローカルファイルシステムのようにストレージにアクセスできます。GlusterFSは、数ペタバイトにスケール可能なクラスターファイルシステムです。これは、Infiniband RDMAまたはTCP/IPインターコネクトを介してさまざまなストレージブリックを1つの大規模な並列ネットワークファイルシステムに集約します。ストレージブリックは、SATA-II RAIDおよびInfiniband HBAを備えたx86_64サーバーなどの一般的なハードウェアで構成できます。
1 前提条件
このチュートリアルでは、3つのシステム、2つのサーバー、および1つのクライアントを使用します:
- server1.example.com: IPアドレス 192.168.0.100 (サーバー)
- server2.example.com: IPアドレス 192.168.0.101 (サーバー)
- client1.example.com: IPアドレス 192.168.0.102 (クライアント)
すべてのシステムは、他のシステムのホスト名を解決できる必要があります。これがDNSを介して行えない場合は、/etc/hostsファイルを編集して、すべてのシステムで次のようにします:
nano /etc/hosts127.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システムでEPEL 7リポジトリを有効にします:
yum -y install epel-releaseyum -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 update3 GlusterFSサーバーの設定
server1.example.com/server2.example.com:
GlusterFSはCentOSストレージ特別興味グループのリポジトリにあります。このコマンドでリポジトリをインストールします:
yum -y install centos-release-gluster次に、以下のようにGlusterFSサーバーをインストールします:
yum -y install glusterfs-serverGlusterデーモンのシステム起動リンクを作成し、起動します:
systemctl enable glusterd.service
systemctl start glusterd.serviceコマンド
glusterfsd --versionは、インストールしたばかりのGlusterFSのバージョン(この場合は3.7.12)を表示するはずです:
[root@server1 ~]# 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.
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-(すべてのボリュームにわたるブリックの数)がserver1.example.comおよびserver2.example.comで開いていることを確認してください。
次に、server2.example.comを信頼されたストレージプールに追加する必要があります(すべてのGlusterFS設定コマンドをserver1.example.comから実行していますが、server2.example.comから実行することもできます。設定はGlusterFSノード間で複製されるため、正しいホスト名またはIPアドレスを使用していることを確認してください):
server1.example.com:
server1.example.comで、次のコマンドを実行します。
gluster peer probe server2.example.com[root@server1 ~]# gluster peer probe server2.example.com
peer probe: success.信頼されたストレージプールのステータスは、次のようになります:
gluster peer status[root@server1 ~]# gluster peer statusNumber of Peers: 1Hostname: server2.example.com
Uuid: 582e10da-aa1b-40b8-908c-213f16f57fe5
State: Peer in Cluster (Connected)次に、/dataディレクトリにserver1.example.comおよびserver2.example.comで2つのレプリカを持つtestvolという名前の共有を作成します(この場合、レプリカの数はサーバーの数と等しくなります。ミラーリングを設定したいためです):
gluster volume create testvol replica 2 transport tcp server1.example.com:/data server2.example.com:/data force[root@server1 ~]# 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
[root@server1 ~]#ボリュームを開始します:
gluster volume start testvol結果は次のようになります:
[root@server1 ~]# gluster volume start testvol
volume start: testvol: success
[root@server1 ~]#上記のコマンドが成功しなかったと表示される場合があります:
[root@server1 ~]# gluster volume start testvol
Starting volume testvol has been unsuccessful
[root@server1 ~]#この場合、両方のサーバーで…
server1.example.com/server2.example.com:
netstat -tap | grep glusterfsdの出力を確認してください。
出力が次のようになる場合…
[root@server1 ~]# 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
[root@server1 ~]#…すべては正常ですが、出力がない場合…
[root@server2 ~]# netstat -tap | grep glusterfsd
[root@server2 ~]#…対応するサーバー(この場合はserver2.example.com)でGlusterFSデーモンを再起動します:
server2.example.com:
systemctl restart glusterd.service次に、…
netstat -tap | grep glusterfsdの出力を再度確認します - これで次のようになるはずです:
[root@server2 ~]# 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
[root@server2 ~]#次にserver1.example.comに戻ります:
server1.example.com:
ボリュームのステータスを確認するには、次のコマンドを使用します。
gluster volume info[root@server1 ~]# 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:
performance.readdir-ahead: on
[root@server1 ~]#デフォルトでは、すべてのクライアントがボリュームに接続できます。client1.example.com(= 192.168.1.102)のみへのアクセスを許可したい場合は、次のコマンドを実行します:
gluster volume set testvol auth.allow 192.168.1.102IPアドレスにワイルドカード(192.168.*のような)を使用することができ、カンマで区切って複数のIPアドレスを指定することも可能です(例:192.168.1.102,192.168.1.103)。
ボリューム情報は、更新されたステータスを表示するはずです:
gluster volume info[root@server1 ~]# gluster volume infoVolume 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
[root@server1 ~]#4 GlusterFSクライアントの設定
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[root@client1 ~]# 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)
[root@client1 ~]#…と…
df -h[root@client1 ~]# 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
[root@client1 ~]#クライアントでGlusterFS共有を手動でマウントする代わりに、/etc/rc.localファイルにマウントコマンドを追加します。/etc/fstabには追加しません。rc.localは常にネットワークが立ち上がった後に実行されるため、ネットワークファイルシステムには必要です。
/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…と…
mount5 テスト
では、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[root@server1 ~]# 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
[root@server1 ~]次に、server1.example.comをシャットダウンし、client1.example.comのGlusterFS共有にいくつかのファイルを追加/削除します。
server1.example.com:
shutdown -h nowclient1.example.com:
touch /mnt/glusterfs/test3
touch /mnt/glusterfs/test4
rm -f /mnt/glusterfs/test2コマンドの実行には時間がかかる場合があります。Glusterfsはserver1に到達できなくなるとserver2に切り替えます。これにより、サーバー1がオフラインのときでもデータストレージ共有で作業を続けることができるため、システムのフォールトトレランスが確認できます。変更はserver2.example.comの/dataディレクトリに表示されるはずです:
server2.example.com:
ls -l /data[root@server2 ~]# 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 test4server1.example.comを再起動し、/dataディレクトリを確認します:
server1.example.com:
ls -l /data[root@server1 ~]# 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
[root@server1 ~]#ご覧のとおり、server1.example.comは自動的に変更を同期しました。変更がまだ同期されていない場合は、クライアントのGlusterFS共有でリードコマンドを実行するだけで簡単に修正できます。例えば:
client1.example.com:
ls -l /mnt/glusterfs/[root@client1 ~]# 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
[root@server1 ~]#再度、server1.example.comの/dataディレクトリを確認すると、変更がそのノードに複製されていることがわかります:
server1.example.com:
ls -l /data[root@server1 ~]# 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
[root@server1 ~]#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/
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。