DRBD インストール手順

2019/08/10 R1.0

目的：MySQLをクラスタ化
実現案：DRBD + Pacemaker
内容：DRBD のインストール手順
　　　※設定は基本的な正常性確認の範囲内※


```
fdisk -l
//
Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
//

yum install -y http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
//
Loaded plugins: fastestmirror
elrepo-release-7.0-3.el7.elrepo.noarch.rpm               | 8.5 kB     00:00
Examining /var/tmp/yum-root-GOnmN0/elrepo-release-7.0-3.el7.elrepo.noarch.rpm: elrepo-release-7.0-3.el7.elrepo.noarch
Marking /var/tmp/yum-root-GOnmN0/elrepo-release-7.0-3.el7.elrepo.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package elrepo-release.noarch 0:7.0-3.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package  Arch   Version          Repository                               Size
================================================================================
Installing:
 elrepo-release
          noarch 7.0-3.el7.elrepo /elrepo-release-7.0-3.el7.elrepo.noarch 5.2 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 5.2 k
Installed size: 5.2 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : elrepo-release-7.0-3.el7.elrepo.noarch                       1/1
  Verifying  : elrepo-release-7.0-3.el7.elrepo.noarch                       1/1

Installed:
  elrepo-release.noarch 0:7.0-3.el7.elrepo

Complete!
//

vi /etc/yum.repos.d/elrepo.repo
//
enabled=1
↓（変更）
enabled=0
//

yum search --enablerepo=elrepo drbd
//

//
============================== N/S matched: drbd ===============================
drbd84-utils.x86_64 : Management utilities for DRBD
drbd84-utils-sysvinit.x86_64 : The SysV initscript to manage the DRBD.
drbd90-utils.x86_64 : Management utilities for DRBD
drbd90-utils-sysvinit.x86_64 : The SysV initscript to manage the DRBD.
kmod-drbd84.x86_64 : drbd84 kernel module(s)
kmod-drbd90.x86_64 : drbd90 kernel module(s)
//

yum install -y --enablerepo=elrepo drbd90-utils kmod-drbd90
//
Dependencies Resolved

================================================================================
 Package            Arch         Version                     Repository    Size
================================================================================
Installing:
 drbd90-utils       x86_64       9.3.1-1.el7.elrepo          elrepo       680 k
 kmod-drbd90        x86_64       9.0.14-1.el7_5.elrepo       elrepo       266 k

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 947 k
Installed size: 2.6 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/elrepo/packages/drbd90-utils-9.3.1-1.el7.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Public key for drbd90-utils-9.3.1-1.el7.elrepo.x86_64.rpm is not installed
(1/2): drbd90-utils-9.3.1-1.el7.elrepo.x86_64.rpm          | 680 kB   00:00
(2/2): kmod-drbd90-9.0.14-1.el7_5.elrepo.x86_64.rpm        | 266 kB   00:07
--------------------------------------------------------------------------------
Total                                              129 kB/s | 947 kB  00:07
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Importing GPG key 0xBAADAE52:
 Userid     : "elrepo.org (RPM Signing Key for elrepo.org) <secure@elrepo.org>"
 Fingerprint: 96c0 104f 6315 4731 1e0b b1ae 309b c305 baad ae52
 Package    : elrepo-release-7.0-3.el7.elrepo.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : drbd90-utils-9.3.1-1.el7.elrepo.x86_64                       1/2
  Installing : kmod-drbd90-9.0.14-1.el7_5.elrepo.x86_64                     2/2
Working. This may take some time ...
Done.
  Verifying  : kmod-drbd90-9.0.14-1.el7_5.elrepo.x86_64                     1/2
  Verifying  : drbd90-utils-9.3.1-1.el7.elrepo.x86_64                       2/2

Installed:
  drbd90-utils.x86_64 0:9.3.1-1.el7.elrepo
  kmod-drbd90.x86_64 0:9.0.14-1.el7_5.elrepo

Complete!
//


mv -i /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.sample
cat > /etc/drbd.d/global_common.conf
global {
    usage-count no;
}
common {
 net {
    protocol C;
    }
}
(^D)

cat /etc/drbd.d/global_common.conf
//
global {
    usage-count no;
}
common {
 net {
    protocol C;
    }
}
//

ls /etc/drbd.d/drbd0.res
//
ls: cannot access /etc/drbd.d/drbd0.res: No such file or directory
//

cat > /etc/drbd.d/drbd0.res
resource drbd0 {
    disk /dev/sdb;
    device /dev/drbd0;
    meta-disk internal;
    on cluster01 {
        address 172.16.0.1:7789;
    }
    on cluster02 {
        address 172.16.0.2:7789;
    }
}
(^D)

cat /etc/drbd.d/drbd0.res
//
resource drbd0 {
    disk /dev/sdb;
    device /dev/drbd0;
    meta-disk internal;
    on cluster01 {
        address 172.16.0.1:7789;
    }
    on cluster02 {
        address 172.16.0.2:7789;
    }
}
//

drbdadm create-md drbd0
//
initializing activity log
initializing bitmap (256 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.
//

systemctl start drbd
systemctl enable drbd

(cluster01 only)
drbdadm primary drbd0 --force

drbdadm status drbd0
//
drbd0 role:Primary
  disk:UpToDate
  cluster02 role:Secondary★
    replication:SyncSource peer-disk:Inconsistent★ done:5.09
//

drbdadm status drbd0
//
drbd0 role:Primary
  disk:UpToDate
  cluster02 role:Secondary
    replication:SyncSource peer-disk:Inconsistent done:22.35★
//

drbdadm status drbd0
//
drbd0 role:Primary
  disk:UpToDate
  cluster02 role:Secondary congested:yes
    replication:SyncSource peer-disk:Inconsistent done:71.65★
//

drbdadm status drbd0
//
drbd0 role:Primary
  disk:UpToDate
  cluster02 role:Secondary
    replication:SyncSource peer-disk:Inconsistent done:93.40
//

drbdadm status drbd0
//
drbd0 role:Primary
  disk:UpToDate
  cluster02 role:Secondary
    peer-disk:UpToDate
//

mkfs.xfs /dev/drbd0
//
meta-data=/dev/drbd0             isize=512    agcount=4, agsize=524270 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2097079, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
//

mount /dev/drbd0 /mnt
touch /mnt/testfile
ls -al /mnt/testfile
//
-rw-r--r-- 1 root root 0 Jun 24 18:29 /mnt/testfile
//

umount /mnt

drbdadm secondary drbd0

(cluster02)
drbdadm primary drbd0

drbdadm status
//
drbd0 role:Primary
  disk:UpToDate
  cluster01 role:Secondary
    peer-disk:UpToDate
//

mount /dev/drbd0 /mnt

ls -al /mnt
//
-rw-r--r--   1 root root   0 Jun 24 18:29 testfile
//

touch /mnt/testfile2

ls -l /mnt/
//
-rw-r--r-- 1 root root 0 Jun 24 18:29 testfile
-rw-r--r-- 1 root root 0 Jun 24 18:31 testfile2
//

umount /mnt
drbdadm secondary drbd0

(cluster01)
drbdadm primary drbd0

mount /dev/drbd0 /mnt

ls -l /mnt
//
-rw-r--r-- 1 root root 0 Jun 24 18:29 testfile
-rw-r--r-- 1 root root 0 Jun 24 18:31 testfile2
//

```
（以上）