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 {
wan@os.cn
! add a few more email addresses here if you would like
}
notification_email_from wan@os.cn ! 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上的这配置

[root@local 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 {
wan@os.cn
! add a few more email addresses here if you would like
}
notification_email_from wan@os.cn ! 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上的这配置

[root@local shell]# iptables -t nat -A PREROUTING -p tcp -d 192.168.13.100 --dport 80 -j REDIRECT
[root@local shell]# iptables -t nat -A OUTPUT -p tcp -d 192.168.13.100 --dport 80 -j REDIRECT

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

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

  1. 借助LVS+Keepalived通过DR模式实现负载均衡

    1.测试环境4台server,全部初始化一下,该关的关了 # vim /etc/hosts 192.168.1.101 lvs-master DIP 192.168.1.102 lvs-slave D ...

  2. lvs负载均衡(DR模式)

    lvs负载均衡(DR模式) 系统环境:lvs+keepalivedcentos7.5 ip:192.168.1.157 vip:192.168.1.150(主)centos7.5 ip:192.168 ...

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

    LVS + Keepalived之三大模式 ============================================================================== ...

  4. LVS负载均衡DR模式

    什么是集群? 一组相互独立的计算机,利用高速通信网络组成的一个计算机系统,对于客户机来说像是一个单一服务器,实际上是一组服务器.简而言之,一堆机器协同工作就是集群.集群的基本特点:高性能.高并发.高吞 ...

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

    现如今DDD越来越流行,园子里漫天都是介绍关于它的文章.说到DDD就不能不提Repository模式了,有的地方也叫它仓储模式. 很多时候我们对Repository都还停留在Copy然后使用的阶段, ...

  6. LVS集群DR模式实例(4)

    LVS集群DR模式实例 1. 实验拓扑图 2. 实验环境 3台CentOS6.4 64bit的服务器. 类型 IP DR eth0:10.20.73.20  VIP eth0:0 10.20.73.3 ...

  7. 内核知识第12讲,SSDT表.以用户模式到系统模式的两种方式.

    内核知识第12讲,SSDT表.以用户模式到系统模式的两种方式. 一丶IDT解析. 我们知道.IDT表中存放着各种中断信息.比如当我们调用int 3的时候,则会调用IDT表中的第三项来进行调用. 而函数 ...

  8. 单例Singleton模式的两种实现方法

    在设计模式中,有一种叫Singleton模式的,用它可以实现一次只运行一个实例.就是说在程序运行期间,某个类只能有一个实例在运行.这种模式用途比较广泛,会经常用到,下面是Singleton模式的两种实 ...

  9. jqGrid中实现radiobutton的两种做法

    http://blog.sina.com.cn/s/blog_4f925fc30102e27j.html   jqGrid中实现radiobutton的两种做法 ------------------- ...

随机推荐

  1. 团队项目第二周spec设计

    本系统针对局域网进行联机聊天.聊天室分为服务器端和和客户端俩部分,服务器端程序主要 负责侦听客户端发来的信息,客户端需要登录到服务器端才可以实现正常的聊天功能. 1.本软件是一款局域网聊天软件,不能进 ...

  2. 接口(interface)与多态

    1. 接口(interface)是抽象方法与常量值的集合: 2. 从本质上来讲,接口是一种特殊的抽象类,这种抽象类中只包含常量与方法的定义,而没有变量和方法的实现: 3. 接口中声明的属性默认为:pu ...

  3. Fastdfs文件服务器搭建

    安装FastDFS之前,先安装libevent工具包.然后要安装libfastcommon和FastDFS,还要依赖nginx来显示图片. 1安装libevent yum -y install lib ...

  4. 第五届蓝桥杯C++B组 地宫取宝

    代码: #include <bits/stdc++.h> using namespace std; #define ll long long const ll mod = 1e9 + 7; ...

  5. PAT 甲级 1044 Shopping in Mars

    https://pintia.cn/problem-sets/994805342720868352/problems/994805439202443264 Shopping in Mars is qu ...

  6. 转帖--计算机网络基础知识大总汇 https://www.jianshu.com/p/674fb7ec1e2c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

    计算机网络基础知识大总汇 龙猫小爷 关注 2016.09.14 23:01* 字数 12761 阅读 30639评论 35喜欢 720 一.什么是TCP/IP 网络和协议 1.     TCP/IP是 ...

  7. Personal Software Process (PSP)

    日期 分类 开始时间 结束时间 中断时间 净时间 活动 备注 C U 2016/03/15 随笔 9:30 10:40 0 70 博客更新 更新<软件项目管理(1)> Y Minute 随 ...

  8. Nginx REWRITE阶段

    rewrite_log on ;#每次rewrite都会记录一条记录在errorlog里 error_log logs/xxx.log notice; location /first { rewrit ...

  9. P3760 [TJOI2017]异或和

    题目描述 在加里敦中学的小明最近爱上了数学竞赛,很多数学竞赛的题都是与序列的连续和相关的.所以对于一个序列,求出它们所有的连续和来说,小明觉得十分的简单.但今天小明遇到了一个序列和的难题,这个题目不仅 ...

  10. java构造函数总结

    构造函数总结 概念:    创建对象时由JVM自动调用的函数 作用:    在创建对象的时候给对象的成员变量赋值: 写法: 修饰符:可以用访问权限修饰符(public.private等)修饰:不能用s ...