[转载]LVS+Keepalived之三大模式
LVS + Keepalived之三大模式
======================================================================================
NAT模式:
======================================================================================
一、仅lvs服务器端安装
yum install ipvsadm openssl-devel popt popt-devel libnl-devel
cd /opt/src/
tar xzvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make && make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/ 修改/etc/keepalived/keepalived.conf文件
[root@WEB ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email { 123@123.com
}
notification_email_from 123@123.com
smtp_server mail.123.com
smtp_connect_timeout 30
router_id LVS_DEVEL
} vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
88.88.88.88
}
}
vrrp_instance LAN_GATEWAY {
state MASTER
interface eth1
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.88
}
}
virtual_server 88.88.88.88 80 {
delay_loop 6
lb_algo lc
#lb_kind DR
#lb_kind TUN
lb_kind NAT
persistence_timeout 60
protocol TCP real_server 192.168.1.18 80 {
weight 3
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 2
connect_port 80
}
}
real_server 192.168.1.68 80 {
weight 3
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 2
connect_port 80
}
}
}
[root@WEB ~]#
[root@WEB ~]# service ipvsadm start
[root@WEB ~]# service keepalived start 注意:
echo "1" > /proc/sys/net/ipv4/ip_forward 二、实际服务器端的操作
将网关设置为lanvip的地址192.168.1.88 三、lvs查看 ipvsadm -ln
ipvsadm -lnc
ipvsadm -l -n --stats 调度算法:rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq
======================================================================================
TUN模式:
======================================================================================
一、仅lvs服务器端安装
yum install ipvsadm openssl-devel popt popt-devel libnl-devel
cd /opt/src/
tar xzvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make && make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/ 修改/etc/keepalived/keepalived.conf文件
[root@WEB ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
123@123.com
}
notification_email_from 123@123.com
smtp_server mail.123.com
smtp_connect_timeout 30
router_id LVS_DEVEL
} vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.88
}
}
virtual_server 192.168.1.88 80 {
delay_loop 6
lb_algo lc
lb_kind TUN
persistence_timeout 60
protocol TCP real_server 192.168.2.18 80 {
weight 3
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 2
connect_port 80
}
}
real_server 192.168.3.68 80 {
weight 3
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 2
connect_port 80
}
}
}
[root@WEB ~]#
[root@WEB ~]# service ipvsadm start
[root@WEB ~]# service keepalived start 注意:
打开转发或关闭,dr/tun模式无影响
echo "1" > /proc/sys/net/ipv4/ip_forward 二、实际服务器端的操作
[root@]# cat /usr/local/vip_tun.sh
#!/bin/bash
#srcipt to start LVS TUN realserver VIP=192.168.1.88
case "$1" in start)
#start LVS-TUN real server on this machine
echo 1 >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 2 >/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
echo 0 >/proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 >/proc/sys/net/ipv4/conf/all/rp_filter
sysctl -p >/dev/null 2>&1
/sbin/modprobe ipip
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
/sbin/ifconfig eth0 mtu 1440 ;;
stop)
#stop lvs-TUN real server loopback device
echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
/sbin/ifconfig tunl0 down
/sbin/modprobe -r ipip
/sbin/ifconfig eth0 mtu 1500 ;;
status)
islothere='/sbin/ifconfig tunl0 |grep $VIP'
isrothere='netstat -rn |grep "tunl0"|grep $VIP'
if [ ! "$islothere" -o ! "$isrothere" ];then
echo "LVS-TUN real server stopped"
else echo "LVS-TUN Running"
fi
;;
*)
echo "$0: Usage: $0 {start|stop|status}"
exit 1
;;
esac
[root@localhost ~]# /usr/local/vip.sh start|stop|status 三、lvs查看 ipvsadm -ln
ipvsadm -lnc
ipvsadm -l -n --stats 调度算法:rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq
======================================================================================
DR模式:
======================================================================================
一、仅lvs服务器端安装
yum install ipvsadm openssl-devel popt popt-devel libnl-devel
cd /opt/src/
tar xzvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make && make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/ 修改/etc/keepalived/keepalived.conf文件
[root@WEB ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
notification_email { 123@123.com
}
notification_email_from 123@123.com
smtp_server mail.123.com
smtp_connect_timeout 30
router_id LVS_DEVEL
} vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.88
}
}
virtual_server 192.168.1.88 80 {
delay_loop 6
lb_algo lc
lb_kind DR
persistence_timeout 60
protocol TCP real_server 192.168.1.18 80 {
weight 3
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 2
connect_port 80
}
}
real_server 192.168.1.68 80 {
weight 3
TCP_CHECK {
connect_timeout 30
nb_get_retry 3
delay_before_retry 2
connect_port 80
}
}
}
[root@WEB ~]#
[root@WEB ~]# service ipvsadm start
[root@WEB ~]# service keepalived start 注意:
打开转发或关闭,dr/tun模式无影响
echo "1" > /proc/sys/net/ipv4/ip_forward 二、实际服务器端的操作
[root@localhost ~]# cat /usr/local/vip.sh
#!/bin/bash
# Script to start LVS DR real server.
# description: LVS DR real server
. /etc/rc.d/init.d/functions
VIP=192.168.1.88
#host=`/bin/hostname`
case "$1" in
start)
# Start LVS-DR real server on this machine.
/sbin/ifconfig lo down
/sbin/ifconfig lo up
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add $VIP dev lo:0
;;
stop)
# Stop LVS-DR real server loopback device(s).
/sbin/ifconfig lo:0 down
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
;;
status)
# Status of LVS-DR real server.
islothere=`/sbin/ifconfig lo:0 | grep $VIP`
isrothere=`netstat -rn | grep "lo:0" | grep $VIP`
if [ ! "$islothere" -o ! "isrothere" ];then
# Either the route or the lo:0 device
# not found.
echo "LVS-DR real server Stopped."
else
echo "LVS-DR real server Running."
fi
;;
*)
# Invalid entry.
echo "$0: Usage: $0 {start|status|stop}"
exit 1
;;
esac
[root@localhost ~]# /usr/local/vip.sh start|stop|status 三、lvs查看 ipvsadm -ln
ipvsadm -lnc
ipvsadm -l -n --stats 调度算法:rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq 注意:
1.TUN模式使用的IP都要是公网IP.
2.VIP的port要和后端realserver的port保持一致,但是不会影响VIP本机的port被其他服务使用. 转载自:http://www.gaizaoren.com/archives/998
附加:
LVS可以使用iptables同时做多个服务的负载均衡并实现持久化连接,使用iptables对包打上标签之后再进行匹配处理。配置如下:
[转载]LVS+Keepalived之三大模式的更多相关文章
- LVS + KEEPAlived 配置 DIR模式
1 .1 Lvs LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目 ...
- 借助LVS+Keepalived通过DR模式实现负载均衡
1.测试环境4台server,全部初始化一下,该关的关了 # vim /etc/hosts 192.168.1.101 lvs-master DIP 192.168.1.102 lvs-slave D ...
- LVS+keepalived 的DR模式的两种做法
LVS DR模式搭建 准备工作 三台机器: dr:192.168.13.15 rs1:192.168.13.16 rs2: 192.168.13.17 vip:192.168.13.100 修改DR上 ...
- LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)
一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Red ...
- LVS+Keepalived 高可用环境部署记录(主主和主从模式)
之前的文章介绍了LVS负载均衡-基础知识梳理, 下面记录下LVS+Keepalived高可用环境部署梳理(主主和主从模式)的操作流程: 一.LVS+Keepalived主从热备的高可用环境部署 1)环 ...
- DR模式下的高可用的LVS(LVS+keepalived)
一.keepalived 在DR模式下,使用Keepalived实现LVS的高可用.Keepalived的作用是检测服务器的状态,如果有一台web服务器 宕机,或工作出现故障,Keepalived将检 ...
- CentOS高可用集群LVS+Keepalived(DR模式)
操作系统:CentOS6.5_x64 mini 负载均衡模式:DR(直接路由) LVS与Keepalived简述: LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是 ...
- 【大型网站技术实践】初级篇:借助LVS+Keepalived实现负载均衡
一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务器集群技术,集群即将相同服务部署在多台服务器上构成一个集群整体对外提供服务,这些集群可以是Web应用服务 ...
- 借助LVS+Keepalived实现负载均衡(转)
原文:http://www.cnblogs.com/edisonchou/p/4281978.html 一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务 ...
随机推荐
- 【编程技巧】NSTimer类的使用
创建一个 Timer + scheduledTimerWithTimeInterval: invocation: repeats: + (NSTimer *)scheduledTimerWithTim ...
- Moogoose Constructor小坑
注意! exports 出来的 Model名字,必须和 Constructor的名字不一样!!! 不然Constructor会被覆盖,报错 这个是修改之后的.修改前,是var account = ne ...
- Codeforces 437 D. The Child and Zoo 并查集
题目链接:D. The Child and Zoo 题意: 题意比较难懂,是指给出n个点并给出这些点的权值,再给出m条边.每条边的权值为该条路连接的两个区中权值较小的一个.如果两个区没有直接连接,那么 ...
- Ajax常用实例
摘录自:http://www.cnblogs.com/gaopeng527/p/4459622.html 1. 级联下拉列表 例1.1 级联下拉列表. (1)编写AjaxRequest.js文件,并将 ...
- linux tpm 测试完整记录,亲测有效。
没有tpm芯片,采用模拟器的方式来测试. 实验环境:内核版本 3.10.0-327 软件包准备: 内网,没有仓库,自己网上下载: 1. cmake-3.9.6-Linux-x86_64.tar.gz ...
- Linux安装mysql 在/etc下没有my.cnf 解决办法
进入 /usr/share/mysql 将my-medium.cnf 移动到etc 并且改名为my.cnf
- CDuiString和String的转换
很多时候 难免用到CDuiString和string的转换. 我们应该注意到,CDuiString类有个方法: LPCTSTR GetData() const; 可以通过这个方法,把CDuiStrin ...
- maven系列--eclipse的m2插件
工欲善其事,必先利其器.我是讨厌用CMD指令来操作maven,既然eclipse已经给我们提供了插件,那我们为什么不使用呢?而且我觉得eclipse的各种插件都挺好用的.好了废话不多说了,现在开始整理 ...
- mysql5.7安装配置,常用命令,常见问题
1.安装配置 参考:http://www.cnblogs.com/Fiona20170420/p/6738185.html 1. 下载 2. 解压缩 3. 添加path环境变量,路径指向mysql所在 ...
- 百度插件webuploader的坑!
前言: 自因为项目中需要使用上传插件,所以之前找了几款上传插件.但是呢,小的上传插件是不支持我们项目上传的(做虚拟机项目的,一个镜像可能好几个G),所以呢这个插件要支持分片上传,拓展性要高(肯定的啦, ...