#两台服务器都添加下面的心跳路由 生产环境建议加route。现在不加也不影响搭建.
/sbin/route add -host 172.16.1.4 dev eth1
/sbin/route add -host 172.16.1.3 dev eth1
echo '/sbin/route add -host 172.16.1.3 dev eth1' >> /etc/rc.local
echo '/sbin/route add -host 172.16.1.4 dev eth1' >> /etc/rc.local
#######################start
[root@MYSQL_M ~]# ping 172.16.1.4
PING 172.16.1.4 (172.16.1.4) 56(84) bytes of data.
64 bytes from 172.16.1.4: icmp_seq=1 ttl=64 time=1.56 ms
64 bytes from 172.16.1.4: icmp_seq=2 ttl=64 time=0.310 ms
^C
--- 172.16.1.4 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1267ms
rtt min/avg/max/mdev = 0.310/0.935/1.561/0.626 ms
[root@MYSQL_M ~]#
============================
[root@MYSQL_S ~]# /sbin/route add -host 172.16.1.3 dev eth1
[root@MYSQL_S ~]#
[root@MYSQL_S ~]# ping 172.16.1.3
PING 172.16.1.3 (172.16.1.3) 56(84) bytes of data.
64 bytes from 172.16.1.3: icmp_seq=1 ttl=64 time=0.391 ms
^C
--- 172.16.1.3 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 897ms
rtt min/avg/max/mdev = 0.391/0.391/0.391/0.000 ms
[root@MYSQL_S ~]#
3、安装heartbeat
a、下载并安装epel包.两台服务器都要操作
mkdir -p /home/lvnian/tools && cd /home/lvnian/tools
wget
rpm -qa |grep epel
[ epel-release-6-8.noarch.rpm ]&& rpm -ivh epel-release-6-8.noarch.rpm
rpm -qa |grep epel
b、安装heartbeat,下面是在CentOS版本系统中部署,.两台服务器都要操作。所有用yum install heartbeat* -y
yum install heartbeat -y
c、拷贝ha的配置文件,资源文件以及授权文件到/etc/ha.d/下面
ll /usr/share/doc/heartbeat-3.0.4/
cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf haresources authkeys /etc/ha.d/
d、开始配置
cd /etc/ha.d
mv ha.cf ha.bak
mv authkeys authkeys.bak
mv haresources haresources.bak
注意点:下面ha.cf、authkeys、haresources这三个文件在主备都是一样的
########配置ha.cf
cat>/etc/ha.d/ha.cf<<eof
#the start by lvnian 20150881
debugfile /var/log/ha-debug
logfile /var/log/ha-log
#logfacility local1
keepalive 2
deadtime 30
warntime 10
initdead 60
#bcast eth1
mcast eth1 225.0.0.181 694 1 0
#ucast eth1 172.16.1.4
auto_failback off #服务器正常后,不接管备用设备资源
node MYSQL_M
node MYSQL_S
crm no
#the end by lvnian 20150881
eof
####配置authkeys
cat >/etc/ha.d/authkeys<<eof
auth 1
1 sha1 b900cbbdfa0a850444fa3dae47a9d354 #这个字符串是随便写的,但是需要主备都是一样的
eof
chmod 600 /etc/ha.d/authkeys
#####配置haresources
cat > /etc/ha.d/haresources <<eof
#lvnian services
#10.0.0.103
MYSQL_M IPaddr::10.0.0.103/24/eth0
#MYSQL_M IPaddr::10.0.0.103/24/eth0 httpd
#10.0.0.104 bbs.etianetian.org
MYSQL_S IPaddr::10.0.0.104/24/eth0
#mysql MYSQL_M mysqlm.etianetian.org
#MYSQL_M IPaddr::10.0.0.103/24/eth0
#MYSQL_M IPaddr::10.0.0.103/24/eth0 mysqld
#mysql slave mysqlm.etianetian.org
#MYSQL_S IPaddr::10.0.0.104/24/eth0
eof
#########
f、启动heartbeat 服务
/etc/init.d/heartbeat start
/etc/init.d/heartbeat stop
/etc/init.d/heartbeat restart
g、设置开机自启动heartbeat
chkconfig heartbeat on
用ip add 查看vip
查看 cat /var/log/ha-log日志文件