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. 我的github地址

    链接:https://github.com/long0123/test.git   推送项目的github的大致步骤如下: 1.在本地创建一个项目仓库,可以放些基本的项目文件 2.cd至该目录下 3. ...

  2. PowerShell一例

    (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey

  3. CentOS Mininal 安装VMtools的方法

    1. 下载安装CentOS75 的mininal版本 2. 安装完成之后挂在vmtools. 虚拟机管理,安装vmtools即可 3. ssh登录虚拟机. cd /dev 进入到设备系统 mount ...

  4. shell获取帮助

    一.內建命令与外部命令 1.內建命令 内建命令是 shell 程序的一部分,是一些比较简单的 Linux 系统命令,这些命令是写在bash源码的builtins里面的,由 shell 程序识别并在 s ...

  5. IDEA 操作及快捷键总结

    一.设置IDEA使用Eclipse快捷键 File->Settings->Keymap->选择Eclipse,就可以使用Eclipse的快捷键了,但是不能修改.如果想要修改,需要点击 ...

  6. html5應用緩存

    HTML5使用了應用緩存,就是web應用緩存,使得在離線狀態下可以訪問web'應用. 應用緩存的優點: 離線訪問-可以在無網的狀態下訪問應用 速度-有緩存的應用加載更快 瀏覽器負載-瀏覽器只從服務器加 ...

  7. js語句

    js語句就是告訴瀏覽器要做什麼: js代碼就是js語句序列: js代碼塊就是{}包括的,函數就是一個代碼塊的典型例子: js注釋:單行注釋://,多行注釋:/**/ js對大小寫敏感: js語句可以不 ...

  8. Nginx ACCESS阶段 统一的用户权限验证系统

    L59 需要编译到Nginx --with-http_auth_request_module 功能介绍: 主要当收到用户请求的时候 通过反向代理方式生成子请求至上游服务器,如果上游服务器返回2xx 则 ...

  9. VMware配置Linux虚拟机访问外网

    [虚拟机版本] 系统版本 : Centos 6.8 [连接方法] 网络模式:桥接模式 ps:本人比较喜欢用桥接,直接NAT也是可以的 [配置步骤] 1.配置网卡 #配置命令 vi /etc/sysco ...

  10. css修改input表单默认样式重置与自定义大全

    链接地址: 伪元素表单控件默认样式重置与自定义大全 http://www.zhangxinxu.com/wordpress/?p=3381 Chrome 现在不支持通过伪元素修改 meter 元素样式 ...