nginx负载均衡如何部署双机热备方法及步骤

  

部署

ip分配nginx192.168.1.5主机,192.168.1.6备机,浮动ip192.168.1.7

<强>首先设置浮动ip(主备机器都要设置)

打开网卡eth0配置好网络参数

复制eth0为eth0:1

修改vim eth0:1 

名称=eth0:1

设备=,eth0:1

IPADDR=192.168.1.7

开启转发

回声“1”;比;/proc/sys/net/ipv4/ip_forward

 nginx负载均衡如何部署双机热备方法及步骤

修改/etc/sysctl。参看文件,让包转发功能在系统启动时自动生效:

#控制IP数据包转发

net.ipv4。ip_forward=1

重启网络

服务网络重启


安装keepalive

yum安装keepalive - y

修改配置文件

vim/etc/keepalived/keepalived。conf

主机配置情况

global_defs {

    notification_email { 

        #baojing@163.com  设置报警

        }

    router_id LVS_DEVEL

    }

    vrrp_script chk_http_port {

        script "

        interval 1

        weight -10

    }

    vrrp_instance VI_1 {

        state MASTER

        interface eth0

        virtual_router_id 51

        priority 100

        advert_int 1

        authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

    192.168.1.7

    }

    track_script {

        chk_http_port

    }

  ,}


备用机上面配置

global_defs {

    notification_email { 

        #baojing@163.com  设置报警

        }

    router_id LVS_DEVEL

    }

    vrrp_script chk_http_port {

        script "

        interval 1

        weight -10

    }

    vrrp_instance VI_1 {

        state BACKUP

        interface eth0

        virtual_router_id 51

        priority 90

        advert_int 1

        authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

    192.168.1.7

    }

    track_script {

        chk_http_port

    }

  ,}

 nginx负载均衡如何部署双机热备方法及步骤

启动查看keepalive情况killall keepalive

服务keepalive开始tail - f/var/log/messages


安装nginx配置转发负载均衡

vim/usr/local/nginx/conf/nginx.conf

添加负载均衡配置

,,,,上游mytest {

,,,,,,,,,,,,,,,, # least_conn;

,,,,,,,,,,,,,,,, # ip_hash;null   null

nginx负载均衡如何部署双机热备方法及步骤