b"/>

nginx配合keepalive的方案(双主)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx配合keepalive的方案(双主)相关的知识,希望对你有一定的参考价值。

技术分享

blog.etiantian.org   10.0.0.17  lb01 主      10.0.0.5  

bbs.etiantian.org    10.0.0.18   lb02主       10.0.0.6

说明:后端的web服务器一个是apacheweb服务,一个nginx服务

测试,,选用静态的html,不涉及nfs以及mysql

1.A1-nginx 负载服务器 01-10.0.0.5-lb01

①查看keepalive的配置文件

[[email protected] ~]# cat   /etc/keepalived/keepalived.conf

global_defs {

   notification_email {

   [email protected]

   }

   notification_email_from  [email protected]

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

vrrp_instance VI_17 {

    state MASTER

    interface eth0

    virtual_router_id 51

    priority 150

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

     10.0.0.17/24 dev eth0 label eth0:1  

    }

}

vrrp_instance VI_18 {

    state BACKUP

    interface eth0

    virtual_router_id 52

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

     10.0.0.18/24 dev eth0 label eth0:2

    }

}

[[email protected] ~]# 

②查看nginx的配置文件

[[email protected] ~]# cat /application/nginx/conf/nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;


    upstream server_pools {

         server 172.16.1.7:80  weight=1;

         server 172.16.1.8:80  weight=1;

    }


    server {

        listen       10.0.0.17:80;

        server_name  blog.etiantian.org;

        location / {

            proxy_pass http://server_pools;

            proxy_set_header Host  $host;

            proxy_set_header X-Forwarded-For $remote_addr; 

        }

    }


    server {

        listen       10.0.0.18:80;

        server_name  bbs.etiantian.org;

        location / {

            proxy_pass http://server_pools;

            proxy_set_header Host  $host;

            proxy_set_header X-Forwarded-For $remote_addr;

        }

    }

}

[[email protected] ~]# 



A2-nginx 负载服务器 02 -10.0.0.6-lb02


①查看keepalive的配置文件

[[email protected] ~]# cat /etc/keepalived/keepalived.conf

global_defs {

   notification_email {

   [email protected]

   }

   notification_email_from  [email protected]

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL1

}

vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

     10.0.0.17/24 dev eth0 label eth0:1  

    }

}

vrrp_instance VI_18 {

    state MASTER

    interface eth0

    virtual_router_id 52

    priority 150

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

     10.0.0.18/24 dev eth0 label eth0:2

    }

}

[[email protected] ~]# 

②查看nginx的配置文件

[[email protected] ~]# cat  /application/nginx/conf/nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;


    upstream server_pools {

         server 172.16.1.7:80  weight=1;

         server 172.16.1.8:80  weight=1;

    }


    server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            proxy_pass http://server_pools;

            proxy_set_header Host  $host;

            proxy_set_header X-Forwarded-For $remote_addr; 

        }

    }


    server {

        listen      10.0.0.18:80;

        server_name  bbs.etiantian.org;

        location / {

            proxy_pass http://server_pools;

            proxy_set_header Host  $host;

            proxy_set_header X-Forwarded-For $remote_addr;

        }

    }

}

[[email protected] ~]# 



测试blog和bbs的站点:

技术分享

技术分享

技术分享

技术分享

宕掉一台负载均衡器再接着测试

宕机以后查看IP:可以看出IP全部飘过来了

[[email protected] ~]# ifconfig 

eth0      Link encap:Ethernet  HWaddr 00:0C:29:90:A5:31  

          inet addr:10.0.0.5  Bcast:10.0.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe90:a531/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:299420 errors:0 dropped:0 overruns:0 frame:0

          TX packets:319616 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:26869861 (25.6 MiB)  TX bytes:58054361 (55.3 MiB)


eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:90:A5:31  

          inet addr:10.0.0.17  Bcast:0.0.0.0  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:90:A5:31  

          inet addr:10.0.0.18  Bcast:0.0.0.0  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


eth1      Link encap:Ethernet  HWaddr 00:0C:29:90:A5:3B  

          inet addr:172.16.1.5  Bcast:172.16.1.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe90:a53b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:1971 errors:0 dropped:0 overruns:0 frame:0

          TX packets:356 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:334109 (326.2 KiB)  TX bytes:47217 (46.1 KiB)


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:293602 errors:0 dropped:0 overruns:0 frame:0

          TX packets:293602 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:17072153 (16.2 MiB)  TX bytes:17072153 (16.2 MiB)


[[email protected] ~]# 

web测试(依然OK):

技术分享

本文出自 “小小三郎的博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1785050

以上是关于nginx配合keepalive的方案(双主)的主要内容,如果未能解决你的问题,请参考以下文章

Nginx+keepalived双主配置(双机双主热备)

Nginx+keepalived高可用(双主模式)

keepalive实验

Keepalive双主搭建配置

keepalive单主双主模型的配置

​Keepalive实现mysql双主热备