MySQL配置HeartBeat实现心跳监控和浮动IP
1. 初始化环境配置
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
ln -s /usr/local/mysql/bin/mysql /sbin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
/sbin/ldconfig
export PATH=$PATH:/usr/local/mysql/bin
2. 安装HeartBeat组件
rpm -ivh libnet-1.1.2.1-2.1.i386.rpm
rpm -ivh heartbeat-pils-2.1.4-2.1.i386.rpm
rpm -ivh --nodeps heartbeat-stonith-2.1.4-2.1.i386.rpm
rpm -ivh --nodeps heartbeat-2.1.4-2.1.i386.rpm
rpm -ivh --nodeps heartbeat-devel-2.1.4-2.1.i386.rpm
rpm -ivh --nodeps heartbeat-ldirectord-2.1.4-2.1.i386.rpm
3. 配置 HA的各配置文
shell> cp /usr/share/doc/packages/heartbeat/authkeys /etc/ha.d/
shell> cp /usr/share/doc/packages/heartbeat/haresources /etc/ha.d/
shell> cp /usr/share/doc/packages/heartbeat/ha.cf /etc/ha.d/
(1) 配置心跳的加密方式
shell> vi /etc/ha.d/authkeys
#如果使用双机对联线(双绞线),可以配置如下:
auth 1
1 crc
shell> chmod 600 /etc/ha.d/authkeys
(2) 配置心跳的监控:haresources
shell> vi /etc/ha.d/haresources
#各主机这部分应完全相同。IP为虚拟IP
mysqlA IPaddr::192.168.1.199 ipvsadm mysqld
(3) 创建日志目录
shell> mkdir -p /var/log/ha_log
shell> chmod 777 /var/log/ha_log/
(4) 编辑ha.cf
shell> vi /etc/ha.d/ha.cf
logfile /var/log/ha_log/ha.log
bcast eth0
keepalive 2
warntime 10
deadtime 30
initdead 120
hopfudge 1
udpport 694
auto_failback on
node feng
node feng2
ping 192.168.1.1
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root
debugfile /var/log/ha_log/ha_debug.log
# 打开调度器转发选项
echo 1 > /proc/sys/net/ipv4/ip_forward
# 设置ipvsadm的巡回监测
ipvsadm -A -t 192.168.1.199:3306 -s rr
ipvsadm -a -t 192.168.1.199:3306 -r 192.168.1.201:3306 -m
ipvsadm -a -t 192.168.1.199:3306 -r 192.168.1.202:3306 -m
执行后进行监测:
ipvsadm --list
HA服务的启动、关闭以及测试启动HA:
service heartbeat start
关闭HA; service heartbeat stop
进行监控: service heartbeat status
heartbeat 默认使用udp 694端口进行心跳监测。 如果系统有使用iptables 做防火墙
iptables -I INPUT -p udp --dport 694 -j ACCEPT
https://www.cnblogs.com/seasonzone/p/14429780.html