首先确认heartbeat状态是否正常,有无辅助IP
[root@data-1-1 data]# ip add|egrep "0.17|0.18"
inet 10.0.0.17/24 brd 10.0.0.255 scope global secondary eth0
[root@data-1-2 /]# ip add|egrep "0.17|0.18"
inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0
停止一台drbd高可用并查看:
[root@data-1-1 data]# ip add|egrep "0.17|0.18"
[root@data-1-1 data]#
[root@data-1-2 /]# ip add|egrep "0.17|0.18"
inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0
inet 10.0.0.17/24 brd 10.0.0.255 scope global secondary eth0
[root@data-1-2 /]#
查看两台机器的drbd状态:
[root@data-1-1 /]# cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:8
[root@data-1-2 /]# cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
显示结果为从----从状态
现在需要通过heartbeat管理drbd,将其中一台提升为主状态,需要修改/etc/ha.d/haresources文件
[root@data-1-1 /]# cat /etc/ha.d/haresources
data-1-1 drbddisk::data IPaddr::10.0.0.17/24/eth0
data-1-2 IPaddr::10.0.0.18/24/eth0
[root@data-1-2 /]# cat /etc/ha.d/haresources
data-1-1 drbddisk::data IPaddr::10.0.0.17/24/eth0
data-1-2 IPaddr::10.0.0.18/24/eth0
然后重新启动heartbeat程序:
[root@data-1-1 /]# /etc/init.d/heartbeat restart
Stopping High-Availability services: Done.
Waiting to allow resource takeover to complete:Done.
Starting High-Availability services: INFO: Resource is stopped
Done.
查看状态:
[root@data-1-1 /]# cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:0 nr:0 dw:0 dr:660 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:8
[root@data-1-2 /]# /etc/init.d/heartbeat restart
Stopping High-Availability services: Done.
Waiting to allow resource takeover to complete:Done.
Starting High-Availability services: INFO: Resource is stopped
Done.
查看状态:
[root@data-1-2 /]# cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
drbd要启动好,两边角色都为secondary时,启动heartbeat,则它可以帮你选主:
根据/etc/ha.d/haresources里面你设置的参数drbddisk::data来选择。
自动挂载/dev/drbd0,则需要在/etc/ha.d/haresources里面配置参数
[root@data-1-2 ~]# cat /etc/ha.d/haresources
data-1-1 drbddisk::data Filesystem::/dev/drbd0::/data::ext4 IPaddr::10.0.0.17/24/eth0
data-1-2 IPaddr::10.0.0.18/24/eth0
Filesystem::/dev/drbd0::/data::ext4 <===========>mount /dev/drbd0 /data 等价
本文转自陈继松 51CTO博客,原文链接:http://blog.51cto.com/chenjisong/1718539,如需转载请自行联系原作者