Centos deployment KeepAlive High-availability software

Source: Internet
Author: User
Tags haproxy

Keepalive Installation Deployment

A. Environment Introduction

1) Centos6.4

2) keepalived-1.2.12

3) IP of the master standby machine

master:172.31.100.5

slave:172.31.100.54

Virtault ip:172.31.100.1

two. Deployment Installation

Plan specific deployment steps:

Step 1: Install

Step 2: Configure

Step 3: Run

Step 4: Check

Start Now:

1) installation

$ 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.  A . tar.gz$ CD keepalived-1.2.  A $ . /configure--prefix=/usr/local/&& make install

2) Configuration

$ cp/usr/local/keepalived/sbin/keepalived/usr/sbin//usr/local/keepalived/etc/sysconfig/keepalived/etc/ sysconfig//usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/-rf/usr/local/ keepalived/etc/keepalived/etc/

A ) Master:

$ vi/etc/keepalived/keepalived.conf! Configuration File forkeepalivedglobal_defs {router_id Lvs_devel} vrrp_script chk_haproxy {script"/etc/keepalived/chk_haproxy.sh"interval2Weight2} vrrp_instance vi_1 {Interfaceeth0 State BACKUP Priority101virtual_router_id -Garp_master_delay1Authentication {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 forkeepalivedglobal_defs {router_id Lvs_devel} vrrp_script chk_haproxy {script"/etc/keepalived/chk_haproxy.sh"interval2Weight2} vrrp_instance vi_1 {Interfaceeth0 State BACKUP Priority -virtual_router_id -Garp_master_delay1Authentication {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 ) Primary and standby detection scripts and mail alert scripts required on both sides :

#keepalive调用该脚本检测haproxy是否停止 $ 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

#邮件报警脚本 from Network Liu Tians Daniel $ VI/etc/keepalived/chk_haproxy.sh#!/usr/bin/Env Python#coding:utf-8  fromemail. Mimemultipart Import Mimemultipart fromemail. Mimetext Import Mimetext fromemail. Mimeimage Import Mimeimage fromemail.header Import Header import sys import smtplib strfrom='[email protected]'#邮件来自哪里strTo='[email protected]'#收件箱smtp_server='smtp.126.com'#邮件服务器地址smtp_user='[email protected]'#发件箱smtp_pass='passwdxx'#密码ifsys.argv[1]!="Master"and sys.argv[1]!="Backup"and sys.argv[1]!="Fault": Sys.exit ()Else: Notify_type=sys.argv[1] Mail_title='[emergency] load balancer mail notification'Mail_body_plain=notify_type+'be activated, please do the emergency treatment. 'mail_body_html='<b><font color=red>'+notify_type+'be activated, please do the emergency treatment. </font></b>'Msgroot= Mimemultipart ('related') msgroot['Subject'] =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 #查看进程 $ IP addr Show           #用来查看地址是否切换的

three. End

The above is the entire deployment process of the software

Centos deployment KeepAlive High-availability software

Related Article

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.