码迷,mamicode.com
首页 > 其他好文 > 详细

利用keepalived实现nginx调度器高可用(一)

时间:2018-06-15 18:23:01      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:两台   start   check   ipaddress   proxy   IV   ica   real   ast   

利用keepalived实现nginx调度器高可用

    声明:提供四台主机,其中两台nginx做前端调度器(一台做主调度器,一台做备用调度器),

              另外两台主机做web服务器向外提供http服务;

           框架如图:

           技术分享图片

        1.在两台nginx上配置nginx反代服务

            # vim /etc/nginx/nginx.conf

             在http上下文中添加下文:

             upstream webser {
             server 172.16.1.12:80 weight=1;
             server 172.16.1.13:80 weight=1;
             }
             server {
                 listen       80 default_server;

                 location / {
                       proxy_pass http://webser;
                 }

             }

            配置完成后,启动nginx服务,使配置生效;

        

         2.配置keepalived+nginx_master(172.16.1.11主机):(前提,安装keepalived : # yum install keepalived)

           # vim /etc/keepalived/keepalived.conf

              ! Configuration File for keepalived

             global_defs {
                     notification_email {
                                root@localhost
                     }
                     notification_email_from keepalived@localhost
                     smtp_server 127.0.0.1
                     smtp_connect_timeout 30
                     router_id drct1
                    vrrp_mcast_group4 224.0.100.18
             }
             vrrp_script check_httpd {
                    script "killall -0 nginx && exit 0 || exit 1"
                    interval 1
                    weight -20
              }
              vrrp_instance VI_1 {
                    state BACKUP
                    interface ens33
                    virtual_router_id 51
                    priority 100
                    advert_int 1
                    authentication {
                           auth_type PASS
                           auth_pass cxqLUKJh
                    }
                   virtual_ipaddress {
                          172.16.1.254/16
                    }
                   track_script {
                           check_httpd
                    }
               }

            启动keepalived服务:

             # systemctl start keepalived.service


            3.配置keepalived+nginx_backup(172.16.1.13主机):

              

           # vim /etc/keepalived/keepalived.conf

              ! Configuration File for keepalived

             global_defs {
                     notification_email {
                                root@localhost
                     }
                     notification_email_from keepalived@localhost
                     smtp_server 127.0.0.1
                     smtp_connect_timeout 30
                     router_id drct2
                    vrrp_mcast_group4 224.0.100.18
             }
             vrrp_script check_httpd {
                    script "killall -0 nginx && exit 0 || exit 1"
                    interval 1
                    weight -20
              }
              vrrp_instance VI_1 {
                    state BACKUP
                    interface ens33
                    virtual_router_id 51
                    priority 90
                    advert_int 1
                    authentication {
                           auth_type PASS
                           auth_pass cxqLUKJh
                    }
                   virtual_ipaddress {
                          172.16.1.254/16
                    }
                   track_script {
                           check_httpd
                    }
               }

            配置完成后,启动keepalived服务:

                   # systemctl start keepalived


           4.配置后端web服务器

              1)安装httpd

                    # yum install http

              2) 做web页面:

                    webserver1:

                         vim /var/www/html/index.html

                         Real Server 1

             

                    webserver2:

                         vim /var/www/html/index.html                      

                         Real Server 2

              3) 启动http服务:

                     # systemctl start httpd


            5.用一个客户端测试:

                   #  for i in {1..10}; do curl http://172.16.1.254;done
                       Real Server 2
                       Real Server 1
                       Real Server 2
                       Real Server 1
                       Real Server 2
                       Real Server 1
                       Real Server 1
                       Real Server 2
                       Real Server 1
                       Real Server 2

 
















           

利用keepalived实现nginx调度器高可用(一)

标签:两台   start   check   ipaddress   proxy   IV   ica   real   ast   

原文地址:http://blog.51cto.com/yuantianchi/2129943

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!