DNS部署(四)之lvs+keepalived+bind架构高可用负载均衡DNS系统

1、网络拓扑

2、环境描述

系统描述 IP地址 作用
LB-master 192.168.1.105 主备负载均衡器(同时做web和DNS调度)
LB-backup 192.168.1.106
DNS-master 192.168.1.107 VIP:192.168.1.30(LVS DNS节点互为主辅同步)
DNS-backup 192.168.1.108
Web节点组 192.168.1.201-203 VIP:192.168.1.40(LVS web节点)

3、配置LVS调度器keepalived的配置文件

keepalived配置双vrrp instance,分别为:WEB实例和DNS实例。

3.1 主LVS上keepalived的配置文件内容:


[[email protected] ~]#cat /etc/keepalived/keepalived.conf

! ConfigurationFile for keepalived

global_defs {

notification_email {

[email protected]

[email protected]

[email protected]

}

[email protected]

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id lvs_105

}

vrrp_instance VI_WEB {

state MASTER

interface eth0

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.40/24

}

}

#############LVSWEB################

virtual_server 192.168.1.40 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

#  persistence_timeout 50

protocol TCP

real_server 192.168.1.201 80 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 80

}

}

real_server 192.168.1.202 80 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 80

}

}

real_server 192.168.1.203 80 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 80

}

}

}

#############DNSInstance start###############

vrrp_instance VI_DNS {

state BACKUP

interface eth0

virtual_router_id 52

priority 90

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.30/24

}

}

###########LVSDNS#######################

virtual_server 192.168.1.30 53 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

# persistence_timeout 50

protocol UDP

real_server 192.168.1.107 53 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 53

}

}

real_server 192.168.1.108 53 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 53

}

}

}

3.2 备LVS上keepalived的配置文件内容:

[[email protected] ~]#cat /etc/keepalived/keepalived.conf

! ConfigurationFile for keepalived

global_defs {

notification_email {

[email protected]

[email protected]

[email protected]

}

[email protected]

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id lvs_106

}

vrrp_instance VI_WEB {

state BACKUP

interface eth0

virtual_router_id 51

priority 90

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.40/24

}

}

#############LVSWEB################

virtual_server 192.168.1.40 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

#  persistence_timeout 50

protocol TCP

real_server 192.168.1.201 80 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 80

}

}

real_server 192.168.1.202 80 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 80

}

}

real_server 192.168.1.203 80 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 80

}

}

}

#############DNS Instancestart###############

vrrp_instance VI_DNS {

state MASTER

interface eth0

virtual_router_id 52

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.30/24

}

}

###########LVSDNS#######################

virtual_server 192.168.1.30 53 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

# persistence_timeout 50

protocol UDP

real_server 192.168.1.107 53 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 53

}

}

real_server 192.168.1.108 53 {

weight 100

TCP_CHECK {

connect_timeout 8

nb_get_retry 3

delay_before_retry 3

connect_port 53

}

}

}

4、配置LVS节点服务器脚本(WEB节点与DNS节点都要配置)

4.1 DNS节点的配置内容(主备DNS都有配置):

[[email protected] ~]# cat /etc/init.d/dns_rs.ctl

#!/bin/bash

. /etc/init.d/functions

VIP=192.168.1.30

case "$1" in

start)

echo "start LVS of Realserver DR mode"

/sbin/ifconfig lo:0 ${VIP} netmask 255.255.255.255 up

route add -host ${VIP} dev lo

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)

/sbin/ifconfig lo:0 ${VIP} netmask 255.255.255.255 down

route del -host ${VIP} dev lo

echo "stop LVS of Realserver DR mode"

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

4.1.1 对上面的脚本赋予权限

[[email protected] init.d]# chmod +x dns_rs.ctl

4.2 WEB节点的配置内容(web的所有节点都有配置)

[[email protected] ~]# cat /etc/init.d/web_rs.ctl

#!/bin/bash

. /etc/init.d/functions

VIP=192.168.1.40

case "$1" in

start)

echo "start LVS of Realserver DR mode"

/sbin/ifconfig lo:0 ${VIP} netmask 255.255.255.255 up

route add -host ${VIP} dev lo

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)

/sbin/ifconfig lo:0 ${VIP} netmask 255.255.255.255 down

route del -host ${VIP} dev lo

echo "stop LVS of Realserver DR mode"

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

4.2.1 对上面的脚本赋予权限

[[email protected] init.d]# chmod +x web_rs.ctl

5、主DNS服务器的区域配置文件修改如下:

[[email protected] ~]# cat /var/named/chroot/var/named/pp.org.zone

$TTL   86400

@               IN SOA  dns.pp.org.       root.pp.org. (

203             ; serial (d. adams)

3H              ; refresh

15M             ; retry

1W              ; expiry

1D)            ; minimum

IN NS           dns.pp.org.

IN MX  10       mail.pp.org.

dns.pp.org.     IN A            192.168.1.107

www             IN  A           192.168.1.40

5.1 修改之后重启DNS服务

[[email protected] ~]# rndc reload

server reload successful

6、综合测试

测试之前要启动相关服务(keepalived、lvs节点脚本、节点Apache、节点DNS服务器等)

A:首先启动一台负载均衡调度器的keepalived服务

[[email protected] ~]# /etc/init.d/keepalived start

Starting keepalived:                                       [  OK  ]

[[email protected] ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:0c:29:81:a8:b3 brd ff:ff:ff:ff:ff:ff

inet 192.168.1.105/24 brd 192.168.1.255 scope global eth0

inet 192.168.1.40/24 scopeglobal secondary eth0

inet 192.168.1.30/24 scopeglobal secondary eth0

inet6 fe80::20c:29ff:fe81:a8b3/64 scope link

valid_lft forever preferred_lft forever

3: sit0: <NOARP> mtu 1480 qdisc noop

link/sit 0.0.0.0 brd 0.0.0.0

查看调度规则:

[[email protected] ~]# ipvsadm -L -n

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port          Forward Weight ActiveConn InActConn

UDP 192.168.1.30:53 rr

-> 192.168.1.108:53            Route   100    0         0

-> 192.168.1.107:53            Route   100    0         0

TCP 192.168.1.40:80 rr

-> 192.168.1.203:80            Route   100    0         0

-> 192.168.1.202:80            Route   100    0         0

-> 192.168.1.201:80            Route   100    0         0

B.停掉和启用一台DNS服务,观察调度器

[[email protected] slaves]# /etc/init.d/named stop

Stoppingnamed:                                           [  OK  ]

查看的日志内容:

Oct 26 23:38:10 localhostKeepalived_healthcheckers: TCP connection to [192.168.1.108:53] failed !!!

Oct 26 23:38:10 localhost Keepalived_healthcheckers:Removing service [192.168.1.108:53] from VS [192.168.1.30:53]

观察lvs调度规则中少了192.168.1.108机器

[[email protected] ~]# ipvsadm -L -n

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port          Forward Weight ActiveConn InActConn

UDP 192.168.1.30:53 rr

-> 192.168.1.107:53            Route   100    0         0

TCP 192.168.1.40:80 rr

-> 192.168.1.203:80            Route   100    0         0

-> 192.168.1.202:80            Route   100    0         0

-> 192.168.1.201:80            Route   100    0         0

再次启动回来,查看日志会发现又把对应的IP地址加入了进来!

C.启动第二台负载均衡调度器的keepalived服务

[[email protected] ~]# /etc/init.d/keepalived start

Starting keepalived:                                       [  OK  ]


   此时DNS的VIP会分配到第二台负载均衡调度器上

[[email protected] ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:0c:29:b5:be:19 brd ff:ff:ff:ff:ff:ff

inet 192.168.1.106/24 brd 192.168.1.255 scope global eth0

inet 192.168.1.30/24 scope global secondary eth0

inet6 fe80::20c:29ff:feb5:be19/64 scope link

valid_lft forever preferred_lft forever

3: sit0: <NOARP> mtu 1480 qdisc noop

link/sit 0.0.0.0brd 0.0.0.0

WEB的VIP仍然在第一台负载均衡调度器上!!

[[email protected] ~]#ip addr

1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:0c:29:81:a8:b3 brdff:ff:ff:ff:ff:ff

inet 192.168.1.105/24 brd 192.168.1.255scope global eth0

inet 192.168.1.40/24 scope global secondaryeth0

inet6 fe80::20c:29ff:fe81:a8b3/64 scopelink

valid_lft forever preferred_lft forever

3: sit0:<NOARP> mtu 1480 qdisc noop

link/sit 0.0.0.0 brd 0.0.0.0

观察调度规则:


[[email protected] ~]#ipvsadm -L -n

IP VirtualServer version 1.2.1 (size=4096)

ProtLocalAddress:Port Scheduler Flags

-> RemoteAddress:Port           Forward Weight ActiveConn InActConn

UDP  192.168.1.30:53 rr

-> 192.168.1.108:53             Route  100    0         35

-> 192.168.1.107:53             Route   100   0         36

TCP  192.168.1.40:80 rr

-> 192.168.1.203:80             Route   100   0          0

-> 192.168.1.202:80             Route   100   0          0

-> 192.168.1.201:80             Route   100   0          0

[[email protected] ~]#ipvsadm -L -n

IP VirtualServer version 1.2.1 (size=4096)

ProtLocalAddress:Port Scheduler Flags

-> RemoteAddress:Port           Forward Weight ActiveConn InActConn

UDP  192.168.1.30:53 rr

-> 192.168.1.108:53             Route   100   0          0

-> 192.168.1.107:53             Route   100   0          0

TCP  192.168.1.40:80 rr

-> 192.168.1.203:80             Route   100   0          35

-> 192.168.1.202:80             Route   100   0          36

-> 192.168.1.201:80             Route   100   0          35

综上:主备调度器的keepalived服务都在工作!

注:bind9功能强大,这里只是讨论了最简单的配置!

时间: 2024-10-12 08:37:29

DNS部署(四)之lvs+keepalived+bind架构高可用负载均衡DNS系统的相关文章

LVS+Keepalived搭建MyCAT高可用负载均衡集群

LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一.目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR),十种调度算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq). Keepalvied Keepalived在这里主要用作RealServer的健康状态检查以及Mast

LVS+KeepAlived,RabbitMQ高可用负载均衡

最近团队准备对项目进行重构,其中用到了RabbitMQ,也考虑了几个方案,下边着重介绍在项目中即将采用的方案.关于RabbitMQ就不在这里详细说明,具体查看 RabbitMQ中文手册.直接看架构图: 如图所示: 前端采用keepalived+lvs实现高可用负载均衡, RabbitMQ HA 队列(镜像队列)进行消息队列结构复制.本方案中搭建两个节点,并且都是磁盘节点(所有节点状态保持一致,节点完全对等),只要有任何一个节点能够工作,RabbitMQ 集群对外就能提供服务.任务处理进程同时监控

LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)

一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Redhat提供的工具piranha来配置LVS 软件下载: ipvsadm下载地址: http://www.linuxvirtualserver.org/software/kernel-2.6/ Keepalived下载地址: http://www.keepalived.org/software/ 安装

LVS+keepalived 实现web高可用负载均衡集群

1.实验环境 4台CentOS-7.5虚拟机web-1:192.168.18.103web-2:192.168.18.104keepalived-1(LVS-DR模式):192.168.18.107 keepalived-2(LVS-DR模式):192.168.18.108 vip:192.168.18.110其中keepalived和lvs安装在同一台机器,web单独一台安装客户端为:个人win10笔记本(192.168.18.102)4台虚机防火墙和selinux均已关闭 2.安装keepa

CentOS7下LVS+Keepalived实现高性能高可用负载均衡

一.规划  对外VIP:10.10.10.10    对内VIP:192.168.10.10 LVS_MASTER:10.10.10.28(eth0)            192.168.10.128(eth1) LVS_BACKUP:10.10.10.29(eth0)            192.168.10.129(eth1)       WEB1:192.168.10.130       WEB2:192.168.10.131 二.释义 LVS是Linux Virtual Server

CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡

一.系统环境 实验拓扑: 实验环境: Vmware 9.01 + Windows 8 x64 企业版+8G内存 虚拟机步骤: 1.安装一台CentOS 6.3 x64主机,内存为1GB,网络为NAT模式,注意检查Vmware中EDIT菜单下Virtual Network Editor中VMnet8 2. 加电,安装系统.基础知识了,不再多说,注意:选择英文而不要选择中文,选择是Basic Server模式,系统名称:LVS-MASTER 3.安装系统后,用root用户登录进去,执行 ifconf

RHEL 5.4下部署LVS(DR)+keepalived实现高性能高可用负载均衡

原文地址:http://www.cnblogs.com/mchina/archive/2012/05/23/2514728.html 一.简介 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. 目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR):十种调度算法(rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq). K

CentOS 6.3下部署LVS(NAT模式)+keepalived实现高性能高可用负载均衡

一.简介 VS/NAT原理图: 二.系统环境 实验拓扑: 系统平台:CentOS 6.3 Kernel:2.6.32-279.el6.i686 LVS版本:ipvsadm-1.26 keepalived版本:keepalived-1.2.4 三.安装 0.安装LVS前系统需要安装popt-static,kernel-devel,make,gcc,openssl-devel,lftp,libnl*,popt* 1.在两台Director Server上分别配置LVS+Keepalived LVS

CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡【转】

CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡 一.简介 VS/NAT原理图: 二.系统环境 实验拓扑: 系统平台:CentOS 6.3 Kernel:2.6.32-279.el6.i686 LVS版本:ipvsadm-1.26 keepalived版本:keepalived-1.2.4 三.安装 0.安装LVS前系统需要安装popt-static,kernel-devel,make,gcc,openssl-devel,lftp,libnl*,popt*