Keepalived编译安装,步骤如下
准备工作
1.将源码包上传到服务器中
2.将修改好的keepalived.conf文件上传到服务器中(安装keepalived后会自动生成默认的keepalived.conf文件,但是需要做删减才能正常启动keepalived,所以将删减好的keepalived.conf上传后续只需要修改里边的内容即可)
3.安装编译源码包所需要的依赖
yum -y install kernel-devel openssl-devel popt-devel gcc*
4.上传编写好的监控shell脚本
安装步骤
1.进入到存放keepalived源码包的目录中并进行解压
tar zxvf keepalived-2.0.20.tar.gz
2.进入到解压后的keepalived目录中
cd keepalived-2.0.20
3.预编译指定安装目录
./configure --prefix=/usr/local/keepalived
4.编译安装
make && make install
加入开机启动项、系统命令
1.把解压目录中keepalived的启动文件复制到init.d
cp /opt/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/
2.将安装目录中keepalived文件拷贝到/etc下
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
3.将准备工作中上传的keepalived.conf配置文件拷贝到/etc/keepalived下
mkdir /etc/keepalived
cp /opt/keepalived.conf /etc/keepalived/
4.将keepalived加入系统命令系统
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
5.重新加载服务的配置文件
systemctl daemon-reload
keepalived系统命令
启动
systemctl stop keepalived
关闭
systemctl start keepalived
重启
systemctl restart keepalived
查看keepalived状态
systemctl status keepalived
#修改/etc/keepalived/keepalived.conf(单机部署只需修改红框中内容,具体修改根据实际环境进行修改)
![](https://i-blog.csdnimg.cn/blog_migrate/249bb4a172b3ae0c48d404d083fee1a8.png)
指定keepalived日志输出路径
1.编辑keepalived安装目录下的keepalived文件
vim /usr/local/keepalived/etc/sysconfig/keepalived
![](https://i-blog.csdnimg.cn/blog_migrate/3fbff68bb267d8f06782699f4087c469.png)
2.编辑etc/rsyslog.conf文件
vim /etc/rsyslog.conf
![](https://i-blog.csdnimg.cn/blog_migrate/02702d92885c5cd8597bf9d7aa96256c.png)
3.重启rsyslog
systemctl restart rsyslog
4.重启keepalived
systemctl restart keepalived
#检测脚本内容如下(如果检测nginx或其他服务就修改为对应服务的进程命令)
要先将上传到服务器上的检测脚本放到keepalived.conf配置文件中指定的路径下(在修改keepalived.conf配置文件时可自行设置检测脚本的存放路径)
![](https://i-blog.csdnimg.cn/blog_migrate/cdab05e70be784230dc909766329ed67.png)
注!!!凡是要执行脚本情况下要先确保是否有权限执行!!!
以keepalived检测tomcat为例(检测nginx和其他服务同理,修改对应的启动脚本并授权即可)
chmod +x /usr/local/src/server_check.sh(该脚本路径为检测脚本路径,由于keepalived配置文件中需要执行检测脚本,所以需要进行授权)