龙空技术网

nginx快速入门 第3篇

不开心就撸代码 186

前言:

眼前兄弟们对“双网卡绑定nginx”大概比较关切,你们都想要分析一些“双网卡绑定nginx”的相关文章。那么小编同时在网上汇集了一些有关“双网卡绑定nginx””的相关资讯,希望朋友们能喜欢,看官们快快来了解一下吧!

nginx 搭建高可用集群

(一)Keepalived安装

1.下载Keepalived 解压

2.cd Keepalived文件夹

3.执行 ./configure

4.执行 make && make install

(二)Keepalived+Nginx 高可用集群(主从模式)

1.配置两台nginx服务器,都安装Keepalived

2.修改第一台服务器的Keepalived配置

(1)cd /etc/keepalived

(2)修改keepalived.conf 文件

global_defs {  notification_email {    acassen@firewall.loc    failover@firewall.loc    sysadmin@firewall.loc  }  notification_email_from Alexandre.Cassen@firewall.loc  smtp_server 192.168.17.129  smtp_connect_timeout 30  router_id LVS_DEVEL } vrrp_script chk_http_port {    script "/usr/local/src/nginx_check.sh"    interval 2 #(检测脚本执行的间隔)    weight 2 } vrrp_instance VI_1 {    state BACKUP # 备份服务器上将 MASTER 改为 BACKUP    interface ens33 //网卡    virtual_router_id 51 # 主、备机的 virtual_router_id 必须相同    priority 90 # 主、备机取不同的优先级,主机值较大,备份机值较小    advert_int 1    authentication {      auth_type PASS      auth_pass 1111    }  virtual_ipaddress {  192.168.17.50 // VRRP H 虚拟地址  }}

(3)在/usr/local/src 添加检测脚本

#!/bin/bashA=`ps -C nginx –no-header |wc -l`if [ $A -eq 0 ];then/usr/local/nginx/sbin/nginxsleep 2if [ `ps -C nginx --no-header |wc -l` -eq 0 ];thenkillall keepalivedfifi

(4)启动 keepalived:systemctl start keepalived.service

(5)输入 ip add检查

(三)Keepalived+Nginx 高可用集群(双主模式)

(1)修改第一台Keepalived.conf配置文件

global_defs {notification_email {381347268@qq.com}smtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVEL}vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 51priority 150advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.1.110/24 dev ens33 label ens33:1}}vrrp_instance VI_2 {state BACKUPinterface ens33virtual_router_id 52priority 100advert_int 1authentication {auth_type PASSauth_pass 2222}virtual_ipaddress {192.168.1.210/24 dev ens33 label ens33:2}}

(2)修改第二台Keepalived.conf配置文件

global_defs {notification_email {381347268@qq.com}smtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVEL}vrrp_instance VI_1 {state BACKUPinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.1.110/24 dev ens33 label ens33:1}}vrrp_instance VI_2 {state MASTERinterface ens33virtual_router_id 52priority 150advert_int 1authentication {auth_type PASSauth_pass 2222}virtual_ipaddress {192.168.1.210/24 dev ens33 label ens33:2}}

(3)其他操作和主从一样

标签: #双网卡绑定nginx