Linux编译安装keepalive最新版本2.2.2

Posted 白-胖-子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 安装完成"  

以上是关于Linux编译安装keepalive最新版本2.2.2的主要内容,如果未能解决你的问题,请参考以下文章

linux-安装及管理程序源码安装

Linux编译安装HAProxy最新版本2.4.1

运维笔记:Linux(CentOS8)免编译安装mysql5.7.33最新版本

Linux编译安装最新半Redis

Keepalive双主搭建配置

nginx编译安装