==========================================================
另外每台主机应预留500M的raw空间或者更多来作为共用空间被HA使用。
RedHat Enterprise 4 Update2 (2.6.9-22 EL)
@ GNOME Desktop Environment
@ KDE Desktop Environment
@ Engineering and Scientific
@ Authoring and Publishing
@ Server Configuration Tools
@ GNOME Software Development
@ KDE Software Development
========================================================
node1: 主机名:servers201 ( HA01 )
eth0: 192.168.10.201 //对外IP地址
eth1: 10.0.0.201 //HA心跳使用地址
node2: 主机名:servers202 ( HA02 )
eth0: 192.168.10.202 //对外IP地址
eth1: 10.0.0.202 //HA心跳使用地址
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1
127.0.0.1 localhost.localdomain localhost
192.168.10.201 servers201 HA01
127.0.0.1 localhost.localdomain localhost
192.168.10.202 servers202 HA02
nameserver 61.139.2.69 //DNS地址
#cat /etc/sysconfig/network
HOSTNAME=servers201 //主机名
GATEWAY="192.168.10.1" //网关
FORWARD_IPV4="yes" //只允许IPV4
#cat /etc/sysconfig/network-scripts/ifcfg-eth0
#cat /etc/sysconfig/network-scripts/ifcfg-eth1
[node1] 与 [node2] 在上面的配置中,除了
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1
配置完成后,试试在各自主机上ping对方的主机名,应该可以ping通:
PING HA02 (10.0.0.202) 56(84) bytes of data.
64 bytes from HA02 (10.0.0.202): icmp_seq=0 ttl=64 time=0.198 ms
64 bytes from HA02 (10.0.0.202): icmp_seq=1 ttl=64 time=0.266 ms
64 bytes from HA02 (10.0.0.202): icmp_seq=2 ttl=64 time=0.148 ms
--- HA02 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.148/0.204/0.266/0.048 ms, pipe 2
===========================================================
rpm -Uvh libnet-1.1.2.1-1.rh.el.um.1.i386.rpm //可以不装
rpm -Uvh heartbeat-pils-2.0.4-1.el4.i386.rpm
rpm -Uvh heartbeat-stonith-2.0.4-1.el4.i386.rpm
rpm -Uvh heartbeat-2.0.4-1.el4.i386.rpm
rpm -Uvh ipvsadm-1.24-5.i386.rpm
============================================================
---------------------------
---------------------------
---------------------------
---------------------------
#vi /etc/ha.d/haresources
server201 IPaddr::192.168.10.200 ipvsadm httpd
指定 server201调用ipvsadm启动http服务,系统附加一个虚拟IP 192.168.10.200 给eth0:0
这里如果server201宕机后,server202可以自动启动http服务,并新分配IP 192.168.10.200给server202的eth0:0
---------------------------
---------------------------
logfile /var/log/ha_log/ha-log.log ## ha的日志文件记录位置。如没有该目录,则需要手动添加
keepalive 2 ##设定心跳(监测)时间时间为2秒
udpport 694 ##使用udp端口694 进行心跳监测
node server201 ##节点1,必须要与 uname -n 指令得到的结果一致。
ping 192.168.10.1 ##通过ping 网关来监测心跳是否正常。
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=root uid=root
debugfile /Datas/logs/ha_log/ha-debug.log
---------------------------
---------------------------
ipvsadm -A -t 192.168.10.200:80 -s rr
ipvsadm -a -t 192.168.10.200:80 -r 192.168.10.201:80 -m
ipvsadm -a -t 192.168.10.200:80 -r 192.168.10.202:80 -m
IP Virtual Server version 1.2.0 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.10.200:http rr
-> server202:http Local 1 0 0
-> server201:http Masq 1 0 0
=================================================
启动HA: service heartbeat start
关闭HA; service heartbeat stop
系统在启动时已经自动把heartbeat 加载了。
编辑各自主机的测试用html文件,放到/var/www/html/目录下。
启动node1的heartbeat,并执行这个指令进行监控: service heartbeat status
====================================================
heartbeat 默认使用udp 694端口进行心跳监测。 如果系统有使用iptables 做防火墙,应记住把这个端口打开。
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
iptables -I INPUT -p udp --dport 694 -j ACCEPT
iptables -I INPUT -p udp --dport 32770 -j ACCEPT
service iptables save
#service iptables restart
本文转自king_819 51CTO博客,原文链接:http://blog.51cto.com/kerry/102143,如需转载请自行联系原作者