First, Introduction
Whether it is keepalived or heartbeat do high availability, its high availability, are standing in the server script to say the high availability, rather than the angle of the service.
In other words, if the server down or network failure, high availability can be achieved automatically switch. If the service is running, such as nginx hanging off
These high-availability software is not aware of, need to write their own scripts to implement the service switch.
Second, installation configuration keepalived copy content to clipboard
Code:#./configure
# make
# make Install
# cp/usr/local/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/
# cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
# cp/usr/local/sbin/keepalived/usr/bin/
# chkconfig--add keepalived
# mkdir/etc/keepalived/
# cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/Edit Master's main profile (master:1.1.1.1) copy content to clipboard
Code:# vim/etc/keepalived/keepalived.conf
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass Mdnginx
}
virtual_ipaddress {
1.1.1.100
}
Track_script {
Chk_nginx
}
Third, start service and scripting (both host and standby) copy content to clipboard
Code:# service Nginx Start
# service keepalived Start write monitor nginx script copy content to clipboard
Code:# vim/opt/monnginx.sh
#!/bin/bash
# Author:honway.liu
# date:2013-03-15
If [$ (ps-c nginx--no-header | wc-l)-EQ 0]; Then
Service Nginx Start
Fi
Sleep 3
If [$ (ps-c nginx--no-header | wc-l)-EQ 0]; Then
Service keepalived Stop
Fi improved script, plus alarm function. Copy Content to Clipboard
Code:# vim/opt/monnginx.sh
#!/bin/bash
# Author:honway.liu
# date:2013-03-15
ipaddr=$ (IP addr show Eth0|awk ' {print $} ' | Sed-n 3p)
Contact= (137XXXXXXXX@139.com)
num=${#contact [@]}
function email () {
For ((i=0;i<num;i++));d o
echo "$IPADDR Service Problem" | Mail-s "WARNING" ${contact[i]}---F gm100861@gmail.com
Done
}
If [$ (ps-c nginx--no-header | wc-l)-EQ 0]; Then
Service Nginx Start
Fi
Email
Sleep 3
If [$ (ps-c nginx--no-header | wc-l)-EQ 0]; Then
Service keepalived Stop
Email
Fi here the alarm use is 139 mailbox, in 139 mailbox inside set up have mail, notify to mobile phone, and long letter way.
Need to account for the SendMail service of this machine.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.