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

[经验分享] Heartbeat学习笔记

[复制链接]

尚未签到

发表于 2019-1-7 09:24:49 | 显示全部楼层 |阅读模式
  

  一、部署环境:

  •   服务器版本:CentOS6.5
  •   双主热备模式:
VIP192.168.3.30MASTER上)
VIP192.168.3.32BACKUP上)

  •   主机网络参数:
接口
MASTERBACKUP说明
eth1192.168.3.23
192.168.3.24内网管理IP
eth2192.168.5.23192.168.5.24心跳线
eth3192.168.2.23192.168.2.24外网(临时下载文件用)


  •   网络拓扑:

  

  二、需求分析:

  通过Heartbeat的高可用功能保证双主VIP同时在线。MySQL01默认绑定VIP:192.168.3.30,MySQL02默认绑定192.168.3.32。任一主机宕机后自动切换。

  

  三、相关配置:

  •   添加心跳线路由:

  1)MySQL01端:
route add -host 192.168.5.24 dev eth2
echo "route add -host 192.168.5.24 dev eth2" >>/etc/rc.local    # 加入到rc.local开机自启,也可修改默认静态路由现实  2)MySQL02端:
route add -host 192.168.5.23 dev eth2
echo "route add -host 192.168.5.23 dev eth2" >>/etc/rc.local

  •   安装heartbeat:
[root@MySQL01 ~]# mkdir tools
[root@MySQL01 ~]# cd tools
[root@MySQL01 tools]# wget
[root@MySQL01 tools]# rpm -ivh epel-release-6-8.noarch.rpm
[root@MySQL01 tools]# yum install heartbeat -y

  •   配置heartbeat:
[root@MySQL01 tools]# cd /usr/share/doc/heartbeat-3.0.4/
[root@MySQL01 heartbeat-3.0.4]# ls
[root@MySQL01 heartbeat-3.0.4]# cp ha.cf haresources authkeys /etc/ha.d/
[root@MySQL01 heartbeat-3.0.4]# ls -ls /etc/ha.d/
[root@MySQL01 heartbeat-3.0.4]# cd /etc/ha.d/

  •   修改HOSTS文件或者配置DNS参数:
  注:由于外网网段192.168.2.0中有DNS服务器,所以在这里就没配HOSTS文件:


  如果没有DNS服务器的话需要手工添加HOST记录,主机名的查看方法:

[root@MySQL01 resource.d]# uname -n
MySQL01.stephenzhou.net
[root@MySQL01 ha.d]# cat /etc/hosts
127.0.0.1       localhost.localdomain   localhost.localdomain   localhost4      localhost4.localdomain4 localhost       MySQL01
::1     localhost.localdomain   localhost.localdomain   localhost6      localhost6.localdomain6 localhost       MySQL01
192.168.2.23 MySQL01.stpehenzhou.net
192.168.2.24 MySQL02.stpehenzhou.net
192.168.3.23 MySQL01.stpehenzhou.net
192.168.3.24 MySQL02.stpehenzhou.net

  •   查看epel是否已经安装好:
[root@MySQL01 resource.d]# rpm -qa|grep epel
epel-release-6-8.noarch

  •   配置heartbeat的三个主要配置文件(ha.cf/haresources/authkeys),完了过后复制到MySQL01及MySQL02的/etc/ha.d/目录下:
  1. ha.cf
#created by stephen#2014-07-07
debugfile /var/log/ha-debug
logfile/var/log/ha-log
logfacilitylocal0
keepalive 2
deadtime 30
warntime 10
initdead 60
serial/dev/ttyS0# Linux
mcast eth2 225.0.0.1 694 1 0    # 使用组/多播形式,通过eth2走心跳线传送,端口为:udp--694
auto_failback on
nodeMySQL01.stephenzhou.net    # 此处必须使用与‘uname -n’一致的名字
nodeMySQL02.stephenzhou.net
crm no  2. haresources
# stephen services
# 192.168.2.23 www.stephenzhou.net
# MySQL01.stephenzhou.net IPaddr::192.168.2.30/24/eth3
#MySQL01.stephenzhou.net IPaddr::192.168.2.30/24/eth3 httpd
# 192.168.2.24 bbs.stephenzhou.net
# MySQL02.stephenzhou.net IPaddr::192.168.2.32/24/eth3
# MySQL master mysqlm.stephenzhou.net
#MySQL01.stephenzhou.net IPaddr::192.168.3.30/24/eth1 mysqld
MySQL01.stephenzhou.net IPaddr::192.168.3.30/24/eth1    # 此处也必须使用与‘uname -n’一致的名字
# MySQL slave mysqls.stephenzhou.net
MySQL02.stephenzhou.net IPaddr::192.168.3.32/24/eth1  3. authkeys
auth 1
1 sha1 47e9336850f1db6fa58bc470bc9b7810eb397f04

  •   配置防火墙规则已允许心跳流量(/etc/sysconfig/iptables):
[root@MySQL01 ha.d]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p udp --dport 694 -j ACCEPT    # 允许端口UDP 694的流量进入
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

  •   测试heartbeat是否配置成功:
  1)MySQL01端:

[root@MySQL01 ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
INFO:  Resource is stopped
Done.
[root@MySQL01 ha.d]# ip add|grep 192.168.3       # 发现VIP已经绑定
    inet 192.168.3.23/24 brd 192.168.3.255 scope global eth1
    inet 192.168.3.30/24 brd 192.168.3.255 scope global secondary eth1
[root@MySQL01 ha.d]# iptables -vL    # 看到udp端口已经有心跳流量了
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination         
   48 12296 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:ha-cluster
   36  2376 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere            
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere            
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            state NEW tcp dpt:ssh
    1   229 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited
[root@MySQL01 ha.d]# tcpdump -i eth2 udp -s 1500     # 对心跳线所在网卡udp端口抓包的话可以看到心跳流量
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth2, link-type EN10MB (Ethernet), capture size 1500 bytes
16:55:16.399325 IP 192.168.5.23.35912 > 225.0.0.1.ha-cluster: UDP, length 226
16:55:17.216819 IP 192.168.5.24.53014 > 225.0.0.1.ha-cluster: UDP, length 226
16:55:17.371805 IP 192.168.5.23.35912 > 225.0.0.1.ha-cluster: UDP, length 239
16:55:18.399199 IP 192.168.5.23.35912 > 225.0.0.1.ha-cluster: UDP, length 226
16:55:19.222381 IP 192.168.5.24.53014 > 225.0.0.1.ha-cluster: UDP, length 226
...
^C
16 packets captured
16 packets received by filter
0 packets dropped by kernel  2)MySQL02端:
[root@MySQL02 ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
INFO:  Resource is stopped
Done.
[root@MySQL02 ha.d]# ip add|grep 192.168.3      
    inet 192.168.3.24/24 brd 192.168.3.255 scope global eth1
    inet 192.168.3.32/24 brd 192.168.3.255 scope global secondary eth1  

  四、参考博文:
  CentOS 6.5 heartbeat高可用集群的详解实现以及工作流程
  heartbeat mysql nfs 高可用mysql集群
  

  





运维网声明 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.iyunv.com/thread-660201-1-1.html 上篇帖子: HA Cluster—heartbeat v2基于crm配置 下篇帖子: Heartbeat V2.x双机热备安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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