Deploy Keepalive high-availability software in Centos, and centoskeepalive
KeepaliveInstallation and deployment
I.Environment Introduction
1) Centos6.4
2) keepalived-1.2.12
3) ip address of the Master/Slave Machine
Master: 172.31.100.5
Slave: 172.31.100.54
Virtault ip: 172.31.100.1
II.Deployment and Installation
Specific deployment steps:
Step 1: Install
Step 2: Configure
Step 3: Run
Step 4: Check
Start now:
1)Install
$ yum install -y gcc make openssl openssl-devel$ wget http://www.keepalived.org/software/keepalived-1.2.12.tar.gz$ tar zxvf keepalived-1.2.12.tar.gz$ cd keepalived-1.2.12$ ./configure --prefix=/usr/local/keepalived$ make && make install
2)Configuration
$ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/$ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/$ cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/$ cp -rf /usr/local/keepalived/etc/keepalived /etc/
A)Master:
$ vi /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs { router_id LVS_DEVEL } vrrp_script chk_haproxy { script "/etc/keepalived/chk_haproxy.sh" interval 2 weight 2 } vrrp_instance VI_1 { interface eth0 state BACKUP priority 101 virtual_router_id 50 garp_master_delay 1 authentication { auth_type PASS auth_pass Hc8scrRddsLsc3 } virtual_ipaddress { 172.31.100.1 } track_script { chk_haproxy } #notify_master "/etc/keepalived/Mailnotify.py backup" #notify_backup "/etc/keepalived/Mailnotify.py master" #notify_fault "/etc/keepalived/Mailnotify.py fault" }
B)Slave:
$ vi /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs { router_id LVS_DEVEL } vrrp_script chk_haproxy { script "/etc/keepalived/chk_haproxy.sh" interval 2 weight 2 } vrrp_instance VI_1 { interface eth0 state BACKUP priority 100 virtual_router_id 50 garp_master_delay 1 authentication { auth_type PASS auth_pass Hc8scrRddsLsc3 } virtual_ipaddress { 172.31.100.1 } track_script { chk_haproxy } notify_master "/etc/keepalived/Mailnotify.py backup" notify_backup "/etc/keepalived/Mailnotify.py master" #notify_fault "/etc/keepalived/Mailnotify.py fault" }
C) Detection scripts and email alarm scripts required on both the master and slave sides:
# Keepalive call this script to check if haproxy stops $ vi/etc/keepalived/chk_haproxy.sh #! /Bin/bashstatus = $ (ps aux | grep haproxy | grep-v grep | grep-v bash | wc-l) if ["$ {status}" = "0"]; then/etc/init. d/haproxy start status2 = $ (ps aux | grep haproxy | grep-v grep | grep-v bash | wc-l) if ["$ {status2}" = "0"]; then/etc/init. d/keepalived stop fifi
# The email alert script is from the Internet: vi $ vi/etc/keepalived/chk_haproxy.sh #! /Usr/bin/env python # coding: UTF-8 from email. MIMEMultipart import MIMEMultipart from email. MIMEText import MIMEText from email. MIMEImage import MIMEImage from email. header import Header import sys import smtplib strFrom = 'xxxxx @ 126.com '# Where the mail comes from strTo = 'receive @ gmail.com' # inbox smtp_server = 'smtp .126.com '# mail server address smtp_user =' send @ 126.com '# send the authorization smtp_pass = 'passwordxx' # password if sys. argv [1]! = "Master" and sys. argv [1]! = "Backup" and sys. argv [1]! = "Fault": sys. exit () else: policy_type = sys. argv [1] mail_title = '[URGENT] Server Load balancer email notification 'mail_body_plain = policy_type +' is activated. Please handle the emergency. 'Mail_body_html = '<B> <font color = red>' + policy_type + 'is activated. Please handle the emergency. </Font> </B> 'msgroot = MIMEMultipart ('related') msgRoot ['subobject'] = Header (mail_title, 'utf-8 ') msgRoot ['from'] = strFrom msgRoot ['to'] = strTo msgAlternative = MIMEMultipart ('alternative ') msgRoot. attach (msgAlternative) msgText = MIMEText (mail_body_plain, 'plain ', 'utf-8') msgAlternative. attach (msgText) msgText = MIMEText (mail_body_html, 'html', 'utf-8') msgAlternative. attach (msgText) smtp = smtplib. SMTP () smtp. connect (smtp_server) smtp. login (smtp_user, smtp_pass) smtp. sendmail (strFrom, strTo, msgRoot. as_string () smtp. quit ()
3)Run
$ /etc/init.d/keepalived start$ chkconfig keepalived on
4)Check
$ Ps aux | grep keeepalived # view process $ ip addr show # used to check whether the address is switched
III.End
The above is the entire deployment process of the software.