php是最好的语言

keepalived高可用搭建

        高可用就是一台服务器down机后另一台服务器可以马上接手继续工作而不影响用户使用。在前面负载均衡的基础上进行搭建两台作为keeplived服务。另外两台作为web服务器。

        我们要先在keeplived服务器上安装keepalived。命令如下yum install keepalived -y ,启动keepalived,/etc/init.d/keepalived start.主备都要进行此安装。

        下面进行配置:cd /etc/keepalived,vi keepalived.conf:主,配置如下:

        

global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id lb01 //和备不同

}


vrrp_instance VI_1 {

    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.12/24 dev eth0 label eth0:1

       # 192.168.200.17

       # 192.168.200.18

    }

}

        备,配置如下:

        


global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 127.0.0.1

   smtp_connect_timeout 30

   router_id lb02

}


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.12/24 dev eth0 label eth0:1

       # 192.168.200.17

       # 192.168.200.18

    }

}

        配置完毕后重启keepalived服务,/etc/init.d/keepalived restart,检查结果ip addr|grep 10.0.0.12(在主备都正常工作的时候,在备服务器上运行不会有任何东西返回,当主down机时,备就有数据返回,我们可以停止主的keepalived服务进行测试)。

        接下来配置主备的nginx.conf,主备配置是一样的,配置如下:

        ..............省略了一些


    #access_log  logs/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

   # keepalive_timeout  65;


    #gzip  on;

    upstream backend {

       server 49.4.143.218;

        server 49.4.143.217;

        check interval=3000 rise=2 fall=5 timeout=1000 type=http;//节点检测

         }

    server {

        listen      10.0.0.12:80;//这里和keepalived.conf里面的virtual_ipaddress 一致

        server_name www.xtwanwan.info;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;

        location / {

#               root html/www;

#               index index.php index.html index.htm;

             proxy_set_header Host $host;

             proxy_set_header X-Real-IP $remote_addr;

             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

             proxy_buffering off;

             proxy_pass http://backend;

        }

        location /status {

            check_status;

            access_log off;

        }

...................//省略了一些

        最后测试要把域名解析执行主备keepalived服务器才行,然后就可以测试了。

作者:xTao 分类:LNMP 浏览:2344 评论:0