您的位置:首页 > 运维架构 > Nginx

ha高可用集群----nginx

2016-06-17 16:47 549 查看
环境:
centos6.5 x86_64
192.168.30.20 web1.com
192.168.30.21 web2.com

nginx和php安装参考lnmp
配置好nginx php后编译索引页
主 html/index.html
web1111111111
备 html/index.html
web2222222222

#------安装高可用集群软件主备都安装
yum install -y heartbeat libnet
#------拷贝配置文件
cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf authkeys haresources /etc/ha.d/
chmod 600 authkeys

主上操作
#------修改authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!

#-----修改ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
#多长时间探测
keepalive 2
##多长时间无法ping通就认为死掉了
deadtime 30
warntime 10
udpport 694
##备上的ip
ucast eth0 192.168.30.21 备的ip
##主fail备变主,主再启动起来,那么备失效
auto_failback on
node web1.com
node web2.com
ping 192.168.30.1
respawn hacluster /usr/lib64/heartbeat/ipfail

备上操作
#------修改authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
#-----修改ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
#多长时间探测
keepalive 2
##多长时间无法ping通就认为死掉了
deadtime 30
warntime 10
udpport 694
##备上的ip
ucast eth0 192.168.30.21 备的ip
##主fail备变主,主再启动起来,那么备失效
auto_failback on
node web1.com
node web2.com
ping 192.168.30.1
respawn hacluster /usr/lib64/heartbeat/ipfail 64位系统lib64 32位为lib

#-------修改haresources 主备一样
web1.com 192.168.30.111/24/eth0:0 nginx 此处ip为vip nginx处为服务

#------启动heartbeat服务
先主后备
service heartbeat start
在主上 ip addr 可以显示vip 192.168.30.111 #这里发现如果nginx没配置对的话 vip出不来

#---------测试
这里我设置域名为www.111.com
windows里hosts文件添加 ip 域名对应关系
192.168.30.111 www.111.com
浏览器输入http://www.111.com
web11111111111111
主上拒绝ping,那vip会跑到备上
iptables -A INPUT -p icmp -j DROP
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  服务 ha nginx