HA(高可用集群)heartbeat
HA 即 (high available)高可用,又被叫做双机热备, 常用实现高可用的开源软件有heartbeat和keepalived,其中keepalived有负载均衡的功能。http://s1.运维网.com/wyfs02/M02/87/BA/wKioL1fgUHqStuSFAAHn-ygfo50631.png下面我们使用heartbeat来做HA集群,并且把nginx服务作为HA对应的服务。
试验准备:
两个机器, 都是centos6.5,网卡eth0 ip如下:
aming 192.168.31.166
aming1192.168.31.100
两个eth1 ip如下:
aming192.168.21.166
aming1 192.168.21.100
http://s3.运维网.com/wyfs02/M00/87/BE/wKiom1fgUK6gnb1lAAW5oM3FmtM091.png
下面操作1-5都是在两个机器上操作
1. hostname 设置好,分别为aming和 aming1
2. 关闭防火墙 iptables -F;
关闭selinux: setenforce 0
3. vi /etc/hosts // 增加内容如下:
192.168.31.166 aming
192.168.31.100 aming1
4. 安装epel扩展源:
rpm -ivh'http://www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm'
yum install -y epel-release
5. 两个机器都安装heartbeat / libnet
yuminstall -y heartbeat* libnetnginx
6.主上(aming)配置
cd /usr/share/doc/heartbeat-3.0.4/
cpauthkeysha.cf haresources /etc/ha.d/
cd /etc/ha.d
viauthkeys//加入或更改为auth 3
3 md5 Hello!
http://s5.运维网.com/wyfs02/M01/87/BE/wKiom1fgUN2Ctd4kAABMUfX3Phs274.png
chmod 600 authkeys
viharesources//加入
aming 192.168.31.110/24/eth0:0 nginx
aming是主服务器的名字, 192。168。31。110是虚拟出来的IP
http://s2.运维网.com/wyfs02/M00/87/BA/wKioL1fgUQywD6GCAAB2bAhrGh4542.png
nginx因为在etc/init.d下
虚拟IP要写对外提供服务的IP段
viha.cf //改为如下内容:
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
ucast eth1 192.168.21.100
auto_failback on
node aming
node aming1
ping 192.168.21.1
respawn hacluster /usr/lib/heartbeat/ipfail
http://s3.运维网.com/wyfs02/M00/87/BA/wKioL1fgUVzSSSlXAABYjAjyALE185.png
这些要打开
http://s3.运维网.com/wyfs02/M02/87/BE/wKiom1fgUXXieEW2AAAmtXbw-Mo192.png
这里写IP也可以写网卡的名字(对方的)不是业务网卡
http://s5.运维网.com/wyfs02/M01/87/BE/wKiom1fgUZKSfzvPAAA5C507W00228.png
检测网络联通性
64位系统可能要写成 ls /usr/lib64/heartbeat/ipfail
http://s2.运维网.com/wyfs02/M01/87/BB/wKioL1fgUcKxeFaaAAA19s1sEUc223.png
http://s2.运维网.com/wyfs02/M01/87/BB/wKioL1fgUcPgKgrzAABIWS4GsnE612.png
这里是以那个用户的身份
http://s5.运维网.com/wyfs02/M02/87/BE/wKiom1fgUfHBy-7TAAB0fjV77mQ127.png
这个IP是个仲裁
http://s3.运维网.com/wyfs02/M02/87/BB/wKioL1fgUhuDq8OkAAAG7s-xYqk411.png
主节点,从节点
从上:
http://s4.运维网.com/wyfs02/M00/87/BE/wKiom1fgUjuwqBqIAAAkANq8ee4805.png
这里写IP也可以写网卡的名字(对方的)
less /var/log/ha-log 日志文件
7.把主上的三个配置拷贝到从上:
cd /etc/ha.d/
scpauthkeysha.cf haresources aming1:/etc/ha.d/
http://s5.运维网.com/wyfs02/M02/87/BB/wKioL1fgUmvhy7HJAAAc3EJoKPs725.png
8. 到从上(aming1) 编辑ha.cf
vi/etc/ha.d/ha.cf //只需要更改一个地方
ucast eth1 192.168.21.100 改为 ucast eth1 192.168.21.166
9.启动heartbeat :
先主,后从
service heartbeat start
/etc/init.d/heartbeat start
10. 检查测试
ifconfig 看是否有 eth0:0
ps aux |grep nginx看是否有nginx进程
11.测试1
主上故意禁ping
iptables -I INPUT -p icmp -j DROP
12. 测试2
主上停止heartbeat服务
service heartbeat stop
13. 测试脑裂
主和从上都down掉eth1网卡
ifdown eth1
脑列就是服务器的第二张网卡,全部down掉
http://s3.运维网.com/wyfs02/M01/87/BE/wKiom1fgUqaThNYHAAD_iD2fpM4361.png
脑列后,网卡接通后,主跟从都会获取不到资源,我们把
主上的hearbent重启下
http://s3.运维网.com/wyfs02/M00/87/BE/wKiom1fgUtfgmuseAAKF--8YKsI790.png
http://s3.运维网.com/wyfs02/M00/87/BB/wKioL1fgUtfjxPmaAABhfOuJNYs486.png
http://s1.运维网.com/wyfs02/M00/87/BB/wKioL1fgUxbRGGMSAAFQIhhsmfM670.png
页:
[1]