11/06/2016

Ubuntu : DRBD Pacemaker HA On Ubuntu 16.04 Server

Ubuntu : DRBD Pacemaker HA On Ubuntu 16.04 Server
1. Install ลงทั้ง 2 เครื่อง
  1. sudo apt-get update
  2. sudo apt-get install -y drbd8-utils

2. Set hosts
  1. nano /etc/hosts

เครื่อง ha01
127.0.0.1 localhost
192.168.2.111 ha01
192.168.2.112 ha02

เครื่อง ha02
127.0.0.1 localhost
192.168.2.111 ha01
192.168.2.112 ha02

3. ติดตั้ง ntp ให้ sync. เวลาให้ตรงกัน ทำทั้ง 2 เครื่อง
  1. sudo apt-get install -y ntp
  1. nano /etc/ntp.conf

Add ip ntp server
pool 192.168.2.2

4. Formate HDD sdb1 name HDD โดยใช้คำสั่ง fdisk -l ดู ทำทั้ง 2 เครื่อง (size hdd ต้องมีขนาดเท่ากันเพื่อ sync partition)
อาจจะใช้เวลานานขึ้นอยู่กับขนาด HDD ข้อมูลจะหายหมด (ใช้เวลานานถ้า HDD ขนาดใหญ่)
  1. sudo dd if=/dev/zero of=/dev/sdb1


5. Edit drbd.conf (ทำทั้ง 2 เครื่อง ก่อนทำให้ Copy ไฟล์เดิมไว้ก่อนเสมอ)
  1. nano /etc/drbd.conf
  1. global { usage-count no; }
  2. common { protocol C; }
  3. resource r0 {
  4.     on ha01 {
  5.         device /dev/drbd0;
  6.         disk /dev/sdb1;
  7.         address 192.168.2.111:7788;
  8.         meta-disk internal;
  9.     }
  10.     on ha02 {
  11.         device /dev/drbd0;
  12.         disk /dev/sdb1;
  13.         address 192.168.2.112:7788;
  14.         meta-disk internal;
  15.     }
  16. }


6. Make sure you use the correct IP Address for your hosts and the correct physical partition.
Still working on both systems we need to load the kernel module with:
  1. sudo modprobe drbd


7. Create the mirror device:
  1. sudo drbdadm create-md r0


8. And then bring the mirror device online
  1. sudo drbdadm up r0


9. We can list the new block device with lsblk. Note the major number of 147 for DRBD. To view the status of the mirroring we can use one of the following commands:
  1. lsblk

show 147 DRBD
  1. sudo drbd-overview

show เป็น Secondary ทั้ง 2 เครื่อง
0:r0/0 Connected Secondary/Secondary Inconsistent/Inconsistent

10. We will see both nodes a secondary and the data to be inconsistent. We can correct this by forcing the Primary role on one node. Only do this on one node! (ทำเครื่องเดียวเพื่อให้เป็น Primary) (ใช้เวลานานถ้า HDD ขนาดใหญ่ในการ sync HDD)
  1. sudo drbdadm -- --overwrite-data-of-peer primary r0/0


11. This can take many hours on large disk, a few minutes on this 1 GB disk. To view the progress:
  1. sudo watch cat /proc/drbd

12. Once complete from the Primary node we can format the disk and mount it.
  1. sudo mkfs.ext4 /dev/drbd0
  2. sudo mkdir /DATA
  3. sudo mount /dev/drbd0 /DATA


แล้วสร้างไฟล์ไว้เพื่อทดสอบ

13. Test by.
ใช้คำสั่ง Run ทั้ง 2 เครื่อง เพื่อดูว่าเครื่องไหนเป็นเครื่องหลัก เครื่องรอง
  1. drbd-overview

เครื่องหลัก
0:r0/0 Connected Primary/Secondary UpToDate/UpToDate /DATA ext4 20G 44M 19G 1%

เครื่องรอง
0:r0/0 Connected Secondary/Primary UpToDate/UpToDate

ที่เครื่องหลัก
umount DATA ที่ mount ไว้
  1. umount /DATA

เปลี่ยนจาก เครื่องหลักให้เป็นเครื่องรอง
  1. drbdadm secondary r0


ที่เครื่องรอง
เปลี่ยนจาก เครื่องรองให้เป็นเครื่องหลัก
  1. drbdadm primary r0

mount DATA
  1. mount /dev/drbd0 /DATA


เข้าไปดูข้อมูลข้างในจะมีข้อมูลจากเครื่องหลักมาแสดง
หรือทดสอบด้วยการปิดเครื่องหลัก แล้วทำเครื่องรองให้เป็น primary ก็ได้เช่นกัน

Pacemaker : ทำงาน Auto เมื่อเครื่องหลักเสียไม่สามารถใช้งานได้
1. disable drbd ทั้งสองเครื่อง
  1. sudo systemctl disable drbd

2. We should also unsure the the directory is not mounted and the drbd device is not in use on either node: (ทั้ง 2 เครื่อง)
  1. sudo umount /DATA
  2. sudo drbdadm down r0

3. Then we can install Pacemaker on both nodes:
  1. sudo apt-get install -y pacemaker

4. edit file corosync.conf (สำรองไฟล์เดิมไว้ก่อนเสมอ) ทำทั้ง 2 เครื่องเหมือนกัน
  1. /etc/corosync/corosync.conf

Delete All Code And Replace Code.
  1. totem {
  2.     version: 2
  3.     cluster_name: debian
  4.     secauth: off
  5.     transport:udpu
  6.     interface {
  7.         ringnumber: 0
  8.         bindnetaddr: 192.168.2.2
  9.         broadcast: yes
  10.         mcastport: 5405
  11.     }
  12. }
  13.  
  14. nodelist {
  15.     node {
  16.         ring0_addr: 192.168.2.111
  17.         name: ha01
  18.         nodeid: 1
  19.     }
  20.     node {
  21.         ring0_addr: 192.168.2.112
  22.         name: ha02
  23.         nodeid: 2
  24.     }
  25. }
  26.  
  27.  
  28. quorum {
  29.     provider: corosync_votequorum
  30.     two_node: 1
  31.     wait_for_all: 1
  32.     last_man_standing: 1
  33.     auto_tie_breaker: 0
  34. }


5.Use your IP Addresses and make sure it is the Network address used for the bindnetaddr:
We can then restart corosync and start pacemaker on both nodes:
  1. sudo systemctl restart corosync
  2. sudo systemctl start pacemaker


6. On either host we can use the command crm status to see the cluster come online.
  1. sudo crm status
7. Now we set some properties and create the cluster resources. Typing the command crm configure will take is to an interactive prompt: (ทำที่เครื่องใดเครื่องหนึ่งที่จะให้เริ่มเป็นเครื่องหลัก)
  1. sudo crm configure

And Run Code For Config crm.
  1. property stonith-enabled=false
  1. property no-quorum-policy=ignore
  1. primitive drbd_res ocf:linbit:drbd params drbd_resource=r0 op monitor interval=29s role=Master op monitor interval=31s role=Slave
  1. ms drbd_master_slave drbd_res meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
  1. primitive fs_res ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/DATA fstype=ext4
  1. colocation fs_drbd_colo INFINITY: fs_res drbd_master_slave:Master
  1. order fs_after_drbd mandatory: drbd_master_slave:promote fs_res:start
  1. commit
  1. show
  1. quit


8. Test Pacemaker By
- Close Or shutdown เครื่องหลัก หรือเครื่องใดเครื่องหนึ่ง ข้อมูลจะ Mount ไปที่เครื่องสำรอง อัตโนมัติ 
คำสั่งเช็คสถาน ของเครื่อง
  1. crm_mon

show
  1. crm status

show

การปิดก็เช่นกันถ้าปิดทั้งสองเครื่องเมื่อเปิดเครื่องสำรอง ก็จะ Mount DATA ให้และเปลี่ยนตัวเองเป็นเครื่อง Master ให้อัตโนมัติ

Thank Method This Web :
http://web.theurbanpenguin.com/drbd-pacemaker-ha-cluster-ubuntu-16-04/

ใช้งานใน SCI
1. ติดตั้ง samba ทั้ง 2 server
https://intranet.sci.com/blog.php?u=281&b=654

2. สร้างชื่อ Server เหมือนกันไว้ที่ DNS
เพื่อที่จะให้สามารถเข้าผ่านชื่อได้ตลอด เมื่อเครื่องใดเครื่องหนึ่งเสีย เช่น data แต่คนล่ะ IP

No comments:

Post a Comment