● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: failed (Result: resources) since Sat 2018-08-04 13:06:35 EDT; 16s ago
Process: 3435 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)

Aug 04 13:06:35 localhost.localdomain systemd[1]: Starting LVS and VRRP High Availability Monitor...
Aug 04 13:06:35 localhost.localdomain systemd[1]: PID file /var/run/keepalived.pid not readable (yet?) after start.
Aug 04 13:06:35 localhost.localdomain systemd[1]: Failed to start LVS and VRRP High Availability Monitor.
Aug 04 13:06:35 localhost.localdomain systemd[1]: Unit keepalived.service entered failed state.
Aug 04 13:06:35 localhost.localdomain systemd[1]: keepalived.service failed.

搭建keepalived注意事项:

环境

主nginx负载均衡器:192.168.5.129 (通过keepalived配置了VIP:192.168.5.101/0供外使用)
副nginx负载均衡器:192.168.5.130(通过keepalived配置了VIP:192.168.5.101/0供外使用)

1.安装 keepalived-1.4.1

 tar xf keepalived-1.3.4.tar.gz
cd keepalived-1.3.4
./configure --prefix=/usr/local/keepalived
make && make install

2.配置keepalived文件

复制/sbin/keepalived到/usr/sbin下
> cp /keepalived/sbin/keepalived /usr/sbin/ keepalived默认会读取/etc/keepalived/keepalived.conf配置文件
> mkdir /etc/keepalived
> cp /keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ 复制sysconfig文件到/etc/sysconfig下
> cp /keepalived/etc/sysconfig/keepalived /etc/sysconfig/ 复制启动脚本到/etc/init.d下
> cd /keepalived-1.3.4
> cp ./keepalived/etc/init.d/keepalived /etc/init.d/
> chmod 755 /etc/init.d/keepalived
  

3.配置keepalived.conf启动文件

! Configuration File for keepalived

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
} vrrp_instance VI_1 {
state MASTER(BACKUP)
interface ens33 -- 注意网卡名字
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
} virtual_ipaddress {
192.168.5.100
192.168.5.101
}
}

4.启动与验证keepalievd  <ip addr list>

service keepalived start
systemctl status keepalived.service

ps -aux|grep keepalived

 

5. 遗留问题:

当服务启动后一段时间就自动关闭了服务;(大约几分钟后)

原因:并未设置监听服务,导致自动关闭服务

6. 设置centos7开机自动启动服务

vim /lib/systemd/system/keepalived.service
[Unit]
Description=Keepalived
After=syslog.target network.target remote-fs.target nss-lookup.target [Service]
Type=forking
PIDFile=/var/run/keepalived.pid
ExecStart=/usr/local/keepalived/sbin/keepalived -D
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true [Install]
WantedBy=multi-user.target
1;systemctl daemon-reload  重新加载

2:systemctl enable keepalived.service  设置开机自动启动

3:systemctl disable keepalived.service 取消开机自动启动

4:systemctl start keepalived.service 启动

5:systemctl stop keepalived.service停止

  

设置nginx开机自启动

vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true [Install]
WantedBy=multi-user.target
systemctl enable nginx.service

systemctl start nginx.service    启动nginx

systemctl stop nginx.service    结束nginx

systemctl restart nginx.service    重启nginx

7.配置监听文件

vi /root/check_nginx.sh

#!/bin/sh
count=`ps aux | grep nginx | grep -v grep | wc -l`
if [ $count -eq 0 ]
then
  echo "running....., please starting...."
  systemctl start nginx.service
  sleep 2
else
  echo "running...."
fi

chmod +x /root/check_nginx.sh

  

加入到作业计划
crontab -e
*/1 * * * * /root/check_nginx.sh >>/root/check_nginx.log

追加keepalived.conf文件

! Configuration File for keepalived


global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}


vrrp_script check_nginx {
script "/root/check_nginx.sh"
interval 2
weight 2
}


vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
mcast_src_ip 192.168.5.129
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 111111
}


track_script { ######执行监控nginx进程的脚本
check_nginx
}
virtual_ipaddress {
192.168.5.100
}
}


参考:用shell脚本监控进程是否存在 不存在则启动的实例

8.知识补充:学习shell编程

9. usr/bin 与 usr/local/bin 的区别

usr/bin 是系统自带的应用

usr/local/bin 是自己安装的应用和自己写的全局脚本

centos7安装keepalived问题的更多相关文章

  1. Centos7 安装keepalived实现高可用

    场景:尝试安装keepalived实现高可用,进而在suse环境中部署. 测试过程需要配合Nginx的相关知识:Centos7 Nginx安装 1 安装过程 问题 !!! OpenSSL is not ...

  2. centos7 安装keepalived

    node1 192.168.5.101 node2 192.168.5.102 1.安装 openssl openssl-devel yum install openssl openssl-devel ...

  3. Centos7安装keepalived(自定义路径安装)-高级篇

    0.Keepalived介绍 Keepalived是一个基于VRRP协议来实现的服务高可用方案,可以利用其来避免IP单点故障,类似的工具还有heartbeat.corosync.pacemaker.但 ...

  4. Centos7 安装 Keepalived

    目标: Keeplaived 简单模拟测试一下Nginx 故障切换前言:C7 默认的 1.3.5 似乎有点问题,改装 keepalived-2.0.7 1:安装 Nginx 和确认 (略)2:安装配置 ...

  5. Centos7+LVS-DR+keepalived实验(包含sorry-server、日志、及HTTP-GET的健康检测)

    目录检索 一.简介 1.lvs-dr原理请参考原理篇 2.keepalived原理请参考原理篇 3.基于lvs-dr+keepalived故障切换架构图如下: 二.部署 1.环境 2.准备RS的web ...

  6. CentOS7.4 Keepalived+LVS 负载均衡 后台节点健康检查

    主机信息 VIP 10.10.10.55 LVS01 10.10.10.59 Web01 10.10.10.60 Web02 10.10.10.61 一.apache简单配置 1.(10.10.10. ...

  7. linux下安装keepalived

    keepalived安装文档 1. 安装环境 su - root yum -y install kernel-devel* yum -y install openssl-* yum -y instal ...

  8. HP服务器 hp 360g5 centos7安装问题

    HP服务器  hp 360g5 centos7安装问题 一 :启动盘无法识别硬盘 1.进入安装光盘,用上下键选择安装centos--Install Centos7(注意不可按Enter键),如图: 2 ...

  9. CentOS7 安装Mono及Jexus

    CentOS7安装Mono及Juxes 1 安装Mono 1.1 安装yum-utils 因为安装要用到yum-config-manager,默认是没有安装的,所以要先安装yum-utils包.命令如 ...

随机推荐

  1. svn Mac

    将已有项目放到svn服务端 svn import 已有项目地址 服务端地址 -m '注释必须填写' 例子 svn import /Applications/Emma/workspace/tansun/ ...

  2. Requests对HTTPS请求验证SSL证书

    SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socket layer(SSL)安全协议是由Netscape Communication公司设计开发.该安全协议主 ...

  3. 如何查看java的class文件

    1.首先拿到javac文件 例如:test.class 2.可以使用文本编辑器用二进制的方式打开() cafe babe 0000 0034 0056 0a00 1200 3209 0010 0033 ...

  4. 工程C++基础

    大家好,我是老A.今天我们要学习的是工程C++,这是一个不可描述的东西.我主要讲的是template. template的用处是装逼,所以很重要. C++配备了函数模板和类模板.函数模板就是我们平时的 ...

  5. 2018 pycharm最近激活码

    今天更新了一下pycharm,结果之前的激活就不能用了,下面是新的激活方法: 1.mac下在终端进入etc目录: cd /etc 2.编辑hosts文件: vi hosts 将“0.0.0.0 acc ...

  6. texmaker报错:could not start command 解决

    我当时文件命名加了邮箱,引入特殊字符@,然后就报错了

  7. 微商城分享 包括app分享 微信分享

    <template> <div class="spr"> <img src="../../assets/images/activity/sh ...

  8. Cdnbest的cdn程序默认支持web Socket

    Cdnbest的cdn程序默认支持web Socket    WSS 是 Web Socket Secure 的简称, 它是 WebSocket 的加密版本. 我们知道 WebSocket 中的数据是 ...

  9. kettle学习笔记(二)——kettle基本使用

    一.子程序功能和启动方式介绍 Spoon.bat: 图形界面方式启动作业和转换设计器. Pan.bat: 命令行方式执行转换. Kitchen.bat: 命令行方式执行作业. Carte.bat: 启 ...

  10. java学习笔记(三):类和对象

     创建对象 构造器 每一个类都有一个构造器. 如果我们不单独为一个类编写构造器那么 Java 的编译器将会给这个类建立一个默认的构造器. 每当一个新的对象被创建,至少一个构造器将会被调用. 构造器的一 ...