Keepalived + nginx的安装部署
2017-03-12 18:03
369 查看
主机:IP->192.168.88.60 nginx已安装OK(省略)
备机:IP->192.168.88.80 nginx已安装OK(省略)
VIP:192.168.88.20
第一步:主备一起安装keepalived
yum install -y keepalived
第二步:配置/etc/keepalived/keepalived.conf
主机192.168.88.60配置如下:
! Configuration File for keepalived
global_defs {
notification_email { #发生邮件目标地址
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc #发生邮件源地址
smtp_server 192.168.200.1 #SMTP 服务器地址
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk {
script "/etc/chk_nginx.sh"
interval 2 #间隔多久检测脚本
weight -20 #脚本返回结果非0,优先级减20
}
vrrp_instance VI_1 {
state BACKUP #主的也设置备,以为主备取决于优先级
interface eth0 #对应网卡
virtual_router_id 51
priority 90 #优先级,谁大谁是主(取值1-255之间)
#nopreempt #开启这个参数当优先级大的主服务恢复了也不抢占,以防跳来跳去
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 #密码
}
track_script {
chk # 对应上面的监测脚本模块
}
virtual_ipaddress {
192.168.88.20 #VIP地址
}
}
==============================================================
备机配置: 192.168.88.80
! Configuration File for keepalived
global_defs {
notification_email { #发生邮件目标地址
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc #发生邮件源地址
smtp_server 192.168.200.1 #SMTP 服务器地址
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk {
script "/etc/chk_nginx.sh"
interval 2 #间隔多久检测脚本
weight -20 #脚本返回结果非0,优先级减20
}
vrrp_instance VI_1 {
state BACKUP #设置备用状态
interface eth0 #对应网卡
virtual_router_id 51
priority 80 #优先级(90-20=70 小于80,如果主服务没有问题,优先级为90,如果有问题优先级变为70,备的设置为80,80>70 所以备成主接管)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 #密码
}
track_script {
chk # 对应上面的监测脚本模块
}
virtual_ipaddress {
192.168.88.20 #VIP地址
}
}
#注意不要少大括号哦
============================================
第三步:编写/etc/chk_nginx.sh脚本内容
#!/bin/bash
nginx_pid_count=`lsof -i :80 |wc -l`
if [ ${nginx_pid_count} -eq 0 ];then
exit 1
else
exit 0
fi
fi
给脚本权限 chmod +x /etc/chk_nginx.sh
第四步:启动主备keepalived
Service keepalived start
ip addr 查看vip是否起来了
#主服务器上关闭服务
/etc/init.d/nginx stop
#在从服务器上查看VIP有无绑定
ip addr
备注:
1 如果没有成功检测是不是{ }少写了
2 sh 测试监控脚本是否正确
备机:IP->192.168.88.80 nginx已安装OK(省略)
VIP:192.168.88.20
第一步:主备一起安装keepalived
yum install -y keepalived
第二步:配置/etc/keepalived/keepalived.conf
主机192.168.88.60配置如下:
! Configuration File for keepalived
global_defs {
notification_email { #发生邮件目标地址
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc #发生邮件源地址
smtp_server 192.168.200.1 #SMTP 服务器地址
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk {
script "/etc/chk_nginx.sh"
interval 2 #间隔多久检测脚本
weight -20 #脚本返回结果非0,优先级减20
}
vrrp_instance VI_1 {
state BACKUP #主的也设置备,以为主备取决于优先级
interface eth0 #对应网卡
virtual_router_id 51
priority 90 #优先级,谁大谁是主(取值1-255之间)
#nopreempt #开启这个参数当优先级大的主服务恢复了也不抢占,以防跳来跳去
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 #密码
}
track_script {
chk # 对应上面的监测脚本模块
}
virtual_ipaddress {
192.168.88.20 #VIP地址
}
}
==============================================================
备机配置: 192.168.88.80
! Configuration File for keepalived
global_defs {
notification_email { #发生邮件目标地址
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc #发生邮件源地址
smtp_server 192.168.200.1 #SMTP 服务器地址
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk {
script "/etc/chk_nginx.sh"
interval 2 #间隔多久检测脚本
weight -20 #脚本返回结果非0,优先级减20
}
vrrp_instance VI_1 {
state BACKUP #设置备用状态
interface eth0 #对应网卡
virtual_router_id 51
priority 80 #优先级(90-20=70 小于80,如果主服务没有问题,优先级为90,如果有问题优先级变为70,备的设置为80,80>70 所以备成主接管)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 #密码
}
track_script {
chk # 对应上面的监测脚本模块
}
virtual_ipaddress {
192.168.88.20 #VIP地址
}
}
#注意不要少大括号哦
============================================
第三步:编写/etc/chk_nginx.sh脚本内容
#!/bin/bash
nginx_pid_count=`lsof -i :80 |wc -l`
if [ ${nginx_pid_count} -eq 0 ];then
exit 1
else
exit 0
fi
fi
给脚本权限 chmod +x /etc/chk_nginx.sh
第四步:启动主备keepalived
Service keepalived start
ip addr 查看vip是否起来了
#主服务器上关闭服务
/etc/init.d/nginx stop
#在从服务器上查看VIP有无绑定
ip addr
备注:
1 如果没有成功检测是不是{ }少写了
2 sh 测试监控脚本是否正确
相关文章推荐
- KeepalivedHA+LVS 部署安装文档
- nginx基本编译安装部署
- ubuntu 12.04安装部署环境nginx,tomcat,mysql以及开机启动备忘
- nginx+keepalived负载均衡可用框架(补一 keepalived安装配置-热备-(服务器层和应用层))
- django环境安装+站点部署(uwsgi+nginx)
- 最后关于nginx+passenger+ror+mysql的安装部署过程
- Nginx安装部署(反向代理与负载均衡)
- Nginx安装部署
- Nginx实战基础篇一 源码包编译安装部署web服务器
- nginx+keepalived负载均衡可用框架(补一 keepalived安装配置-互备)
- 【转载】KeepalivedHA+LVS 部署安装文档
- ubuntu12.04 安装部署环境,nginx,tomcat,mysql。以及开机启动
- Nginx技术交流Q群:225942451(探讨安装、部署、模块开发、源码分析,及其他知名服务端开源软件)
- Nginx+keepalived 脚本安装主从双机热备自动切换解决方案
- Nginx实战基础篇一 源码包编译安装部署web服务器 推荐
- 【Linux】Nginx安装、部署--CentOS5.4
- trac和nginx安装部署指南
- Ubuntu 12.04 Server LTS安装部署Nginx+MySQL+Ruby1.9.3+Rails3.2
- linux下nginx结合tomcat安装部署
- nginx使用cronolog切割日志安装、部署、应用测试