nginx+keepalived简单实现双击热备-高可用HA

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx+keepalived简单实现双击热备-高可用HA相关的知识,希望对你有一定的参考价值。

主: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 [email protected][email protected]#

   }

   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 [email protected][email protected]#

   }

   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的主要内容,如果未能解决你的问题,请参考以下文章

Nginx双机热备

搭建Keepalived实现双机热备

LVS+DR模式+keepalived

windows2016双击热备不用共享存储

LVS+Keepalived高可用群集

基于ensp防火墙双击热备二层网络规划与设计