快速搭建keepalived(DR)+lvs脚本

#!/bin/bash
#write:blacksnow
echo "Welcome use keepalived+LVS(DR) script!!"
read -p "Keepalived_master_地址: " KL_master
read -p "Keepalived_backup地址: " KL_backup
read -p "报警邮件名(eg:[email protected]): " EM_to
read -p "邮件的发送名(eg:[email protected]): " EM_from
read -p "监测网络的接口(eg:eth0): " interface
read -p "虚拟VIP地址: " vir_VIP
read -p "虚拟访问端口(default 80): " port
port=${port:-80}

read -p "负载调度算法(rr/wrr): " lb_algo
#read -p "负载均衡的机制(NAT/TUN/DR): " lb_kind
lb_kind=‘DR‘
read -p "后端web-1地址: " real1_IP
read -p "后端web-2地址: " real2_IP

NULL="/dev/null"
real1_weight=1
real2_weight=1

####################################################
#调度器Keepalived+lvs(DR)
####################################################
#
#ssh ${KL_master} yum -y install keepalived ipvsadm >${NULL}
#ssh ${KL_backup} yum -y install keepalived ipvsadm >${NULL}
#
####################################################
#Keepalived+lvs(DR)MASTER配置
####################################################

cat <<EOE | ssh ${KL_master} "cat -> /etc/keepalived/keepalived.conf"
! Configuration File for keepalived

global_defs {
notification_email {
${EM_to}
}
notification_email_from ${EM_from}
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER
interface ${interface}
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
${vir_VIP}
}
}

virtual_server ${vir_VIP} ${port} {
delay_loop 6
lb_algo ${lb_algo}
lb_kind ${lb_kind}
persistence_timeout 50
protocol TCP

real_server ${real1_IP} ${port} {
weight ${real1_weight}
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server ${real2_IP} ${port} {
weight ${real2_weight}
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
EOE
####################################################
#Keepalived+lvs(DR)BACKUP配置
####################################################

cat <<EOE | ssh ${KL_backup} "cat -> /etc/keepalived/keepalived.conf"
! Configuration File for keepalived

global_defs {
notification_email {
${EM_to}
}
notification_email_from ${EM_from}
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER
interface ${interface}
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
${vir_VIP}
}
}

virtual_server ${vir_VIP} ${port} {
delay_loop 6
lb_algo ${lb_algo}
lb_kind ${lb_kind}
persistence_timeout 50
protocol TCP

real_server ${real1_IP} ${port} {
weight ${real1_weight}
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server ${real2_IP} ${port} {
weight ${real2_weight}
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
EOE
####################################################
#Realserver 修改ARP内核参数和绑定VIP地址
####################################################
for IP in ${real1_IP} ${real2_IP}
do
cat <<EOE |ssh ${IP} "cat - > /etc/sysconfig/network-scripts/ifcfg-lo:0"
DEVICE=lo:0
IPADDR=${vir_VIP}
NETMASK=255.255.255.255
NETWORK=${vir_VIP}
BROADCAST=${vir_VIP}
ONBOOT=yes
NAME=lo:0
EOE
ssh ${IP} ifup lo:0

cat <<EOE |ssh ${IP} "cat - > /etc/sysctl.conf"
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
EOE
ssh ${IP} sysctl -p > ${NULL}
done

####################################################
#开启keepalived
####################################################
ssh ${KL_master} "systemctl restart keepalived"
ssh ${KL_master} "systemctl enable keepalived"
ssh ${KL_backup} "systemctl restart keepalived"
ssh ${KL_backup} "systemctl enable keepalived"

echo -e "\033[36mSuccessful configure!!\033[0m"

原文地址:http://blog.51cto.com/13762620/2131606

时间: 2024-11-08 15:28:21

快速搭建keepalived(DR)+lvs脚本的相关文章

LVS+keepalived快速搭建测试环境

#LVS+keepalived快速搭建测试环境 #centos6 X64 # LVS 负载均衡模式:DR(直接路由) 192.168.18.31 master(LVS) 192.168.18.32 slave(LVS) 192.168.18.18 VIP 192.168.18.11 web1 192.168.18.12 web2 ################################## #手动配置测试 ###LVS 安装配置 yum install ipvsadm -y rpm -q

centos6.5里搭建LVS+Keepalived(DR模式)集群

最近闲着,整理下以前搭建的服务.. 介绍还是百度下, LVS+Keepalived 介绍LVSLVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一.目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR):十种调度算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq).KeepalviedKeepalived在这里主要用作

RHEL6 搭建 keepalived + lvs/DR 集群

搭建 keepalived + lvs/DR  集群 使用Keepalived为LVS调度器提供高可用功能,防止调度器单点故障,为用户提供Web服务: LVS1调度器真实IP地址为192.168.4.50 LVS2调度器真实IP地址为192.168.4.55 服务器VIP地址设置为192.168.4.252 真实Web服务器地址分别为192.168.4.51.192.168.4.52 实验拓扑图: 实验步骤: 实验准备: 配置yum源 # service iptables stop       

搭建keepalived + lvs DR

简介:lvs 能为服务器提供负载均衡 keepalived 能为lvs服务器提供热备切换,提高可用性.并对服务器池的节点进行健康检查,自动移除故障节点. 一 搭建lvs 1 网络环境: .配置各IP: lvs1:172.16.16.173 :lvs2:172.16.16.174 :web1:172.16.16.175 :web2:172.16.16.177 四台服务器都需配置vip:172.16.16.172以作为负载均衡提供服务. (1)lvs的vip根据eth0的虚接口进行配置 2) 节点服

Oracle Compute云快速搭建MySQL Keepalived高可用架构

最近有个客户在测试Oracle Compute云,他们的应用需要使用MySQL数据库,由于是企业级应用一定要考虑高可用架构,因此有需求要在Oracle Compute云上搭建MySQL高可用集群.客户根据自身的技术储备想要使用Keepalived组件来配合MySQL实现.今天结合Oracle Compute刚刚宣布terraform支持的架构即代码方式,交付给客户一个快速搭建MySQL+Keepalived高可用架构,来帮助他们快速搭建测试环境甚至将来使用到正式环境. MySQL主主复制模式 M

LVS + keepalived(DR) 实战

一.LVS体系结构 使用LVS架设的服务器集群系统有三个部分组成:最前端的负载均衡层,用Load Balancer表示,中间的服务器群组层,用Server Array表示,最底端的数据共享存储层,用Shared Storage表示,在用户看来,所有的内部应用都是透明的,用户只是在使用一个虚拟服务器提供的高性能服务. LVS体系结构如图1所示: 二.LVS 3种负载均衡技术对比 负载均衡技术有很多实现方案,有基于DNS域名轮流解析的方法.有基于客户端调度访问的方法.有基于应用层系统负载的调度方法,

LVS+Keepalived DR模式实现web负载均衡高可用

一.环境介绍: lvs_master:192.168.1.18 lvs_backup:192.168.1.19 web1:192.168.1.16 web2:192.168.1.17 vip:192.168.1.20 二.安装: 在两台lvs上安装lvs+keepalived: yum install lvsadm keepalived -y 在两台web服务器上安装nginx(安装配置略过) 配置keepalived: 主lvs上配置: vim /etc/keepalived/keepaliv

负载均衡高可用之LVS+Keepalived(DR/主备)+apache

负载均衡高可用之LVS+Keepalived(DR/主备)+apache 介绍: LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. LVS集群采用IP负载均衡技术和基于内容请求分发技术.调度器具有很好的吞吐率,将请求均衡地转移到不同的服务器上执行,且调度器自动屏蔽掉服务器的故障,从而将一组服务器构成一个高性能的.高可用的虚拟服务器.整个服务器集群的结构对客户

LVS + keepalived DR 模式

第1章 LVS  + keepalived 负载均衡安装配置笔记 经安装测试能够实现我的这些需要: 双机或多机实现虚拟IP,能够实现IP故障切换 能够连接多台后端真实服务器,实现后端服务器的负载均衡 能够实现双机热备份(同一时间单机工作,故障后切换到另一台) 能够双机虚拟IP且负载均衡(双机即做调度器又做真实服务器) 1.1 LVS (Linux Virtual Server) 虚拟IP,负载均衡调度器,但需要手工动态增加命令,所以需要keepalived来实现自动配合.虚拟IP同时只能存在于某