软件下载:
http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
主从:
/ 172.16.0.200(master)+nginx\
VIP:172.16.0.199<===> <==>mysql集群
\ 172.16.0.201 (slave) +nginx/
主从安装软件:
这里可以省略安装ipvsadm
#ln -s /usr/src/kernels/2.6.18-164.el5-x86_64/ /usr/src/linux
#tar zxvf ipvsadm-1.24.tar.gz
#cd ipvsadm-1.24
#make && make install
#tar zxvf keepalived-1.1.15.tar.gz
#cd keepalived-1.1.15
#./configure && make && make install
#find / -name keepalived # 查看keepalived位置
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/
#service keepalived start|stop #做成系统启动服务方便管理.
主keepalived配置文件:
! Configuration File for keepalived
global_defs {
notification_email {
sys@larry.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/etc/keepalived/nginx_pid.sh"
interval 2
weight 2
}
! VIP1
vrrp_instance VI_1 {
state MASTER
interface eth0
mcast_src_ip 172.16.0.200
virtual_router_id 51
lvs_sync_daemon_inteface eth0
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
172.16.0.199
}
}
从keepalived配置文件:
! Configuration File for keepalived
global_defs {
notification_email {
sys@larry.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/etc/keepalived/nginx_pid.sh"
interval 2
weight 2
}
! VIP1
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 172.16.0.201
lvs_sync_daemon_inteface eth0
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
172.16.0.199
}
}
nginx_pid.sh脚本检查nginx检查:
#/bin/bash
Q=`ps -C nginx --no-header |wc -l`
if [ $Q -eq 0 ];then
/usr/local/nginx/sbin/nginx
sleep 3
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
killall keepalived
fi
fi
keepalived+nginx双机热备
原创5iqiong 博主文章分类:Web operation ©著作权
©著作权归作者所有:来自51CTO博客作者5iqiong的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:haproxy实现负载均衡
下一篇:for循环总结
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
keepalived+nginx双机热备+负载均衡
keepalived+nginx双机热备+负载均衡最近因业务扩展,需要将当前的ster进程分配模式下,Master进程永远不进行业务处理
nginx 负载均衡 keepalived 高可用 双机热备份