考虑到后面设备可能没法连接到外网,所以采用安装包的方式进行部署,下载地址:https://www.openssl.org/source/old/1.1.1/index.html,当前选择的版本是openssl-1.1.1w。
#解压
tar -xzvf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w
#配置,指定安装目录
./config --prefix=/usr/local/ssl
#编译
make
#安装
sudo make install
如果想对所有用户都生效,可以直接修改到/etc/profile里面,这样openssl对所有用户都是可用的了,在后面添加:
export PATH="/usr/local/ssl/bin:$PATH"
添加成功后执行:
source ~/.bashrc
想要验证是否安装成功可以通过这个命令,检查输出的版本号跟自己安装的是否一致:
openssl version
同时检查/usr/local/ssl/目录下是不是都有bin、lib、include等目录,如果两者检查都输出正常,就说明openssl安装成功。
当前安装完成后openssl的版本号为:OpenSSL 1.1.1w 11 Sep 2023。
Keepalived源码下载地址:https://keepalived.org/download.html,当前选择的版本是Version 2.3.1。
#解压
tar -xzvf keepalived-2.3.1.tar.gz
cd keepalived-2.3.1
#配置
./config
#编译
make
#安装
sudo make install
在配置的时候报错:configure: error: !!! OpenSSL is not properly installed on your system. !!! !!! Can not include OpenSSL headers files.上网查了下资料,是因为找不到openssl安装的依赖,所以需要自己指定一个,我是通过手动添加编译器标志的方式进行解决:
CFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib" ./configure --with-openssl=/usr/local/ssl
通过下面命令看可以检查Keepalived是否安装完成:
keepalived --version
正常来说会打印如下信息:
Keepalived v2.3.1 (05/24,2024)
Copyright(C) 2001-2024 Alexandre Cassen,
也可以检查是否生成了可执行文件,存在的话也说明安装成功。
ls /usr/local/sbin/keepalived
其中需要修改keepalived.conf配置文件,具体内容如下所示:
[Unit]
Description=Keepalived High Availability
After=network.target
Before=network-online.target
[Service]
ExecStart=/usr/local/sbin/keepalived -f /etc/keepalived/keepalived.conf
PIDFile=/run/keepalived.pid
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
User=keepalived
Group=keepalived
[Install]
WantedBy=multi-user.target
sudo systemctl status keepalived
正常来说,运行状态应该是active(running),如果是failed说明是启动失败了。
sudo journalctl -xe -u keepalived
#修改
sudo nano /etc/systemd/system/keepalived.service
#生效
sudo systemctl daemon-reload
sudo systemctl restart keepalived
sudo keepalived -f /etc/keepalived/keepalived.conf -t