centos7源码方式安装配置keepalived

https://blog.csdn.net/xyang81/article/details/52554398
https://blog.csdn.net/brazier820104/article/details/73195147

准备

  • centos7.4
  • keepalived-2.0.4
    下载地址 - http://www.keepalived.org/download.html

安装

  • 安装依赖
yum -y install openssl openssl-devel libnl* libnfnetlink-devel
  • 下载源码
wget http://www.keepalived.org/software/keepalived-2.0.4.tar.gz
  • 在/usr/local/src下解压
# 解压
tar -zxvf keepalived-2.0.4.tar.gz
# 进入目录
cd keepalived-2.0.4

# 创建安装目录
mkdir /usr/local/keepalived
# 配置安装目录
./configure --prefix=/usr/local/keepalived/
#编译
make && make install

如果 ./configure时出错,说明没有安装OpenSS依赖,参考文章开头的依赖安装


centos7源码方式安装配置keepalived_第1张图片
OpenSSL出错

如果出现configure: error: libnfnetlink headers missing,说明没有安装OpenSS依赖,参考文章开头的依赖安装

  • 安装好以后,/usr/local/keepalived/目录下结构:


    image.png
centos7源码方式安装配置keepalived_第2张图片
image.png
centos7源码方式安装配置keepalived_第3张图片
image.png

配置

  • 开机启动
# 创建/etc/keepalived目录
mkdir /etc/keepalived
# 拷贝文件到目录
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# 这个从keepalived源码目录复制,安装目录中没有
cp /usr/local/src/keepalived-2.0.4/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/

# 开机启动
chkconfig keepalived on
service keepalived start   #启动服务
service keepalived stop    #停止服务
service keepalived restart #重启服务
service keepalived status  #状态

#查看keepalived进程
ps -ef | grep keepalived

配置文件说明

Keepalived的所有功能是配置keepalived.conf文件来实现的。

  1. 修改/usr/local/keepalived/etc/keepalived/keepalived.conf配置文件:

TODO。。。

常见问题

  • 日志提示:WARNING - script '/etc/keepalived/check_nginx.sh' is not executable for uid:gid 0:0 - disabling.

原因:keepalived监控脚本没有执行权限
解决:chmod +x /etc/keepalived/check_nginx.sh

  • 日志提示:/etc/keepalived/check_nginx.sh exited due to signal 15

    解决:interval 5 #监控脚本的执行时间要大于advert_int(3秒不行就5秒)

      advert_int 1         #心跳检查间隔时间
    
  • 如果是配置文件出错,那么在执行监控脚本时会输出错误信息,所以要重定向到空

    解决:/usr/local/openresty/nginx/sbin/nginx &>/dev/null

你可能感兴趣的:(centos7源码方式安装配置keepalived)