分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

keepalived+nginx+apache双活搭建(双网卡模式)

发布时间:2023-09-06 02:00责任编辑:沈小雨关键词:apachenginxkeepalived
之前写过一篇文章《keepalived+nginx+apache主备及双活搭建测试》,该测试环境只有一张网卡,双活的ip都在该网卡上。

本文背景:自动化运维平台的前置机部署在云平台,服务器有两张网卡,分别对应带外ip和业务ip;云平台的被管服务器访问带外虚ip,非云平台的物理服务器访问业务的虚ip。


架构图:



配置:

主机
ip
操作系统
软件
vip
nginx01

172.27.9.91

172.27.18.127

Centos7.3.1611

nginx 端口82

keepalived

172.27.9.200
nginx02

172.27.9.92

172.27.18.128

Centos7.3.1611

nginx 端口82

keepalived

172.27.18.120
web01
172.27.9.125
Centos7.3.1611apache 端口1180
/
web02
172.27.9.126
Centos7.3.1611apache 端口1180

/

vmware版本:12.5.2 build-4638234


1.vmware新增网卡

打开‘虚拟网络编辑器’

‘VMnet0’和‘VMnet2’分别对应pc机物理网卡和无线网卡:

新增网卡及配置:



2.keepalived配置

nginx01上keepalived配置:

[root@nginx01 keepalived]# more /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_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_connect_timeout 30   router_id proxy1 }vrrp_script chk_nginx {  script "/etc/keepalived/check_nginx.sh"  interval 2  weight 20  fall 1  rise 10}vrrp_instance VI_1 {    state MASTER    interface ens33    virtual_router_id 51    priority 100    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        172.27.9.200    }    track_script {        chk_nginx    }}vrrp_instance VI_2 {    state BACKUP     interface ens37    virtual_router_id 52    priority 90    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        172.27.18.120    }    track_script {        chk_nginx    }}

nginx02上keepalived配置:

[root@nginx02 keepalived]# more /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_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_connect_timeout 30   router_id proxy2}vrrp_script chk_nginx {  script "/etc/keepalived/check_nginx.sh"  interval 2  weight 20  fall 2  rise 1}vrrp_instance VI_1 {    state BACKUP     interface ens33    virtual_router_id 51    priority 90    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        172.27.9.200    }    track_script {        chk_nginx    }}vrrp_instance VI_2 {    state MASTER    interface ens37    virtual_router_id 52    priority 100    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        172.27.18.120    }    track_script {        chk_nginx    }}

check_nginx.sh脚本配置同之前文章


3.nginx配置

两台nginx服务器配置相同如下:

[root@nginx02 keepalived]# more /usr/local/nginx/conf/nginx.conf#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    upstream webser{             server 172.27.9.125:1180;             server 172.27.9.126:1180;             server 172.27.18.127:1180;             server 172.27.18.128:1180;           }    server {        listen       82;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            proxy_pass http://webser;            #root   html;            #index  index.html index.htm;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }}


4.启动服务

启动两台服务器nginx和keepalived服务:

[root@nginx01 ~]# nginx[root@nginx01 ~]# service keepalived startRedirecting to /bin/systemctl start  keepalived.service


5.查看vip


6.页面访问

vip1:http://172.27.9.200:82/

vip2:http://172.27.18.120:82/


刷新web,发现vip1和vip2分别以轮询方式访问web服务器


7.高可用测试

同之前文章,不再赘述。


测试完成,云平台生产环境也可以按本次测试实施。

keepalived+nginx+apache双活搭建(双网卡模式)

原文地址:http://blog.51cto.com/3241766/2129948

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved