● 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)
tar xf keepalived-1.3.4.tar.gz
cd keepalived-1.3.4./configure --prefix=/usr/local/keepalived
make && make install
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
! 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}}
service keepalived start
systemctl status keepalived.service
When the service is started, the service is automatically closed for a period of time; (about a few minutes later)
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
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