nginx学习笔记五

Nginx 配置高可用的集群

1、准备两台安装了nginx的Linux系统

2、在两台安装了nginx的Linux系统中安装keepalived

yum install keepalived –y

3、安装完成之后在/etc/keepalived目录下有keepalived.conf配置文件

cd /etc/keepalived

4、修改keepalived.conf配置文件

1、主机器

!Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER     #主机器MASTER  备机器BACKUP
    interface ens33
    virtual_router_id 51
    priority 100   
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.50 dev ens33 label ens33:1
    }
}

2、备机器

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

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 {
        192.168.10.50 dev ens33 label ens33:1
    }
}

3、修改完成之后使用以下代码分别启动keepalibed

systemctl start keepalived

4、这样就可以通过虚拟IP   192.168.10.50访问nginx了,当主机器挂了之后自动使用备选机器


版权声明:本文为fangyuwuzhu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。