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. Practice2 结对子之“小学四则运算”

    开发环境:Eclipse,js,css,html 程序完成的方向: 1.可以出表达式里含有负整数(负整数最小不小于-100)的题目,且负数需要带括号,用户输入的结果不用带括号.如: 2*(-4) = ...

  2. PAT L2-027 名人堂与代金券

    https://pintia.cn/problem-sets/994805046380707840/problems/994805055176163328 对于在中国大学MOOC(http://www ...

  3. JHipster - Generate your Spring Boot + Angular/React applications!

    JHipster - Generate your Spring Boot + Angular/React applications!https://www.jhipster.tech/

  4. activiti-ldap-integration

    https://stackoverflow.com/questions/19488764/activiti-ldap-integration https://community.alfresco.co ...

  5. js排序方法

    function swap(ary, x, y) { if (x === y) return let temp = ary[x] ary[x] = ary[y] ary[y] = temp } //生 ...

  6. Cmder 常用配置

    windows 系统的 cmd 命令窗口不是很好用,可以试试 Cmder 工具包. 1.在运行框中快速启动 Cmder 将 cmder.exe 文件所在目录加载环境变量 PATH 中. 2.把 cms ...

  7. Angular 序列化和反序列化和遍历

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...

  8. OneZero第七周第一次站立会议(2016.5.9)

    1. 时间: 12:15--12:25  共计10分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  9. apache2.4.29安装脚本

    #!/bin/bash . /etc/init.d/functions yum install -y expat-devel gcc gcc-c++ zlib-devel openssl-devel ...

  10. Python中print/format字符串格式化实例

    Python 字符串格式化使用 "字符 %格式1 %格式2 字符"%(变量1,变量2),%格式表示接受变量的类型.简单的使用例子如下 # 例:字符串格式化Name = '17jo' ...