centos7离线安装keepalived2.0.20并设置开机自启动

tech2023-02-07  94

一、安装

1、从官网下载源码安装包并手动上传到linux服务器:

https://www.keepalived.org/download.html;下载.tar.gz的文件夹,例如:https://www.keepalived.org/software/keepalived-2.0.20.tar.gz

2、解压文件:

tar -zvxf keepalived-2.0.20.tar.gz

3、创建文件夹

mkdir /home/keepalived

4、安装gcc等编译源码需要的工具及其他工具

yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel

5、源码安装软件时配置环境用,根据你的配置选项和你的系统情况生成makefile文件,为make做准备

./configure --prefix=/home/keepalived

6、编译

make

7、安装

make install

 

二、配置与开机自启动

       安装完成后,进入安装目录的etc目录下,将keepalived相应的配置文件拷贝到系统相应的目录当中。keepalived启动时会从/etc/keepalived目录下查找keepalived.conf配置文件,如果没有找到则使用默认的配置。

1、keepalived 启动脚本变量引用文件,默认文件路径是 /etc/sysconfig/,做软链接:

cp /home/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived

2、将keepalived 主程序加入到环境变量(安装目录下):

cp /home/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/keepalived

3、将配置文件放到默认路径下

mkdir /etc/keepalived cp /home/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

4、加为系统服务:

chkconfig   --add keepalived

5、设置开机自启动

chkconfig keepalived on

6、运行keepalived的相关命令:

service keepalived start|stop|restart|status

7、使用命令查看运行情况:

ps -ef|grep keepalived root      1476     1  0 9月04 ?       00:00:00 /home/keepalived/sbin/keepalived -D root      1478  1476  0 9月04 ?       00:00:41 /home/keepalived/sbin/keepalived -D root      1480  1476  0 9月04 ?       00:00:24 /home/keepalived/sbin/keepalived -D root     15585 15493  0 09:41 pts/0    00:00:00 grep --color=auto keepalived

 

三、防火墙配置

1、关闭SElinux防火墙:

vim /etc/sysconfig/selinux

2、编辑selinux配置文件:

#SELINUX=enforcing                      #注释掉 #SELINUXTYPE=targeted                #注释掉 SELINUX=disabled                           #增加

3、刷新配置:

setenforce 0

4、开启vrrp组播:

firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --destination 224.0.0.18 --protocol vrrp -j ACCEPT firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 --destination 224.0.0.18 --protocol vrrp -j ACCEPT

5、刷新防火墙:firewall-cmd --reload

 

五、问题

1、编译环境的问题,此问题根据提示进行处理;如需要如下的环境:

解决措施如:yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel

2、如果service keepalived start启动后依然无法通过ps -ef|grep keepalived看到启动的线程,请使用vi /var/log/messages查看启动时候的日志,常见错误是因为配置文件中的信息与实际不一致导致,如网卡号错误等。

解决措施:修改配置文件后重启

最新回复(0)