编译部署keepalived

环境:centos7 ubuntu18.04

一. centos 编译部署keepalived

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#环境:centos7
#软件版:keepalived-2.0.18.tar.gz
set -e
dir="/usr/local/src"
keepalived="keepalived-2.0.18"
keepalived_v="keepalived-2.0.18.tar.gz"
yilai="openssl openssl-devel wget vim lrzsz"
keepalived_make(){
echo -e "\033[33m 此脚本容错率较低请不要重复执行 \033[0m"
sleep 10
echo -e "\033[36m ===============开始拉取安装包:${keepalived_v} \033[0m"
wget --no-check-certificate https://www.keepalived.org/software/${keepalived_v}
echo -e "\033[36m 解压到: ${dir} \033[0m"
tar -zxvf ./${keepalived_v} -C ${dir}
yum install -y ${yilai}
cd ${dir}/${keepalived}/ && ./configure --prefix=/usr/local/keepalived
cd ${dir}/${keepalived}/ && make
cd ${dir}/${keepalived}/ && make install
[ $? = 0 ] && echo -e "\033[36m 编译安装${keepalived}成功 \033[0m" || echo -e "\033[33m 编译安装${keepalived}失败 \033[0m"
}
keepalived_system(){
echo -e "\033[36m ===============开始配置:${keepalived} \033[0m"
[ -d "/etc/keepalived" ] || mkdir -p /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /etc/init.d/
systemctl daemon-reload
systemctl start keepalived
systemctl enable keepalived
systemctl status keepalived
echo -e "\033[36m
常用命令:
systemctl restart keepalived
systemctl status keepalived
systemctl enable keepalived
\033[0m"
echo "keepalived版本是:"
/usr/local/keepalived/sbin/keepalived -v
}
main(){
keepalived_make
keepalived_system
}
main

二. ubuntu部署keepailved

1
2
3
4
5
6
7
8
9
1 查看keepalived软件版本
# apt-cache madison keepalived
keepalived | 1:2.0.19-2 | http://mirrors.aliyun.com/ubuntu focal/main amd64 Packages
2.2 安装keepalived
# apt -y install keepalived
2.3 准备keepalived.conf文件
# cp /usr/share/doc/keepalived/samples/keepalived.conf.sample /etc/keepalived/keepalived.conf
2.4 修改keepalived.conf文件 (不执行)
# sed -i 's@interface eth0@interface ens33@g' /etc/keepalived/keepalived.conf