1,293   Linux RedHat

一,原理:
1,heartbeat实现主备切换,对外使用一个浮动IP,
2,浮动IP绑定在主服务器,备服务器处于侦听状态;
3,当主服务出现异常,heartbeat会自动切换浮动IP到备服务器,并执行一些初始化工作,比如启动http等

二,配置

1,修改各自/etc/hosts

VLR-123-189-132 10.123.189.132
VLR-123-189-133 10.123.189.133

2,各自增加/etc/ha.d/ha.cf,基本配置

# 日志
logfile /var/log/ha-log
logfacility local0
# 侦听配置,包括心跳和端口等
keepalive 2
deadtime 30
initdead 120
udpport 696
bcast eth0 # Linux
auto_failback off
# 节点
node VLR-123-189-132
node VLR-123-189-133
# 判断节点是否正常
ping 10.123.189.129

3,各自增加/etc/ha.d/authkeys,更改权限600,认证配置

# 认证方式
auth 1
1 crc
2 sha1 HI!
3 md5 unimall

4,各自增加/etc/ha.d/haresources,初始化配置

服务器1:

VLR-123-189-132 10.123.189.154 httpd

服务器2:

VLR-123-189-133 10.123.189.154 httpd

5,测试

# 启停heartbeat达到服务器异常的测试情况
> service heartbeat start/stop/status
# 查看浮动IP
> ifconfig
# 查看httpd的启动情况
> service httpd status



Leave a Reply

Your email address will not be published. Required fields are marked *