Keepalived+nginx+apache Double-Live build (dual-NIC mode)

Source: Internet
Author: User

Previously wrote an article "Keepalived+nginx+apache and double Live Build test", the test environment only a network card, the dual-live IP is on the network card.

background: The automatic operation and maintenance platform of the front-mounted machine deployed in the cloud platform, the server has two network cards, respectively, corresponding to the out-of-band IP and business IP, the cloud platform of the managed server access to out-of-band virtual IP, non-cloud platform physical server access to the virtual IP of the business.


Architecture diagram:



Configuration:

Host
Ip
Operating system
Software
Vip
nginx01

172.27.9.91

172.27.18.127

Centos7.3.1611

Nginx Port 82

Keepalived

172.27.9.200
nginx02

172.27.9.92

172.27.18.128

Centos7.3.1611

Nginx Port 82

Keepalived

172.27.18.120
Web01
172.27.9.125
Centos7.3.1611 Apache Port 1180
/
Web02
172.27.9.126
Centos7.3.1611 Apache Port 1180

/

VMware version : 12.5.2 build-4638234


1.vmware New network card

Open ' Virtual network editor ':

The ' VMnet0 ' and ' VMnet2 ' respectively correspond to the PC physical network card and the wireless network card:

New network card and configuration:



2.keepalived Configuration

NGINX01 on keepalived configuration:

[[Email protected] keepalived]# more /etc/keepalived/keepalived.conf! configuration  File for keepalivedglobal_defs {   notification_email {      [email protected]     [email protected]      [email protected]   }   notification_email_from [email  protected]    #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 { &nBsp;      172.27.18.120    }    track_ script {        chk_nginx    }}

nginx02 on keepalived configuration:

[[Email protected] keepalived]# more /etc/keepalived/keepalived.conf! configuration  File for keepalivedglobal_defs {   notification_email {      [email protected]     [email protected]      [email protected]   }   notification_email_from [email  protected]    #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 {  &nbSp;     172.27.18.120    }    track_script  {        chk_nginx    }}

check_nginx.sh script configuration with previous articles


3.nginx Configuration

The two Nginx servers are configured as follows:

[[email protected] 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. Start the service

Start two server nginx and keepalived services:

[[email protected] ~]# Nginx[[email protected] ~]# service keepalived startredirecting to/bin/systemctl start keepalived . Service


5. View VIP


6. Page Access

vip1:http://172.27.9.200:82/

vip2:http://172.27.18.120:82/


Refresh the Web to discover Vip1 and VIP2 to access the Web server in polling mode, respectively


7. Highly Available tests

With the previous article, no longer repeat.


The test is complete, the cloud Platform production environment can also be implemented according to this test.

Keepalived+nginx+apache Dual-Live build (dual-NIC mode)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.