Deploy Keepalive high-availability software in Centos

Source: Internet
Author: User
Tags haproxy

Deploy Keepalive high-availability software in Centos
I. environment Introduction 1) Centos6.4 2) keepalived-1.2.12 3) Master ip Master: 172.31.100.5 Slave: 172.31.100.54 Virtault ip: 172.31.100.1 II. deployment and installation plan specific deployment steps: Step 1: Installation Step 2: configuration Step 3: Run Step 4: Check now start: 1) install $ yum install-y gcc make 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) configure $ cp/usr/local/keepalived/sbin/keepalived/usr/sbin/$ cp/usr/local/keepalived/etc/sysconfig/$ cp/ usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/$ cp-rf/usr/local/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) Check 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 alarm script is from the Internet: Liu tiansi Daniel $ 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 # Check the process $ ip addr show # Check whether the address is switched. the above is the entire deployment process of the software.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.