Centos 离线部署keepalived高可用

服务器资源准备

MASTER:192.168.10.1 #主服务
BACKUP:192.168.10.2 #备用服务
VIP1:192.168.10.10 #虚拟VIP1
VIP2:192.168.10.11 #虚拟VIP2(一般可以只配置一个虚拟VIP)

提示:以下安装两台服务器除配置文件内容不同外,安装步骤一律相同。

1.下载软件

Tomcat tomcat官网

keepalived 官网

2.安装依赖

yum -y install gcc
yum -y install openssl-devel
yum -y install libnl libnl-devel
yum -y install libnfnetlink-devel #ipv6相关
yum -y install net-tools

帮助:yum离线安装

3.上传压缩包到app文件夹

cd /app
tar -zxf keepalived-2.2.4.tar.gz
cd /app/keepalived-2.2.4

4.安装

./configure
make
make install #警告忽略

5.验证

ll /usr/local/etc/keepalived/keepalived.conf
ll /usr/local/etc/sysconfig/keepalived
ll /usr/local/sbin/keepalived

6.初始化

mkdir /etc/keepalived
cp /app/keepalived-2.2.4/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /app/keepalived-2.2.4/keepalived/etc/init.d/keepalived  /etc/rc.d/init.d/
cp /app/keepalived-2.2.4/keepalived/etc/sysconfig/keepalived  /etc/sysconfig/
cp /usr/local/sbin/keepalived  /usr/sbin/

7.配置

cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bk
echo '' > /etc/keepalived/keepalived.conf
#查看网卡名称
ip add
vi /etc/keepalived/keepalived.conf

-----------------------192.168.10.1------------------------------ ! Configuration File for keepalived global_defs { router_id LVS_DEVEL_01 } vrrp_instance VI_1 { state MASTER interface enp0s8 #网卡名称 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.10.10 192.168.10.11 } } -----------------------192.168.10.2------------------------------ ! Configuration File for keepalived global_defs { router_id LVS_DEVEL_02 } vrrp_instance VI_1 { state BACKUP interface enp0s8 #网卡名称 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.10.10 192.168.10.11 } }

8.验证服务

=========操作=========
service keepalived stop //停止服务
service keepalived status //查看服务状态
service keepalived start //启动服务

9.查看ip是否漂移

ip addr|grep 192.168.10.10

10.两台服务器各自解压部署tomcat

  停止192.168.10.1上的keepalived查看vip是否漂移到192.168.10.2上。

  启动192.168.10.1上的keepalived服务器,查看VIP是否漂移回到192.168.10.1上。

  访问192.168.10.10:8080或者192.168.10.11:8080查看tomcat服务是否正常可以访问。

posted @ 2022-06-27 17:15  aongao  阅读(681)  评论(0编辑  收藏  举报