LoginSignup
4
5

More than 5 years have passed since last update.

Vagrantを使ってDRBD+pacemaker+corosyncによるHA構成を構築する (その1: DRBDのインストール~設定)

Posted at

Vagrant上の仮想マシン二台を用いて、DRBD+pacemaker+corosyncによるHA構成を構築したい。
まずはその1として、ディスクミラーリングを行うツールであるDRBDをインストールし、設定を行う。

環境

ホスト

  • Vagrant 1.7.2
  • VirtualBox 4.3.26

ゲスト1

  • OS: CentOS 7.1
  • ホスト名: node01
  • IPアドレス: 192.168.33.101

ゲスト2

  • OS: CentOS 7.1
  • ホスト名: node02
  • IPアドレス: 192.168.33.102

※vagrantを使う場合、仮想マシンにハードディスクを追加しておく必要がある。

Vagrantfile
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # 省略

  config.vm.provider :virtualbox do |vb|
    file_to_disk = "./tmp/disk.vdi"
    if not File.exist?(file_to_disk) then
      vb.customize ["createhd",
                    "--filename", file_to_disk,
                    "--size", 100 * 1024]
    end
    vb.customize ['storageattach', :id,
                  '--storagectl', 'SATA Controller',
                  '--port', 1,
                  '--device', 0,
                  '--type', 'hdd',
                  '--medium', file_to_disk]  
  end
  # 省略

end

参考:Vagrant の VM にハードディスクを追加する | CUBE SUGAR STORAGE

構築手順

前準備

ホスト名を設定する。(node01の場合)

$ sudo vi /etc/hosts
127.0.0.1  node01 localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.33.102  node02
$ sudo vi /etc/hostname
node01

ファイアウォールでポート7788を許可しておく。

$ sudo firewall-cmd --permanent --add-port=7788/tcp

インストール

elrepoを追加する。

$ sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
$ sudo vi /etc/yum.repos.d/elrepo.repo

[elrepo]
name=ELRepo.org Community Enterprise Linux Repository - el6
baseurl=http://elrepo.org/linux/elrepo/el6/$basearch/
mirrorlist=http://elrepo.org/mirrors-elrepo.el6
enabled=0                              # 0に変更する
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0

drbdのインストール

$ sudo yum --enablerepo=elrepo install drbd84 kmod-drbd84

パーティション作成

fdiskコマンドでパーティションを作成する。

$ sudo 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 0x76627a10.

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): 1
First sector (2048-209715199, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

作成されたことを確認する。

$ ls /dev/sdb*
/dev/sdb  /dev/sdb1

DRBDの設定

リソースの設定を記述する。

$ sudo vi /etc/drbd.d/disk.res
resource r0 {
        protocol C;

        startup {
                wfc-timeout 120;
        }
        disk {
                on-io-error pass_on;
        }
        on node01 {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.33.101:7788;
                meta-disk internal;
        }
        on node02 {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.33.102:7788;
                meta-disk internal;
        }
}

メタファイルの作成と、自動起動の設定を行う。

$ sudo drbdadm create-md r0
$ sudo systemctl enable drbd.service

ここまでを2台のゲストマシンで行う。

DRBDの起動

まず1台目でDRBDを起動する。

$ sudo systemctl start drbd.service

※前準備のhostsやfirewallの設定をやっておかないとsystemd[1]: Failed to start LSB: Bring up/down networkingのようなエラーが出て起動しない可能性がある。

正常に起動できたら、2台目も起動する。

$ sudo systemctl start drbd.service

正常に起動したことを確認する。

$ sudo /lib/drbd/drbd status
m:res  cs         ro                   ds                         p  mounted  fstype
0:r0   Connected  Secondary/Secondary  Inconsistent/Inconsistent  C

Primaryのノードのみで以下のコマンドを実行する。

$ sudo drbdadm primary r0 --force

これで同期が開始される。同期には若干時間がかかる。最初の時点では以下のようなステータスである。

$ sudo /lib/drbd/drbd status
m:res  cs          ro                   ds                     p  mounted  fstype
...    sync'ed:    8.9%                 (31120/34148)M
0:r0   SyncSource  Secondary/Secondary  UpToDate/Inconsistent  C

一定時間経過後、以下の通りとなる。

$ sudo /lib/drbd/drbd status
m:res  cs         ro                   ds                 p  mounted  fstype
0:r0   Connected  Secondary/Secondary  UpToDate/UpToDate  C

ファイルシステムを作成する。

$ sudo mkfs.ext4 /dev/drbd0

マウントを行う。

$ sudo mkdir /data
$ sudo mount -t ext4 /dev/drbd0 /data

マウントされたことを確認する。

$ sudo /lib/drbd/drbd status
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C  /data     ext4

動作確認を行う。

# Primary側(node01)にて
$ sudo touch /data/test.txt
$ sudo umount /data
$ sudo drbdadm secondary r0

# Secondary側(node02)にて
$ sudo drbdadm primary r0
$ sudo mkdir /data
$ sudo mount -t ext4 /dev/drbd0 /data
$ ls /data/
lost+found  test.txt

test.txtがSecondary側にもミラーリングされている。

参考URL

Pacemaker+Corosync+DRBDを利用したWEBサーバの冗長化 - OSSでLinuxサーバ構築

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5