centos7 install keepalived problem

● 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.

Precautions for building keepalived:

surroundings

Main nginx [load balance] (https://cloud.tencent.com/product/clb?from=10680) device: 192.168.5.129 (VIP is configured through keepalived: 192.168.5.101/0 for external use)
Deputy nginx load balancer: 192.168.5.130 (VIP is configured through keepalived: 192.168.5.101/0 for external use)

  1. Install 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
  1. Configure keepalived file
copy/sbin/keepalived to/usr/sbin
> cp /keepalived/sbin/keepalived /usr/sbin/

keepalived will read by default/etc/keepalived/keepalived.conf configuration file
> mkdir /etc/keepalived
> cp /keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

Copy the sysconfig file to/etc/under sysconfig
> cp /keepalived/etc/sysconfig/keepalived /etc/sysconfig/

Copy the startup script to/etc/init.under d
> cd /keepalived-1.3.4> cp ./keepalived/etc/init.d/keepalived /etc/init.d/> chmod 755/etc/init.d/keepalived
  
  1. Configure keepalived.conf startup file
! Configuration File for keepalived

global_defs {
 notification_email {
  [email protected]
  [email protected]
  [email protected]
   }
 notification_email_from [email protected]
 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)interfaceens33--Pay attention to the network card name
 virtual_router_id 51
 priority 50
 advert_int 1
 authentication {
  auth_type PASS
  auth_pass 1111}
    
 virtual_ipaddress {192.168.5.100192.168.5.101}}
  1. Start and verify keepalievd
service keepalived start
systemctl status keepalived.service

  1. Remaining issues:

When the service is started, the service is automatically closed for a period of time; (about a few minutes later)

  1. Set centos7 to start the service automatically
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 reload

2: systemctl enable keepalived.service set to start automatically

3: systemctl disable keepalived.service cancel automatic startup

4: systemctl start keepalived.service start

5: systemctl stop keepalived.service stop

Set nginx to start automatically

vim /lib/systemd/system/keepalived.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 start nginx

systemctl stop nginx.service ends nginx

systemctl restart nginx.service restart nginx
  1. Configure listening file
vi /root/check_nginx.sh

#! /bin/bash
if[`ps -C nginx --no-header |wc -l`-eq 0]
 then
 systemctl start nginx.service
 sleep 2if[`ps -C nginx --no-header |wc -l`-eq 0]
   then
    systemctl stop keepalived.service
 fi
fi
chmod +x /root/check_nginx.sh
Add to job plan
crontab -e
* /1****/root/check_nginx.sh >>/root/check_nginx.log

Append keepalived.conf file

vrrp_script check_nginx {                   ######Define the script to monitor nginx
 script "/root/check_nginx.sh"
 interval 2                            ######Monitoring interval
 weight 2                              ######Load parameter
}

vrrp_instance vrrptest {
track_script {                       
 check_nginx
}

8. Knowledge supplement: learn shell programming

Recommended Posts

centos7 install keepalived problem
1.5 Install Centos7
Install and configure keepalived under CentOS 5.9
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
CentOS7 install MySQL
Centos7 install protobuf
CentOS 7 install Docker
CentOS7 install GlusterFS
CentOS 7.4 install Zabbix 3.4
CentOS7 install Docker
Centos6.5 install Tomcat
Vmware install CentOS6
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
CentOS6 install mist.io
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
centos7 install docker
CentOS install jdk
centos7 install nginx-rtmp
Centos6.3 install KVM
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS 7 install Java 1.8
CentOS8 install fastdfs6.06
CentOS 7 install Gitlab
Centos 7 install PostgreSQL
CentOS7 install MySQL8
CentOS 7 install Java 1.8
CentOS 6 install Docker
centos 6.5 install zabbix 4.4
Centos8 install Docker
CentOS6.8 install python2.7
CentOS install nodejs 8
CentOS6.5 install GNS3
centos 7.5 install mysql5.7.17
Centos7 install MySQL8.0-manual
CentOS7 install Kubernetes 1.16.3
VirtualBox install centos7
centos7 install lamp
Centos7 compile and install MySQL8 problem record
Install centos7 and connect
Install Docker on Centos7
Centos7 install docker-18.x original
install LNMP on centos7.4
Centos7 YUM install MariaDB 10.0
CentOS 8 install ZABBIX4.4 guide