heartbeat高可用+lvsDR

selinux iptables disabled
主:desktop75.example.com(eth0:192.168.0.75;eth1:10.0.0.5) 备:desktop53.example.com(192.168.0.53;eth1:10.0.0.3)
虚拟IP:192.168.0.35

[root@desktop75 ~]# ls
heartbeat-3.0.4-1.el6.x86_64.rpm        heartbeat-libs-3.0.4-1.el6.x86_64.rpm
heartbeat-devel-3.0.4-1.el6.x86_64.rpm  ldirectord-3.9.2-1.2.x86_64.rpm
[root@desktop75 ~]#yum localinstall --nogpgcheck *(可以自动安装依赖包)
[root@desktop75 heartbeat-3.0.4]# cp ha.cf haresources authkeys /etc/ha.d/
#vim ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="static"
IPADDR=10.0.0.5
PREFIX=24
HWADDR="52:54:00:92:68:9e"
ONBOOT="yes"
[root@desktop75 ha.d]# grep -v '#' ha.cf      
debugfile /var/log/ha-debug
logfile    /var/log/ha-log
logfacility    local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport    1078
auto_failback on
watchdog /dev/watchdog
node    desktop75.example.com ---上面的是主
node    desktop53.example.com
ping 192.168.0.253
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
[root@desktop75 ha.d]# grep -v '#' haresources
desktop75.example.com(主的) IPaddr::192.168.0.35/24/eth0 httpd---(可以调用/etc/init.d;/etc/ha.d/rc.d;/etc/ha.d/resource.d里面的程序)
[root@desktop75 ha.d]# grep -v '#' authkeys
auth 3
3 md5 Hello!
[root@desktop75 ha.d]# chmod 600 authkeys
[root@desktop75 ha.d]#modprobe softdog
[root@desktop75 ha.d]# ll /dev/watchdog
crw-rw---- 1 root root 10, 130 Aug 12 02:12 /dev/watchdog
[root@desktop75 ha.d]# scp authkeys haresources ha.cf desktop53:/etc/ha.d/

保证两台电脑的httpd启动,有index.html,
[root@desktop75 ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: IPaddr[5263]: INFO:  Resource is stopped
Done.
大概过60秒后,httpd会启动
同时再启动53上的heartbeat
在/var/log/下 ha-debug 和ha-log两个文件看到相应动作
此时浏览器访问虚拟ip就可看到,关掉主heartbeat,服务可以立刻切换到备上;关掉http是不会切过去的

当主上的心跳eth1挂掉,主和备都会认为对方挂了,最后导致都在抢服务,两个都提供服务;当心跳eth1恢复后,整个服务是不能恢复的,kill一个后,然后再重启
当主eth0挂了,备份可以接管
所以在实际中心跳放到eth0上

当主内核挂掉(echo c > /proc/sysrq-trigger)(Kernel panic);此时dogwatch也没用

2.调度器lvs的dr集成(上面两个主机作为调度器,都有ipvsadm)
realserver1:192.168.0.63
realserver2:192.168.0.53
[root@desktop63 ~]# ifconfig lo:0 192.168.0.163 netmask 255.255.255.255 up
[root@desktop63 ~]# route add -host 192.168.0.163 dev lo:0
[root@Desktop75 ~]# rpm -ql ldirectord
/etc/ha.d/resource.d
/etc/ha.d/resource.d/ldirectord
/etc/init.d/ldirectord
/etc/logrotate.d/ldirectord
/sbin/rcldirectord
/usr/sbin/ldirectord
/usr/share/doc/packages/ldirectord
/usr/share/doc/packages/ldirectord/ldirectord.cf
/usr/share/man/man8/ldirectord.8.gz
[root@Desktop75 ha.d]# grep -v "#" ldirectord.cf |grep -v "^$"
checktimeout=3
checkinterval=1
autoreload=yes
quiescent=no
virtual=192.168.0.75:80
    real=192.168.0.63:80 gate
    real=192.168.0.53:80 gate
    fallback=127.0.0.1:80 gate
    service=http
    scheduler=rr
    persistent=600
    protocol=tcp
    checktype=negotiate
    checkport=80
        request="index.html"
[root@Desktop75 ha.d]# grep -v "#" haresources
desktop77.example.com IPaddr::192.168.0.252/24/eth0 ldirectord httpd
同步文件到53上
[root@desktop75 ~]# /etc/init.d/ldirectord status
如果ok就可以启动heartbeat
如果realserver上的httpd启动则
[root@desktop75 ~]#ipvsadm -L 可以看到列出两个主机

命令说明:ipvsadm -Lnc ---可以看到更详细到信息

你可能感兴趣的:(LVS,heartbeat)