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上的/etc/sysctl.conf文件

net.ipv4.ip_forward=0改为net.ipv4.ip_forward=1

第一种做法lo

Dr上的配置

! Configuration File for Keepalived
! ---------------------------------------------------------------------------
! GLOBAL
! ---------------------------------------------------------------------------
global_defs {
	! this is who emails will go to on alerts
	notification_email {
		[email protected]
		! add a few more email addresses here if you would like
	}
	notification_email_from [email protected]

	! mail relay server
	smtp_server 127.0.0.1
	smtp_connect_timeout 30
	! each load balancer should have a different ID
	! this will be used in SMTP alerts, so you should make
	! each router easily identifiable
	router_id LVS_13.100
}
vrrp_instance VI1_LVS_CN {
	state MASTER
	interface eth1
	! interface to run LVS sync daemon on
	lvs_sync_daemon_interface eth1
	!mcast_src_ip 192.168.13.15
	virtual_router_id 100
	priority 100
	advert_int 1
	smtp_alert
	authentication {
		auth_type PASS
		auth_pass qw_web
	}
	! these are the IP addresses that keepalived will setup on this
	! machine. Later in the config we will specify which real
	! servers  are behind these IPs without this block, keepalived
	! will not setup and takedown any IP addresses
	virtual_ipaddress {
		192.168.13.100
	}
}

virtual_server 192.168.13.100 80 {
	! interval between checks in seconds
	delay_loop 5
	! use weighted least connection as a load balancing algorithm
	lb_algo wrr
	! lvs_sched wrr
	! we are doing Direct Routing
	lb_kind DR
	! lvs_method DR
	protocol TCP
	! WEB01
	real_server 192.168.13.16 80 {
		weight 100
		HTTP_GET {
			url {
				path /.keepalived
				status_code 200
			}
			connect_timeout 10
			nb_get_retry 3
			delay_before_retry 5
		}
	}
	! WEB02
	real_server 192.168.13.17 80 {
		weight 100

		HTTP_GET {
			url {
				path /.keepalived
				status_code 200
			}
			connect_timeout 10
			nb_get_retry 3
			delay_before_retry 5
		}
	}
}

两台Rs上的这配置

[[email protected] shell]# more realserver.sh
#!/bin/bash
vip=192.168.13.100
case "$1" in
start)
	ifdown lo
	ifup lo
	ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
	/sbin/route add -host $vip lo:0
	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
	;;
stop)
	ifdown lo
        ifup lo
        /sbin/route del -host $vip lo:0
        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
        ;;
*)
        echo "Usage: $0 {start|stop}"
        exit 1
esac
exit 0 

第二种做法iptables

Dr上的配置(同第一种一致)

! Configuration File for Keepalived
! ---------------------------------------------------------------------------
! GLOBAL
! ---------------------------------------------------------------------------
global_defs {
	! this is who emails will go to on alerts
	notification_email {
		[email protected]
		! add a few more email addresses here if you would like
	}
	notification_email_from [email protected]

	! mail relay server
	smtp_server 127.0.0.1
	smtp_connect_timeout 30
	! each load balancer should have a different ID
	! this will be used in SMTP alerts, so you should make
	! each router easily identifiable
	router_id LVS_13.100
}
vrrp_instance VI1_LVS_CN {
	state MASTER
	interface eth1
	! interface to run LVS sync daemon on
	lvs_sync_daemon_interface eth1
	!mcast_src_ip 192.168.13.15
	virtual_router_id 100
	priority 100
	advert_int 1
	smtp_alert
	authentication {
		auth_type PASS
		auth_pass qw_web
	}
	! these are the IP addresses that keepalived will setup on this
	! machine. Later in the config we will specify which real
	! servers  are behind these IPs without this block, keepalived
	! will not setup and takedown any IP addresses
	virtual_ipaddress {
		192.168.13.100
	}
}

virtual_server 192.168.13.100 80 {
	! interval between checks in seconds
	delay_loop 5
	! use weighted least connection as a load balancing algorithm
	lb_algo wrr
	! lvs_sched wrr
	! we are doing Direct Routing
	lb_kind DR
	! lvs_method DR
	protocol TCP
	! WEB01
	real_server 192.168.13.16 80 {
		weight 100
		HTTP_GET {
			url {
				path /.keepalived
				status_code 200
			}
			connect_timeout 10
			nb_get_retry 3
			delay_before_retry 5
		}
	}
	! WEB02
	real_server 192.168.13.17 80 {
		weight 100

		HTTP_GET {
			url {
				path /.keepalived
				status_code 200
			}
			connect_timeout 10
			nb_get_retry 3
			delay_before_retry 5
		}
	}
}

两台Rs上的这配置

[[email protected] shell]# iptables -t nat -A PREROUTING -p tcp -d 192.168.13.100 --dport 80 -j REDIRECT
[[email protected] shell]# iptables -t nat -A OUTPUT -p tcp -d 192.168.13.100 --dport 80 -j REDIRECT

以上两种方式均可实现DR模式。

原文地址:https://www.cnblogs.com/xzlive/p/9235395.html

时间: 2024-07-30 17:41:45

LVS+keepalived 的DR模式的两种做法的相关文章

Lvs群集(DR/NAT)两种模式配置

-----构建DR 模式的LVS 群集----- --client----------LVS-----------WEB1 2.2.2.100    eth0:2.2.2.10    eth0:2.2.2.20 子接口eth0:0:2.2.2.2   lo:0:2.2.2.2 ------------WEB2--------- eth0:2.2.2.30 lo:0:2.2.2.2 一.配置LVS 调度器 1.配置IP 和VIP [[email protected] ~]# vim /etc/sy

LVS+keepalived搭建DR模式架构实验

环境: CentOS6.4  64bit ipvsadm-1.24.tar.gz keepalived-1.1.19.tar.gz IP部署: VIP:172.16.100.5 DIP1:172.16.100.1 DIP2:172.16.100.2 RIP1:172.16.100.3 RIP2:172.16.100.4 说明:VIP在防火墙上做映射 安装: ln  -s  /usr/src/kernels/2.6.32-358.el6.x86_64/  /usr/src/linux tar  z

[转载]LVS+Keepalived之三大模式

LVS + Keepalived之三大模式 ====================================================================================== NAT模式: ====================================================================================== 一.仅lvs服务器端安装 yum install ipvsadm openssl-devel

LVS学习笔记--DR模式部署

一.部署环境: 服务器版本:CentOS6.5(Finnal) 网络拓扑: 二.需求分析:调度服务器与网页服务器均在同一网段局域网环境,用户提交的请求会经过调度器的分配指定到网页服务器,同时保证服务高可用性(任意一台网站服务器宕机后调度器会剔除它直至服务器恢复至正常:主调度器宕机后从调度器会接管它直至其恢复正常.). 三.相关配置: 部署调度器LVS服务脚本: #!/bin/sh mkdir tools cd tools/ # yum install lrzsz # rz # ls wget h

探究Repository模式的两种写法与疑惑

现如今DDD越来越流行,园子里漫天都是介绍关于它的文章.说到DDD就不能不提Repository模式了,有的地方也叫它仓储模式. 很多时候我们对Repository都还停留在Copy然后使用的阶段, 我注意到Repository模式有两种流行的设计方式. 今天我就是想跟大家讨论下这两种设计方式之间的区别,同时弄清楚哪种方式更合理(无需纠结代码细节),见下图: 左右两边代码比较: 1.左边的Repository代码在实际使用中是最常见的,右边的使用更少一些. 2.左边代码的更难理解一些,右边的代码

flink on yarn模式下两种提交job方式

flink on yarn模式下两种提交job方式 https://juejin.im/post/5bf8dd7a51882507e94b8b15 https://www.cnblogs.com/asker009/p/11327533.html https://ci.apache.org/projects/flink/flink-docs-release-1.9/ops/deployment/yarn_setup.html#flink-yarn-session 原文地址:https://www.

SqlServer保留几位小数的两种做法

SqlServer保留几位小数的两种做法   数据库里的 float momey 类型,都会精确到多位小数.但有时候 我们不需要那么精确,例如,只精确到两位有效数字. 解决: 1. 使用 Round() 函数,如 Round(@num,2) 参数 2 表示 保留两位有效数字. 2. 更好的方法是使用 Convert(decimal(18,2),@num) 实现转换,decimal(18,2) 指定要保留的有效数字. 这两个方法有一点不同:使用 Round() 函数,如果 @num 是常数,如 R

jqGrid中实现radiobutton的两种做法

http://blog.sina.com.cn/s/blog_4f925fc30102e27j.html   jqGrid中实现radiobutton的两种做法 -------------------------------------------------------------------------------------------------- 第一种:colModel: [                {                    name: 'MY_ID',    

SPOJ 1812 LCS2 - Longest Common Substring II (后缀自动机)【两种做法】

手动博客搬家: 本文发表于20181217 23:54:35, 原地址https://blog.csdn.net/suncongbo/article/details/85058680 人生第一道后缀自动机. 说实话SAM我还没学多么明白. 但是题还是要做的. 说起来这玩意真的很妙.可惜我智商低理解不了. 再次验证了代码能力菜到没边.hyw 30min写完我写2.5h. 题目链接 (洛谷) https://www.luogu.org/problemnew/show/SP1812 题目大意 给\(n