两台机器的环境:
data-1-1 eth0 10.0.0.7 eth1 172.16.1.7 eth2 10.0.10.7
data-1-2 eth0 10.0.0.8 eth1 172.16.1.8 eth2 10.0.10.8
[root@data-1-2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.10.7 data-1-1
10.0.10.8 data-1-2
[root@data-1-1 ~]# route add -host 10.0.10.8 dev eth2 互相添加路由
[root@data-1-2 ~]# route add -host 10.0.10.7 dev eth2 互相添加路由
更新yum源:
[root@data-1-1 ~]# mkdir /home/oldboy/tools -p
[root@data-1-1 ~]# cd /home/oldboy/tools
[root@data-1-1 tools]# wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@data-1-1 tools]# rpm -ivh epel-release-6-8.noarch.rpm
[root@data-1-2 yum.repos.d]# rpm -qa|grep epel 检查是否已安装上
epel-release-6-8.noarch
[root@data-1-2 yum.repos.d]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf 是否留下软件包
[root@data-1-2 yum.repos.d]# yum install heartbeat* -y 都需要安装heartbeat软件及其依赖
启动脚本:/etc/init.d/heartbeat
配置文件目录:/etc/ha.d
资源控制目录:/etc/ha.d/resource.d
核心的配置文件:authkey haresource ha.cf
配置文件模版放置目录:/usr/share/doc/heartbaeat-3.0.4
ha.cf配置文件:
[root@data-1-1 ha.d]# cat /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
mcast eth0 225.0.0.1 694 1 0
auto_failback on
node data-1-1
node data-1-2
crm no
authkeys配置文件
[root@data-1-2 html]# echo chenjisong|sha1sum
8e901fca8d58aa2e2b315b4af1769ffe54e5257a -
[root@data-1-2 ha.d]# cat authkeys
auth 1
1 sha1 8e901fca8d58aa2e2b315b4af1769ffe54e5257a
[root@data-1-1 ha.d]# chmod 600 authkeys
haresources 配置文件
[root@data-1-2 ha.d]# cat haresources
data-1-1 IPaddr::10.0.0.17/24/eth0 ====虚拟IP
data-1-2 IPaddr::10.0.0.18/24/eth0 ====虚拟IP
[root@data-1-1 ha.d]# /etc/ha.d/resource.d/IPaddr 10.0.0.17/24/eth0 start
[root@data-1-1 ha.d]# ip a|grep 10.0.0.17
inet 10.0.0.17/24 brd 10.0.0.255 scope global secondary eth0
[root@data-1-2 ha.d]# /etc/ha.d/resource.d/IPaddr 10.0.0.18/24/eth0 start
[root@data-1-2 ha.d]# ip a|grep 10.0.0.18
inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0
两台机器上面安装httpd
然后启停heartbeat服务,查看ip漂移过程
heartbeat的使用场景: