专栏首页智慧协同Keepalived+Tomcat高可用配置说明

Keepalived+Tomcat高可用配置说明

参考地址:http://blog.51cto.com/songky/1964672

安装编译所必要的依赖

yum install gcc openssl-devel libnl libnl3-devel libnfnetlink-devel

下载并编译

wget [http://www.keepalived.org/software/keepalived-1.3.5.tar.gz](http://www.keepalived.org/software/keepalived-1.3.5.tar.gz)
tar zxf keepalived-1.3.5.tar.gz
cd keepalived-1.3.5
./configure --prefix=/usr/local/keepalived --with-init=SYSV  --不指定的话,默认不生成RECL6的启动脚本
make && make install

将文件拷贝到特定的目录

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp -p /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
chkconfig --add keepalived
chkconfig --list keepalived
chkconfig  keepalived on
chmod +x /etc/init.d/keepalived

启动服务

service tomcat start
service keepalived start

检查主从切换日志:

tail -f /var/log/messages

重点说明:

一、重启keepalived服务后,ping不通vip地址?

vim /etc/keepalived/keepalived.conf

把下面这个注释就可以了

vrrp_strict

二、vip切换及恢复原则:

  1. 切换:master服务器的tomcat服务停止,则master上的keepalived会自动停止, vip漂移到backup服务器
  2. 恢复:master服务器修复完毕后, 请分别启动tomcat和keepalived,则vip会自动漂移到master服务器

配置文件参考

  1. keepalived.master.conf
global_defs {
    notification_email {
        root@localhost
    }
    notification_email_from root@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id LVS_DEVEL
    vrrp_skip_check_adv_addr
    # vrrp_strict
    vrrp_garp_interval 0
    vrrp_gna_interval 0
}

vrrp_script chk_http_port {
    script "/etc/keepalived/check-tomcat.sh"
    interval 1
    weight 2
}

vrrp_instance VI_1 {
    state Primary
    interface eno1
    virtual_router_id 51
    priority 99          #此处不同,要低于master
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    track_interface {
        eno1
    }
    track_script {
        chk_http_port
    }
    virtual_ipaddress {
        172.20.30.33
    }
}
  1. keepalived.slaver.conf
global_defs {
    notification_email {
        root@localhost
    }
    notification_email_from root@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id LVS_DEVEL
    vrrp_skip_check_adv_addr
    # vrrp_strict
    vrrp_garp_interval 0
    vrrp_gna_interval 0
}
    
vrrp_script chk_http_port {
    script "/etc/keepalived/check-tomcat.sh"
    interval 1
    weight -2
}

vrrp_instance VI_1 {
    state Secondary
    interface eno1
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    track_interface {
        eno1
    }
    track_script {
        chk_http_port
    }
    virtual_ipaddress {
        172.20.30.33
    }
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式

    原理: 在微信的JS-API 中 play 一下 audio 即可达到自动播放的目的(应该是微信自己做了处理)

    飞奔去旅行
  • 运行Windows Phone模拟器提示“Unable to start the emulator”的解决办法

    错误提示:The emulator is unable to start because the hypervisor is not running. The ...

    飞奔去旅行
  • Android menu item "showAsAction"属性出错的解决办法

    最近在看《Android编程权威指南》,按照第16.1.1节创建菜单的时候,却报错了:

    飞奔去旅行
  • Nginx(八)-- Nginx+keepalived实现高可用

    keepalived下载地址:http://download.csdn.net/detail/u010821757/9892484

    码农小胖哥
  • CentOS7 下 keepalived 的安装和配置

    安装前准备: yum -y install gcc gcc-c++ autoconf automake make  yum -y install zlib zl...

    庞小明
  • Keepalived实现对web服务的高可用

    Keepalived is a routing software written in C.

    用户6641876
  • linux下keepalived的安装

    4. 启动 service keepalived star |stop| restart

    用户1499526
  • KeepAlived双主模式高可用集群

    一、keepalived简介 keepalived是vrrp协议的实现,原生设计目的是为了高可用ipvs服务,keepalived能够配置文件中的定义生成ipv...

    小小科
  • KeepAlived双主模式高可用集群

    一、keepalived简介 keepalived是vrrp协议的实现,原生设计目的是为了高可用ipvs服务,keepalived能够配置文件中的定义生成ipv...

    小小科
  • 连肝7个晚上,总结了计算机网络的知识点!(共66条)

    http1.1中浏览器再也不用为每个请求重新发起TCP连接了,增加内容有:缓存相关首部的扩展,OPTIONS方法,Upgrade首部,Range请求,压缩和传输...

    达达前端

扫码关注云+社区

领取腾讯云代金券