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. (转)SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM之间

    原因: 出现这种问题多半是因为你插入或者更新数据库时,datetime字段值为空默认插入0001年01月01日造成datetime类型溢出. 传给数据库表的时间类型值是null值.这里的null指的是 ...

  2. [转]Spring通过@Value注解注入属性的几种方式

    原文地址:https://blog.csdn.net/csujiangyu/article/details/50945486 ------------------------------------- ...

  3. Activiti 用户手册

    https://tkjohn.github.io/activiti-userguide/

  4. Docker Dockerfile指令

    Docker 可以通过 Dockerfile 的内容来自动构建镜像.Dockerfile 是一个包含创建镜像所有命令的文本文件,通过docker build命令可以根据 Dockerfile 的内容构 ...

  5. node的读写流

    let http = require('http'); http.createServer((req,res)=>{ res.end(); }).listen(,()=>{ console ...

  6. Xshell 使用数字小键盘进行vim 写入操作.

    Copy From http://blog.csdn.net/shenzhen206/article/details/51200869 感谢原作者 在putty或xshell上用vi/vim的时候,开 ...

  7. SAP字体调节大小

    登陆SAP 之后,菜单下面一行,最右边的那个彩色按钮(SAP GUI),点击“选项”-可视设计-字体设计-固定狂赌字体设计,点击:选择字体 即可.

  8. python slots

    正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: >>> class Studen ...

  9. notepad编写html

    notepad写代码的过程: 1.打开notepad,新建一个文档,然后保存,文件的后缀名为.html,代码保存前界面上文件名称为红色,保存后蓝色: 2.保存为html后,进行代码的输入,如果设置好自 ...

  10. 【转】SpringMVC,获取request的几种方法,及线程安全性

    作者丨编程迷思 https://www.cnblogs.com/kismetv/p/8757260.html 概述 在使用Spring MVC开发Web系统时,经常需要在处理请求时使用request对 ...