设为首页 收藏本站
查看: 1306|回复: 0

[经验分享] Heartbeat+Drbd实现

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-9-27 08:54:29 | 显示全部楼层 |阅读模式
继续之前的操作,在drbd部署完成之后,将drbd和heartbeat结合起来,实现drbd服务的高可用,并在主节点完成自动挂载,且能够做到故障自动切换。
按照之前的部署,只需要修改heartbeat中的资源,也即修改/etc/init.d/haresources文件的内容。
1、准备工作
注意:在配置drbd高可用之前,需要保证drbd服务是启动的,而且要实现两端都是secondary的状态,如下:

[iyunv@heartbeat01 ~]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37
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:0
所以,需要在两个drbd节点上都把drbd设置为开机自动启动。
1
2
/etc/init.d/drbd start
chkconfig drbd on



在上述工作完成之后,修改haresources文件,内容如下所示:
[iyunv@heartbeat01 ~]# tail -1 /etc/ha.d/haresources
heartbeat01.contoso.com  IPaddr::172.16.49.100/24/eth1 drbddisk::test Filesystem::/dev/drbd0::/data::ext4
#这里以heartbeat01为例,heartbeat02的配置和heartbeat01保持一致

2、启动heartbeat
然后,两个节点同时启动heartbeat服务,

/etc/init.d/heartbeat start
3、观察两个节点的服务
1)下面是节点1(heartbeat01)上的状态:
[iyunv@heartbeat01 ~]# ip a |grep 49.100
    inet 172.16.49.100/24 brd 172.16.49.255 scope global secondary eth1
可以看到,节点1(heartbeat01)已经获取了VIP。
[iyunv@heartbeat01 ~]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:4 nr:0 dw:4 dr:709 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
而且,heartbeat01是drbd中的Primary节点。
[iyunv@heartbeat01 ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/drbd0 on /data type ext4 (rw)
heartbeat01已经自动挂载/dev/drbd0到/data下。
[iyunv@heartbeat01 ~]# ls /data
10.txt  1.txt   29.txt  38.txt  47.txt  56.txt  65.txt  74.txt  83.txt  92.txt
11.txt  20.txt  2.txt   39.txt  48.txt  57.txt  66.txt  75.txt  84.txt  93.txt
12.txt  21.txt  30.txt  3.txt   49.txt  58.txt  67.txt  76.txt  85.txt  94.txt
13.txt  22.txt  31.txt  40.txt  4.txt   59.txt  68.txt  77.txt  86.txt  95.txt
14.txt  23.txt  32.txt  41.txt  50.txt  5.txt   69.txt  78.txt  87.txt  96.txt
15.txt  24.txt  33.txt  42.txt  51.txt  60.txt  6.txt   79.txt  88.txt  97.txt
16.txt  25.txt  34.txt  43.txt  52.txt  61.txt  70.txt  7.txt   89.txt  98.txt
17.txt  26.txt  35.txt  44.txt  53.txt  62.txt  71.txt  80.txt  8.txt   99.txt
18.txt  27.txt  36.txt  45.txt  54.txt  63.txt  72.txt  81.txt  90.txt  9.txt
19.txt  28.txt  37.txt  46.txt  55.txt  64.txt  73.txt  82.txt  91.txt  lost+found
同时,之前drbd同步的文件也都在。
2)下面是节点1(heartbeat01)上的状态:
[iyunv@heartbeat02 ~]# ip a |grep 49.100
节点2上没有VIP。
[iyunv@heartbeat02 ~]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
    ns:0 nr:4 dw:4 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
节点2(heartbeat02)在drbd中是secondary状态。
[iyunv@heartbeat02 ~]# mount -n
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
同时,heartbeat02也没有挂载/dev/drbd0。
[iyunv@heartbeat02 ~]# ll /data
total 0
当然,/data下面什么都没有。
4、模拟故障切换场景
下面将heartbeat01的heartbeat服务停掉,查看drbd能否自动挂载到heartbeat02上。
[iyunv@heartbeat01 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
1)下面是节点1(heartbeat01)上的状态:
[iyunv@heartbeat01 ~]# ip a|grep 49.100
[iyunv@heartbeat01 ~]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
    ns:16 nr:4 dw:20 dr:1418 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[iyunv@heartbeat01 ~]# ll /data
total 0
2)下面是节点2(heartbeat02)上的状态:
[iyunv@heartbeat02 ~]# ip a |grep 49.100
    inet 172.16.49.100/24 brd 172.16.49.255 scope global secondary eth1
[iyunv@heartbeat02 ~]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:4 nr:16 dw:20 dr:705 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[iyunv@heartbeat02 ~]# ls /data
10.txt  1.txt   29.txt  38.txt  47.txt  56.txt  65.txt  74.txt  83.txt  92.txt
11.txt  20.txt  2.txt   39.txt  48.txt  57.txt  66.txt  75.txt  84.txt  93.txt
12.txt  21.txt  30.txt  3.txt   49.txt  58.txt  67.txt  76.txt  85.txt  94.txt
13.txt  22.txt  31.txt  40.txt  4.txt   59.txt  68.txt  77.txt  86.txt  95.txt
14.txt  23.txt  32.txt  41.txt  50.txt  5.txt   69.txt  78.txt  87.txt  96.txt
15.txt  24.txt  33.txt  42.txt  51.txt  60.txt  6.txt   79.txt  88.txt  97.txt
16.txt  25.txt  34.txt  43.txt  52.txt  61.txt  70.txt  7.txt   89.txt  98.txt
17.txt  26.txt  35.txt  44.txt  53.txt  62.txt  71.txt  80.txt  8.txt   99.txt
18.txt  27.txt  36.txt  45.txt  54.txt  63.txt  72.txt  81.txt  90.txt  9.txt
19.txt  28.txt  37.txt  46.txt  55.txt  64.txt  73.txt  82.txt  91.txt  lost+found
3)检查一下heartbeat02上的日志
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4084]: info: Received shutdown notice from 'heartbeat01.contoso.com'.
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4084]: info: Resources being acquired from heartbeat01.contoso.com.
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4150]: info: acquire local HA resources (standby).
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4150]: info: local HA resource acquisition completed (standby).
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4084]: info: Standby resource acquisition done [all].
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4151]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys heartbeat02.contoso.com] to acquire.
harc(default)[4176]:        2016/09/26_00:32:04 info: Running /etc/ha.d//rc.d/status status
mach_down(default)[4193]:        2016/09/26_00:32:04 info: Taking over resource group IPaddr::172.16.49.100/24/eth1
ResourceManager(default)[4220]:        2016/09/26_00:32:04 info: Acquiring resource group: heartbeat01.contoso.com IPaddr::172.16.49.100/24/eth1 drbddisk::test Filesystem::/dev/drbd0::/data::ext4
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_172.16.49.100)[4248]:        2016/09/26_00:32:04 INFO:  Resource is stopped
ResourceManager(default)[4220]:        2016/09/26_00:32:04 info: Running /etc/ha.d/resource.d/IPaddr 172.16.49.100/24/eth1 start
IPaddr(IPaddr_172.16.49.100)[4373]:        2016/09/26_00:32:04 INFO: Adding inet address 172.16.49.100/24 with broadcast address 172.16.49.255 to device eth1
IPaddr(IPaddr_172.16.49.100)[4373]:        2016/09/26_00:32:04 INFO: Bringing device eth1 up
IPaddr(IPaddr_172.16.49.100)[4373]:        2016/09/26_00:32:04 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-172.16.49.100 eth1 172.16.49.100 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_172.16.49.100)[4347]:        2016/09/26_00:32:04 INFO:  Success
ResourceManager(default)[4220]:        2016/09/26_00:32:04 info: Running /etc/ha.d/resource.d/drbddisk test start
/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[4505]:        2016/09/26_00:32:04 INFO:  Resource is stopped
ResourceManager(default)[4220]:        2016/09/26_00:32:04 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /data ext4 start
Filesystem(Filesystem_/dev/drbd0)[4595]:        2016/09/26_00:32:04 INFO: Running start for /dev/drbd0 on /data
/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_/dev/drbd0)[4587]:        2016/09/26_00:32:04 INFO:  Success
mach_down(default)[4193]:        2016/09/26_00:32:04 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down(default)[4193]:        2016/09/26_00:32:04 info: mach_down takeover complete for node heartbeat01.contoso.com.
Sep 26 00:32:04 heartbeat02.contoso.com heartbeat: [4084]: info: mach_down takeover complete.
Sep 26 00:32:36 heartbeat02.contoso.com heartbeat: [4084]: WARN: node heartbeat01.contoso.com: is dead
Sep 26 00:32:36 heartbeat02.contoso.com heartbeat: [4084]: info: Dead node heartbeat01.contoso.com gave up resources.
Sep 26 00:32:36 heartbeat02.contoso.com heartbeat: [4084]: info: Link heartbeat01.contoso.com:eth1 dead.
Sep 26 00:32:36 heartbeat02.contoso.com ipfail: [4110]: info: Status update: Node heartbeat01.contoso.com now has status dead
Sep 26 00:32:38 heartbeat02.contoso.com ipfail: [4110]: info: NS: We are dead. :<
Sep 26 00:32:38 heartbeat02.contoso.com ipfail: [4110]: info: Link Status update: Link heartbeat01.contoso.com/eth1 now has status dead
Sep 26 00:32:39 heartbeat02.contoso.com ipfail: [4110]: info: We are dead. :<
Sep 26 00:32:39 heartbeat02.contoso.com ipfail: [4110]: info: Asking other side for ping node count.



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-278027-1-1.html 上篇帖子: Heartbeat配置多播方式以及heartbeat安装脚本 下篇帖子: Heartbeat+Drbd+NFS高可用实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表