Heartbeat+Drbd+Mysql高可用(HA)集羣架構的部署

主機環境 redhat6.5 64位node

實驗環境 服務端1 ip 172.25.25.111   主機名:server1.example.com     mysql

     服務端2 ip172.25.25.112    主機名:server2.example.com算法

安裝包   heartbeat-3.0.4-2.el6.x86_64.rpm       sql

     heartbeat-devel-3.0.4-2.el6.x86_64.rpmshell

  ldirectord-3.9.5-3.1.x86_64.rpmvim

  heartbeat-libs-3.0.4-2.el6.x86_64.rpmapi

  drbd-8.4.3.tar.gzbash

防火牆狀態:關閉   app


    前面的博文中提過mysql的源碼安裝和drbd的內核模塊的添加,有些報錯的解決、安裝、測試這裏再也不重複,只是稍微提一下,感興趣的能夠看前面的博文socket


1.安裝heartbeat、修改主配置文件及測試

1.安裝heartbeat、修改主配置文件(服務端1)

[root@server1 mnt]# ls    #安裝包

heartbeat-3.0.4-2.el6.x86_64.rpm      heartbeat-devel-3.0.4-2.el6.x86_64.rpm ldirectord-3.9.5-3.1.x86_64.rpm

heartbeat-libs-3.0.4-2.el6.x86_64.rpm

[root@server1 mnt]# yum install * -y        #安裝/mnt全部

[root@server1 mnt]# cd /usr/share/doc/heartbeat-3.0.4/     #切換

[root@server1 heartbeat-3.0.4]# ls

apphbd.cf  authkeys  AUTHORS ChangeLog  COPYING  COPYING.LGPL ha.cf  haresources  README

[root@server1 heartbeat-3.0.4]# cp ha.cf haresources authkeys/etc/ha.d/    #拷貝主配置文件、資源配置文件、認證文件到指定目錄

[root@server1 heartbeat-3.0.4]# cd /etc/ha.d/

[root@server1 ha.d]# ls

authkeys  ha.cf  harc haresources  rc.d  README.config resource.d  shellfuncs

[root@server1 ha.d]# vim ha.cf  #進入主配置文件

 34 logfacility     local0

 48 keepalive 2

 56 deadtime 30

 61 warntime 10

 71 initdead 60

 76 udpport 719     #udp協議端口號

 91 bcast   eth0           

157 auto_failback on

#結點主機名,那個寫在前面那個就是主,另外一個就是備,以下:服務端1是主,服務端2是備

211 node   server1.example.com    

212 node   server2.example.com

220 ping 172.25.25.250

253 respawn hacluster /usr/lib64/heartbeat/ipfail

259 apiauth ipfail gid=haclient uid=hacluster

[root@server1 ha.d]# vim haresources

150 server1.example.com IPaddr::172.25.25.100/24/eth0 httpd     #主機名是主結點的主機名、添加虛擬ip、httpd服務

[root@server1 ha.d]# vim authkeys  #進入認證文件

 23 auth 1          #認證

 24 1 crc           #認證方式crc

root@server1 ha.d]# chmod 600 authkeys      #修改認證文件的權限

[[root@server1 ha.d]# /etc/init.d/heartbeat start       #開啓heartbeat

 

服務端2和服務端1的配置徹底相同,能夠在服務端2安裝好heartbeat的狀況下,將服務端1配置好的文件考過去,放在相同的目錄下,而後啓動服務端2的heartbeat服務,以下;

[root@server1 ha.d]# scp ha.cf haresources authkeys root@172.25.25.112:/etc/ha.d/  #拷貝

root@172.25.25.112's password:

 

[root@server2 ha.d]# /etc/init.d/heartbeat start   #啓動(服務端2)

 

在測試以前,服務端1和服務端2要安裝httpd且有內容不一樣的測試頁。注意:不要手動啓動httpd,系統會自動啓動。

 

2.測試 172.25.25.100

wKiom1f7UAbygGe_AAARe-ZGn0U881.png

 

[root@server1 ha.d]# /etc/init.d/httpd stop     #將服務端1的httpd中止,測試

Stopping httpd:                                           [  OK  ]

wKiom1f7UAazMr_CAACQWQopcc0528.png

 

[root@server1 ha.d]# /etc/init.d/httpd start        #開啓httpd

Starting httpd:                                           [  OK  ]

wKioL1f7UAfh2AUpAAASNLiEDTM957.png

 

2.編譯、安裝drbd內核模塊及測試

 1.編譯、安裝drbd內核模塊

[root@server1 mnt]# ls

drbd-8.4.3.tar.gz   

[root@server1 mnt]# tar zxf drbd-8.4.3.tar.gz       #解壓

[root@server1 mnt]# ls

drbd-8.4.3           drbd-8.4.3.tar.gz

[root@server1 mnt]# cd drbd-8.4.3

[root@server1 drbd-8.4.3]# ./configure --enable-spec --with-km     

[root@server1 drbd-8.4.3]# rpmbuild -bb drbd.spec       

error: File /root/rpmbuild/SOURCES/drbd-8.4.3.tar.gz: No suchfile or directory

[root@server1 drbd-8.4.3]# cp /mnt/drbd-8.4.3.tar.gz/root/rpmbuild/SOURCES/

[root@server1 drbd-8.4.3]# rpmbuild -bb drbd.spec

[root@server1 drbd-8.4.3]# rpmbuild -bb drbd-km.spec


[root@server1 drbd-8.4.3]# cd /root/rpmbuild/RPMS/x86_64/      #切換目錄

[root@server1 x86_64]# ls       #生成10個安裝包

drbd-8.4.3-2.el6.x86_64.rpm

drbd-bash-completion-8.4.3-2.el6.x86_64.rpm

drbd-debuginfo-8.4.3-2.el6.x86_64.rpm

drbd-heartbeat-8.4.3-2.el6.x86_64.rpm

drbd-km-2.6.32_431.el6.x86_64-8.4.3-2.el6.x86_64.rpm

drbd-km-debuginfo-8.4.3-2.el6.x86_64.rpm

drbd-pacemaker-8.4.3-2.el6.x86_64.rpm

drbd-udev-8.4.3-2.el6.x86_64.rpm

drbd-utils-8.4.3-2.el6.x86_64.rpm

drbd-xen-8.4.3-2.el6.x86_64.rpm

[root@server1 x86_64]# yum install * -y    #安裝全部的包

[root@server1 x86_64]# scp * root@172.25.25.112:/mnt       #將包傳給服務端2

[root@server2 mnt]# rpm -vih *          #安裝

Preparing...               ########################################### [100%]

   1:drbd-utils            ########################################### [ 10%]

  2:drbd-bash-completion  ########################################### [ 20%]

   3:drbd-heartbeat        ########################################### [ 30%]

   4:drbd-pacemaker        ########################################### [ 40%]

   5:drbd-udev             ########################################### [ 50%]

   6:drbd-xen              ########################################### [ 60%]

   7:drbd                   ###########################################[ 70%]

  8:drbd-km-2.6.32_431.el6.########################################### [80%]

  9:drbd-km-debuginfo     ########################################### [ 90%]

  10:drbd-debuginfo         ###########################################[100%]

 

在服務端1和服務端2虛擬機中各添加一塊虛擬磁盤或劃分一個新的分區,而後進行下面的步驟:

 

[root@server1 x86_64]# cd /etc/drbd.d/     #切換到drbd的主配置文件目錄

[root@server1 drbd.d]# vim dbdata.res     #建立一個文件,後綴必須是.res

  1 resource dbdata{

  2 meta-disk internal;

  3 device /dev/drbd1;

  4 syncer {

  5 verify-alg sha1;        #設置主備機之間通訊使用的信息算法

  6 }

#每一個主機的說明以"on"開頭,後面是主機名.在後面的{}中爲這個主機的配置

  7 on server1.example.com{     #主機名

  8 disk /dev/vdb;             #磁盤名稱

  9 address172.25.29.1:7789;      #ip加端口,端口是指定的

 10 }

 11 onserver2.example.com{

 12 disk /dev/vdb;

 13 address172.25.29.2:7789;

 14 }

 15 }

 

[root@server1 drbd.d]# scp dbdata.resroot@172.25.29.2:/etc/drbd.d/

root@172.25.29.2's password:

#服務端1和服務端2同時初始化 ,同時開啓drbd

[root@server1 drbd.d]# drbdadm create-md dbdata    #初始化

  --==  Thank you for participating in the globalusage survey  ==--

The server's response is:

 

Writing meta data...

initializing activity log

NOT initializing bitmap

New drbd meta data block successfully created.

 

[root@server2 drbd.d]# drbdadm create-md dbdata

  --==  Thank you for participating in the globalusage survey  ==--

The server's response is:

 

Writing meta data...

initializing activity log

NOT initializing bitmap

New drbd meta data block successfully created.

 

[root@server1 drbd.d]# /etc/init.d/drbd start       #開啓drbd

[root@server2 drbd.d]# /etc/init.d/drbd start

 

[root@server1 drbd.d]# cat /proc/drbd   #查看

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-08 15:10:25

 

 1: cs:Connectedro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----

    ns:0 nr:0 dw:0 dr:0al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:2097052 

 

[root@server2 drbd.d]# cat /proc/drbd

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-08 15:10:25

 

 1: cs:Connectedro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----

    ns:0 nr:0 dw:0 dr:0al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:2097052

#從上面能夠看出兩個都是secondary

 

[root@server1 drbd.d]# drbdadm primary dbdata --force   #強制使服務端1變成primary

[root@server1 drbd.d]# cat /proc/drbd      #查看,服務端1和服務端2正在同步

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-08 15:10:25

 

 1: cs:SyncSource ro:Primary/Secondaryds:UpToDate/Inconsistent C r-----

    ns:496640 nr:0 dw:0dr:497304 al:0 bm:30 lo:0 pe:4 ua:0 ap:0 ep:1 wo:f oos:1604508

    [===>................]sync'ed: 23.7% (1604508/2097052)K

    finish: 0:00:16 speed:98,508 (98,508) K/sec

 

[root@server1 drbd.d]# cat /proc/drbd

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-08 15:10:25

 

 1: cs:SyncSourcero:Primary/Secondary ds:UpToDate/Inconsistent C r---n-

    ns:1566436 nr:0 dw:0dr:1569432 al:0 bm:94 lo:0 pe:16 ua:3 ap:0 ep:1 wo:f oos:546716

    [=============>......]sync'ed: 74.1% (546716/2097052)K

    finish: 0:00:08 speed:64,596 (64,596) K/sec

 

[root@server1 drbd.d]# cat /proc/drbd   #同步完成,服務端1爲primary

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-08 15:10:25

 

 1: cs:Connectedro:Primary/Secondary ds:UpToDate/UpToDate C r-----

    ns:2097052 nr:0 dw:0dr:2097716 al:0 bm:128 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

 

[root@server2 drbd.d]# cat /proc/drbd

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-08 15:10:25

 

 1: cs:Connectedro:Secondary/Primary ds:UpToDate/UpToDate C r-----

    ns:0 nr:2097052dw:2097052 dr:0 al:0 bm:128 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[root@server1 drbd.d]# mkfs.ext4 /dev/drbd1     #格式化

  

 

3.將drdb、mysql寫進heartbeat的文件裏且測試

1.將drdb、mysql寫進heartbeat的文件(服務端1)

[root@server1 ~]# yum install mysql-server -y   #服務端1和服務端2都要安裝mysql,不要手動啓動    

[root@server1 ~]# cat /proc/drbd  #服務端1和服務端2要同爲secondary

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build byroot@server1.example.com, 2016-10-02 15:19:31

 

 1: cs:Connectedro:Secondary/Secondary ds:UpToDate/UpToDate C r-----

ns:171868 nr:0 dw:0dr:171868 al:0 bm:18 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[root@server1 ~]# cd /etc/ha.d/      #切換到heartbeat的配置文件路徑

[root@server1 ha.d]# vim haresources  #進入

150 server1.example.com IPaddr::172.25.25.100/24/eth0drbddisk::dbdata Filesystem::/dev/drbd1::/var/lib/mysql::ext4 mysqld  #將/dev/drbd1掛載到/var/lib/mysql目錄下,開啓mysql

[root@server1 ~]# /etc/init.d/heartbeat stop   #中止heartbeat

Stopping High-Availability services: Done.

 

[root@server1 ~]# /etc/init.d/heartbeat status   #查看狀態

heartbeat is stopped. No process

[root@server1 ~]# /etc/init.d/heartbeat start

Starting High-Availability services: INFO:  Resource is stopped

Done.

[root@server1 ~]# /etc/init.d/heartbeat start    #開啓heartbeat

Starting High-Availability services: INFO:  Resource is stopped

Done.

[root@server1 ha.d]# scp haresourcesroot@172.25.25.112:/etc/ha.d/

root@172.25.25.112's password:

 

服務端2

[root@server2 ha.d]# /etc/init.d/heartbeat stop

Stopping High-Availability services: Done.

 

[root@server2 ha.d]# /etc/init.d/heartbeat start

Starting High-Availability services: INFO:  Resource is stopped

Done.

 

2.測試

[root@server3 ~]# ping 172.25.25.100    #ping通了

64 bytes from 172.25.29.100: icmp_seq=1 ttl=64 time=0.485 ms

64 bytes from 172.25.29.100: icmp_seq=2 ttl=64 time=0.292 ms

64 bytes from 172.25.29.100: icmp_seq=3 ttl=64 time=0.289 ms

[root@server3 ~]# arp -an|grep 172.25.25.100   #查看ip

? (172.25.25.100) at 52:54:00:ec:8b:36 [ether] on eth0

[root@server1 ~]# ip addr show eth0     #和服務端1的同樣

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast state UP qlen 1000

    link/ether52:54:00:ec:8b:36 brd ff:ff:ff:ff:ff:ff

    inet 172.25.25.111/24brd 172.25.25.255 scope global eth0

    inet 172.25.25.100/24brd 172.25.25.255 scope global secondary eth0

    inet6fe80::5054:ff:feec:8b36/64 scope link

       valid_lft foreverpreferred_lft forever

[root@server1 ~]# df      #磁盤也掛載上了

Filesystem                  1K-blocks    Used Available Use%Mounted on

/dev/mapper/VolGroup-lv_root  7853764 1290388   6164428  18% /

tmpfs                          510200       0    510200  0% /dev/shm

/dev/vda1                      495844   33467    436777  8% /boot

/dev/drbd1                    4128284   95176   3823404  3% /var/lib/mysql

[root@server1 ~]# mysql     #mysql也打開了

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.00 sec)

[root@server2 ha.d]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server throughsocket '/var/lib/mysql/mysql.sock' (2)

 

[root@server1 ~]# /etc/init.d/heartbeat stop     #當服務端1的heartbeat中止以後

Stopping High-Availability services: Done.

[root@server1 ~]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server throughsocket '/var/lib/mysql/mysql.sock' (2)

 

[root@server3 ~]# arp -an|grep 172.25.25.100     #查看ip

? (172.25.25.100) at 52:54:00:85:1a:3b [ether] on eth0

[root@server2 ha.d]# ip addr show eth0      #服務端2在服務

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast state UP qlen 1000

    link/ether52:54:00:85:1a:3b brd ff:ff:ff:ff:ff:ff

    inet 172.25.25.112/24brd 172.25.25.255 scope global eth0

    inet6fe80::5054:ff:fe85:1a3b/64 scope link

       valid_lft foreverpreferred_lft forever

[root@server2 ha.d]# df        #掛載上了

Filesystem                  1K-blocks    Used Available Use%Mounted on

/dev/mapper/VolGroup-lv_root  7853764 1188980   6265836  16% /

tmpfs                          510200       0   510200   0% /dev/shm

/dev/vda1                      495844   33467    436777  8% /boot

/dev/drbd1                    4128284   95176   3823404  3% /var/lib/mysql

 

[root@server1 ~]# /etc/init.d/heartbeat start      #當服務端1的heartbeat啓動以後

Starting High-Availability services: INFO:  Resource is stopped

Done.

[root@server3 ~]# arp -an|grep 172.25.25.100     #又回到了服務端1

? (172.25.25.100) at 52:54:00:ec:8b:36 [ether] on eth0

[root@server1 ~]# ip addr show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdiscpfifo_fast state UP qlen 1000

    link/ether52:54:00:ec:8b:36 brd ff:ff:ff:ff:ff:ff

    inet 172.25.25.111/24brd 172.25.25.255 scope global eth0

    inet 172.25.25.100/24brd 172.25.25.255 scope global secondary eth0

    inet6 fe80::5054:ff:feec:8b36/64scope link

       valid_lft foreverpreferred_lft forever

相關文章
相關標籤/搜索