ubuntu1804上搭建高可用nginx-(5)

1、搭建2台服务器,部署tomcat,ip分别为192.168.2.175和132,

http://192.168.2.175/tomcat/tomcat.html

http://192.168.2.132/tomcat/tomcat.html

 

  2、安装keepalived-参考imooc

2.1、下载keepalived

官网下载keepalived-2.2.4.tar.gz

tar -xvf keepalived-2.2.4.tar.gz

cd keepalived-2.2.4/

执行./configure --prefix=/usr/local/keepalived --sysconf=/etc

2.2、如出现

出现该错误主要原因缺少头文件

在centos中 :只需要安装openssl和openssl-devel即可。

    yum -y install openssl-devel

在ubuntu中,安装libssl-dev

apt-get install libssl-dev

出现WARN:*** WARNING - this build will not support IPVS with IPv6. Please in

apt install  libnfnetlink-dev

2.3、make &&make install 

2.4、配置,调整/etc/keepalived下的配置文件,

! Configuration File for keepalived

global_defs {
   router_id keep_132
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.99         虚拟ip
    }
}

2.5、进入usr/local/keepalived下执行./keepalived启动

2.6、测试

http://192.168.2.99/tomcat/tomcat.html

 3、搭建175的keepalived-备

此时99虚拟ip绑定在132中,175的ip addr看不到99的虚拟ip。

当停止132中的keepalived后,虚拟ip出现在175上。切换为备机

 

 

4、重新启动主节点132的keepalive,发现虚拟ip又绑定到132上,访问虚拟ip时,切换到132上的nginx

 

附:keepalived原理

猜你喜欢

转载自blog.csdn.net/XJF199001/article/details/121715684