Centos 部署Keepalive高可用软件

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/

AMaster:

$ vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_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" 

}

 

 

 

BSlave:

$ vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

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

 

#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-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 = ‘[email protected]‘      #邮件来自哪里
strTo = ‘[email protected]‘    #收件箱
smtp_server=‘smtp.126.com‘     #邮件服务器地址
smtp_user=‘[email protected]‘       #发件箱
smtp_pass=‘passwdxx‘           #密码

if sys.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            #用来查看地址是否切换的

三.结尾

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

时间: 2024-11-17 01:38:53

Centos 部署Keepalive高可用软件的相关文章

mysql运维管理-heartbeat高可用软件的安装及配置

部署Heartbeat高可用需求 1 操作系统 CentOS-6.8-x86_64 2 Heartbeat服务主机资源准备 主服务器A: 主机名:heartbeat-1-130 eth0网卡地址:192.168.1.130(管理IP) eth1网卡地址:10.0.10.4 (心跳IP) 从服务器B: 主机名:heartbeat-1-129 eth0网卡地址:192.168.1.129(管理IP) eth1网卡地址:10.0.10.5(心跳IP) 虚拟VIP: 虚拟VIP在主服务器heartbea

CentOS 7 corosync高可用集群的实现

CentOS 7 corosync高可用集群的实现 =============================================================================== 概述: =============================================================================== 在CentOS 7上实现高可用集群案例  1.corosync安装配置 ★CentOS 7: corosync v2 (

高可用软件Keepalived学习之Keepalived架构学习

最近在测试新游戏的部署方案,我们正在测试的一款手游后端代码部署采用HAProxy+Keepalived的方式进行部署,所以顺便研究下Keepalived的详细资料. Keepalived的官方地址是http://www.keepalived.org/index.html Keepalived是一个用C语言编写的路由软件,它的目的是为Linux系统或基于Linux系统的基础架构提供简单而强壮的负载均衡和高可用机制.负载均衡框架依赖于LVS的内核模块并提供四层负载均衡功能.它可以根据负载均衡器后端的

部署keepalived高可用服务

keepalived服务概念说明 keepalived软件能干什么?Keepalived软件起初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能 Keepalived软件主要是通过VRRP协议实现高可用功能的. VRRP是Virtual Router Redundancy Protocol(虚拟路由器冗余协议)的缩写, VRRP出现的目的就是为了解决静态路由单点故障问题的,它能够保证当个别节点宕机时, 整个网络可以不间断地

Centos 7 MYSQL-MMM高可用

Centos 7 MYSQL-MMM高可用 操作环境: 虚拟机:5台双网卡 第一块内网,第二块外网(虚拟机一定要能上网)192.168.80.100 主数据库1192.168.80.101 主数据库2192.168.80.102 从数据库1192.168.80.103 从数据库2192.168.80.104 监控端 monitor5台虚拟机的防火墙一定要关:systemctl stop firewalld setenforce 0 1.搭建阿里云yum仓库: [Ali] name=CentOS-

keepalive高可用nginx(nginx动静分离)的实现

HA Cluster的配置前提: 1.各节点时间要同步: 2.确保iptables及selinux不会成为障碍: 3.(可选)各节点之间可通过主机名互相通信: 节点的名称设定与hosts文件中解析的主机名都要保持一致: # uname -n 获得的主机,与解析的主机名要相同: 4.(可选)各节点之间基于密钥认证的方式通过ssh互信通信: keepalive高可用nginx(nginx动静分离)的实现 一.各节点时间同步的实现方法 在centos中安装chrony,其根据时间协议配置文件将多台主机

Keepalived高可用软件的安装与配置

监听和替换多台服务器之间的来回切换 一.安装tar zxvf keepalived-1.1.15.tar.gzcd keepalived-1.1.15./configure --prefix=/usr/local/keepalivedmake && make install # 这段配置只是为了使用的方便,可以不这样来操作--------------------------------------------------------------------------------cp ke

ansible部署简单高可用LAMP

ansible部署简单高可用LAMP ansible主机:192.168.152.145HA1(HighAvailable):192.168.152.140HA2:192.168.152.141VIP1(virtualIP):192.168.152.190VIP2:192.168.152.191AP1(Apache+PHP):192.168.152.142AP2(Apache+PHP):192.168.152.143DB:192.168.152.144 配置ansible yum -y inst

keepalive高可用

准备两台主备主机,都安装keepalived yum install -y keepalived master上前期已安装nginxbackup 上使用yum 安装nginx yum install -y nginx 提示错误时没有可用软件包nginx,解决办法: yum install -y epel-release 在主(master)上编辑配置文件vim /etc/keepalived/keepalived.conf global_defs {notification_email { #如