标签:keepalived nginx
主:192.168.1.2_nginx
备:192.169.1.3_nginx
nginx部署情况:
新建运行账号:useradd -s /sbin/nologin nginx
nginx账号密码:123456
部署路径:/usr/local/nginx/
nginx部署步骤:
1.解压pcre-8.38.tar.gz和nginx-1.8.1.tar.gz至nginx家目录
2.cd /root/nginx-1.8.1/
3../configure --prefix=/usr/local/nginx/--user=nginx --group=nginx --with-pcre=/root/pcre-8.38/ --without-mail_pop3_module--without-mail_imap_module --without-mail_smtp_module
4.make && make install
修改配置文件/usr/local/nginx/conf/nginx.conf,将”#user nobody; ”修改为“user nginx;”
配置文件:/usr/local/nginx/conf/nginx.conf
建立软连接:
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
启动方式:
nginx 或者 /usr/local/sbin/nginx 或 /usr/local/nginx/sbin/nginx
keepalived部署情况:
部署路径:
/usr/local/keepalived-1.3.0
建立软连接:
ln -s /usr/local/keepalived-1.3.0/sbin/keepalived /usr/local/sbin/keepalived
nginx监控脚本部署路径:
/usr/local/keepalived-1.3.0/nginx.sh
keepalived.conf配置文件部署路径:/etc/keepalived.conf
启动方式:keepalived -d -f /etc/keepalived.conf 或 /usr/local/keepalived-1.3.0/sbin/keepalived -d -f /etc/keepalived.conf
定义高可用VIP:192.168.1.4
主配置文件内容:
! Configuration File for keepalived
global_defs {
router_id NGINX_MASTER
}
vrrp_script chk_ngx {
script "/usr/local/keepalived-1.3.0/nginx.sh"
interval 2
weight -3
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.1.2
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 123@2016!@#
}
track_script {
chk_ngx
}
virtual_ipaddress {
192.168.1.4
}
}
备配置文件内容:
! Configuration File for keepalived
global_defs {
router_id NGINX_BACKUP
}
vrrp_script chk_ngx {
script "/usr/local/keepalived-1.3.0/nginx.sh"
interval 5
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51 ##必须与主一致
mcast_src_ip 192.168.1.3
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123@2016!@#
}
track_script {
chk_ngx
}
virtual_ipaddress {
192.168.1.4
}
}
nginx.sh检查nginx运行状态,脚本内容:
#!/bin/bash
count=`ps -C nginx --no-header |wc -l`
if [[ "$count" -gt "0" ]]; then
exit 0
else
exit 1
fi
本文出自 “Mask_X 博客” 博客,请务必保留此出处http://zhpfbk.blog.51cto.com/4757027/1879872
nginx+keepalived简单实现双击热备-高可用HA
标签:keepalived nginx
原文地址:http://zhpfbk.blog.51cto.com/4757027/1879872