Loading

keepalived编译安装-CentOS X86

环境信息

操作系统: CentOS Linux release 7.9.2009 (Core)
架构:X86
keepalived版本:2.3.1

编译

wget https://www.keepalived.org/software/keepalived-2.3.1.tar.gz
tar xvf keepalived-2.3.1.tar.gz
cd keepalived-2.3.1/
./configure --prefix=/usr/local/keepalived 
make
make install

编译完成查看版本

 /usr/local/keepalived/sbin/keepalived --version

配置并启动 Keepalived

创建配置目录和日志目录:

sudo mkdir -p /etc/keepalived
sudo mkdir -p /var/log/keepalived

创建和编辑配置文件 /etc/keepalived/keepalived.conf:

sudo vi /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1234
    }

    virtual_ipaddress {
        192.168.1.100
    }
}

创建系统服务(可选)

为了方便管理 Keepalived 服务,可以创建一个 systemd 服务文件。

创建 systemd 服务文件:

sudo vi /etc/systemd/system/keepalived.service
[Unit]
Description=Keepalived service
After=network.target

[Service]
ExecStart=/usr/local/keepalived/sbin/keepalived -D
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/var/run/keepalived.pid
KillSignal=SIGTERM
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

启动并启用 Keepalived 服务:

sudo systemctl daemon-reload
sudo systemctl start keepalived
sudo systemctl enable keepalived

检查 Keepalived 服务状态:

systemctl status keepalived
posted @ 2024-12-11 15:36  亚里士多智  阅读(6)  评论(0编辑  收藏  举报