Keepalived安装

keepalived-学习目录

1、方式1:yum安装

1.1、配置yum仓库

gzip /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache

1.2、安装keepalived

yum install keepalived -y

2、方式2:源码安装

2.1、下载软件

curl -o keepalived-2.2.2.tar.gz https://www.keepalived.org/software/keepalived-2.2.2.tar.gz

2.2、keepalived安装

2.2.1、安装依赖包

yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

2.2.2、编译安装

tar xvf keepalived-2.2.2.tar.gz && cd keepalived-2.2.2 && ./configure --prefix=/usr/local/keepalived-2.2.2 && make && make install
ln -s /usr/local/keepalived-2.2.2 /usr/local/keepalived

2.2.3、修改配置信息

sed -i '/KEEPALIVED_OPTIONS=/c KEEPALIVED_OPTIONS="-D -f /usr/local/keepalived/etc/keepalived/keepalived.conf -p /var/run/keepalived.pid"' /usr/local/keepalived/etc/sysconfig/keepalived

2.3、配置systemd脚本

cat << 'CAT_END' > /usr/lib/systemd/system/keepalived.service
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network-online.target

[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
KillMode=process
EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
CAT_END

systemctl daemon-reload

 

posted @ 2023-05-05 20:10  小粉优化大师  阅读(145)  评论(0编辑  收藏  举报