Centos部署Keepalive高可用软件

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

Keepalive安装部署

一.环境介绍

1)Centos6.4

2) keepalived-1.2.12

3) 主备机的ip

Master:172.31.100.5

Slave: 172.31.100.54

Virtault ip:172.31.100.1

二.部署安装

计划具体部署步骤:

步骤1:安装

步骤2:配置

步骤3:运行

步骤4:检查

现在开始:

1)安装

$ 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)配置

$ 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 Fileforkeepalived

global_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_id50garp_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 Fileforkeepalived

global_defs {

router_id LVS_DEVEL

}

vrrp_script chk_haproxy {

script"/etc/keepalived/chk_haproxy.sh"interval2weight2}

vrrp_instance VI_1 {interfaceeth0

state BACKUP

priority100virtual_router_id50garp_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)主备两边都需要的检测脚本和邮件报警脚本:

#keepalive调用该脚本检测haproxy是否停止

$ vi/etc/keepalived/chk_haproxy.sh

#!/bin/bash

status=$(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

fi

fi

#邮件报警脚本来自网络刘天斯大牛

$ vi/etc/keepalived/chk_haproxy.sh

#!/usr/bin/env python

#coding: utf-8fromemail.MIMEMultipart import MIMEMultipartfromemail.MIMEText import MIMETextfromemail.MIMEImage import MIMEImagefromemail.header import Header

import sys

import smtplib

strFrom='xxxxx@126.com'#邮件来自哪里

strTo='receive@Gmail.com'#收件箱

smtp_server='smtp.126.com'#邮件服务器地址

smtp_user='send@126.com'#发件箱

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='[紧急]负载均衡器邮件通知'mail_body_plain=notify_type+'被激活,请做好应急处理。'mail_body_html='<b><font color=red>'+notify_type+'被激活,请做好应急处理。</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)运行

$ /etc/init.d/keepalived start

$ chkconfig keepalived on

4)检查

$ ps aux|grep keeepalived#查看进程

$ ip addr show #用来查看地址是否切换的

三.结尾

以上是该软件的全部部署过程

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航