Linux编译安装keepalive最新版本2.2.2

keepalive

  • keepalive,是在TCP中一个可以检测死连接的机制。
  • 使用飘虚拟IP实现服务器高可用的软件
  • vrrp 协议的软件实现,原生设计目的为了高可用 ipvs服务
  • 官网:http://keepalived.org/

功能:

  • 基于vrrp协议完成地址流动
  • 为vip地址所在的节点生成ipvs规则(在配置文件中预先定义)
  • 为ipvs集群的各RS做健康状态检测
  • 基于脚本调用接口完成脚本中定义的功能,进而影响集群事务,
  • 原生支持lvs
  • 支持nginx、haproxy等服务

包安装keepalive

#CentOS
[root@centos ~]#yum -y install keepalived
#ubuntu
[root@ubuntu1804 ~]#apt -y install keepalived

编译安装keepalive

  • 编译安装可以使用最新版keepalive
  • 默认会自动生成unit文件
  • 编译安装后因为缺少配置文件导致无法启动
  • 默认生成iptables规则,无法访问VIP,
  • 编译时可以加–disable-fwmark禁用生成iptables规则

1. 下载最新安装包并解压缩

wget https://keepalived.org/software/keepalived-2.2.2.tar.gz

tar xf keepalived-2.2.2.tar.gz -C /usr/local/src

2. 安装依赖

yum -y install gcc curl openssl-devel libnl3-devel net-snmpdevel

3. 添加编译参数进行预编译

  • #选项–disable-fwmark 可用于禁用iptables规则,可访止VIP无法访问,无此选项默认会启用ipatbles规则

cd /usr/local/src/keepalived-2.2.2/ && ./configure --prefix=/usr/local/keepalived --disable-fwmark

4. 执行编译安装

make -j $CUP && make install

5. 创建配置文件

mkdir /etc/keepalived && cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived

6. 启动服务器并设为开机运行

systemctl enable --now keepalived.service

写个脚本快速安装keepalive-2.2.2

#!/bin/bash
# 
#********************************************************************
#Author:                    timonium
#E-mail:                    8528379[AT]]sina.com
#Date:                      2021-06-22
#FileName:                 ik.sh
#BlogURL:                   blog.csdn.net/timonium
#Description:              Install Keepalive-2.2.2
#Copyright (C):            2021 All rights reserved
#********************************************************************
SRC_DIR=/usr/local/src
KAL_URL=https://keepalived.org/software/
KAL_FILE=keepalived-2.2.2
TAR=.tar.gz
KAL_INSTALL_DIR=/apps/KAL

[ -e ${KAL_INSTALL_DIR} ] && echo "KAL 已安装,请卸载后再安装" && exit
cd ${SRC_DIR};[ -e ${KAL_FILE}${TAR} ] || wget ${KAL_URL}${KAL_FILE}${TAR}
[ $? -ne 0 ] && echo "下载 ${KAL_FILE}${TAR}文件失败" && exit;
yum -y -q install make gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embed libnl3-devel net-snmpdevel &> /dev/null
cd $SRC_DIR && tar xf ${KAL_FILE}${TAR}
KAL_DIR=`echo ${KAL_FILE}${TAR}| sed -nr 's/^(.*[0-9]).*/\1/p'`
cd ${KAL_DIR} && ./configure --prefix=${KAL_INSTALL_DIR} --disable-fwmark
make -j 2 && make install
mkdir /etc/keepalived && cp ${KAL_INSTALL_DIR}/etc/keepalived/keepalived.conf /etc/keepalived
systemctl daemon-reload
systemctl enable --now keepalived &> /dev/null
systemctl is-active keepalived &> /dev/null || echo "KAL 启动失败,退出!" && exit
echo "keepalived 安装完成"  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值