GSLB 全局负载均衡
GSLB:Global Server Load Balance全局负载均衡
GSLB是对服务器和链路进行综合判断来决定由哪个地点的服务器来提供服务,实现异地服务器群服务 质量的保证
GSLB主要的目的是在整个网络范围内将用户的请求定向到最近的节点(或者区域)
GSLB分为基于DNS实现、基于重定向实现、基于路由协议实现,其中最通用的是基于DNS解析方式
范例:查询 VIP 使用网宿的CDN服务
CDN 内容分发网络
- 用户向浏览器输入www.a.com这个域名,浏览器第一次发现本地没有dns缓存,则向网站的DNS 服务器请求
- 网站的DNS域名解析器设置了CNAME,指向了www.a.tbcdn.com,请求指向了CDN网络中的智能 DNS负载均衡系统
- 智能DNS负载均衡系统解析域名,把对用户响应速度最快的IP节点返回给用户;
- 用户向该IP节点(CDN服务器)发出请求
- 由于是第一次访问,CDN服务器会通过Cache内部专用DNS解析得到此域名的原web站点IP,向原 站点服务器发起请求,并在CDN服务器上缓存内容
- 请求结果发给用户
范例:CDN 原理就是利用公司资源使用分布式的思想对 DNS 临近的 DNS 请求进行解析并缓存到本地
CDN 服务商
- 阿里,腾讯,蓝汛,网宿,帝联等
- 智能 DNS:dnspod dns.la
智能 DNS 相关技术
bind 中的 ACL
将多个 IP 绑定到一个 ACL 列表中,如果将 ACL 应用在 DNS 那么定义的将会是一个区域。可以将这个通过 IP 网段划分的区域定义一个统一的名称调用
注意:只能先定义后使用;因此一般定义在配置文件中,处于 options 的前面
格式:
bash
acl acl_name {
ip;
net/perlen;
};
范例:
bash
acl beijing {
172.16.1,0/24;
10.0.0.10;
};
bind 中有四个内置的 acl
- none 没有一个主机
- any 任意主机
- localhost 本机
- localnet 本机的 IP 同掩码运算后得到的网络地址(网段)
访问控制的指令
- allow-query {}; 允许查询的主机;白名单
- allow-transfer {}; 允许区域传送的主机;白名单
- allow-recursion {}; 允许递归的主机,建议全局使用
- allow-update {}; 允许更新区域数据库中的内容
view 视图
view 视图,将 ACL 与区域数据库实现对应关系,实现智能 DNS 解析
- 一个 bind 服务器可定义多个view,每个view中可定义一个或多个 zone
- 每个 view 用来匹配一组客户端
- 多个 view 内可能需要对同一个区域进行解析,但使用不同的区域解析文件
注意:
- 一旦启用了view,所有的zone都只能定义在view中
- 仅在允许递归请求的客户端所在view中定义根区域
- 客户端请求到达时,是自上而下检查每个view所服务的客户端列表
view 格式
Code
view VIEW_NAME {
match-clients { beijingnet; };
zone "dingchen.local" {
type master;
file "dingchen.local.zone.bj";
};
include "/etc/named.rfc1912.zones";
};
view VIEW_NAME {
match-clients { shanghainet; };
zone "dingchen.local" {
type master;
file "dingchen.local.zone.sh"
};
include "/etc/named.rfc1912.zones";
};
实战案例:利用 view 实现智能 DNS
实验目的
bash
搭建 DNS 主从服务器架构,实现 DNS 服务冗余
环境要求
bash
需要六台主机
web服务器1:100.0.0.123/8
web服务器2:100.0.0.105/8
web服务器3:100.0.0.106/8
DNS主服务器:100.0.0.104/8
DNS客户端1:100.0.0.6/8
DNS客户端2:100.0.0.10/8
实验步骤
1. 主 DNS 服务端配置文件实现 view
创建 ACL
bash
[root@centos7 ~]# yum install bind bind-utils -y
[root@centos7 ~]# vim /etc/named.conf
acl beijing {
100.0.0.9;
10.0.0.0/8;
};
acl shanghai {
100.0.0.10;
11.0.0.0/8;
};
acl other {
any;
};
# 修改下面两行
listen-on port 53 { localhost; };
allow-query { any; };
创建 view
bash
view beijingview {
match-clients { beijing; };
include "/etc/named.rfc1912.zones.bj";
};
view shanghaiview {
match-clients { shanghai; };
include "/etc/named.rfc1912.zones.sh";
};
view otherview {
match-clients { other; }; include "/etc/named.rfc1912.zones.other";
};
实现区域配置文件
bash
[root@centos7 ~]# cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bj
zone "." IN {
type hint;
file "named.ca";
};
zone "dingchen.local" {
type master;
file "dingchen.local.zone.bj";
};
[root@centos7 ~]# cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.sh
zone "." IN {
type hint;
file "named.ca";
};
zone "dingchen.local" {
type master;
file "dingchen.local.zone.sh";
};
[root@centos7 ~]# cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.other
zone "." IN {
type hint;
file "named.ca";
};
zone "dingchen.local" {
type master;
file "dingchen.local.zone.other";
};
实现解析库
bash
[root@centos7 named]# ll dingchen.local.zone.*
-rw-r--r--. 1 root named 134 Sep 12 15:50 dingchen.local.zone.bj
-rw-r--r--. 1 root named 134 Sep 12 15:51 dingchen.local.zone.other
-rw-r--r--. 1 root named 134 Sep 12 15:53 dingchen.local.zone.sh
[root@centos7 named]# cat dingchen.local.zone.*
$TTL 1D
@ IN SOA n1 admin.dingchen.local. ( 1 1D 2H 1D 1D )
IN NS n1
n1 IN A 100.0.0.104
websrc IN A 100.0.0.123
www IN CNAME websrc
$TTL 1D
@ IN SOA n1 admin.dingchen.local. ( 1 1D 2H 1D 1D )
IN NS n1
n1 IN A 100.0.0.104
websrc IN A 100.0.0.106
www IN CNAME websrc
$TTL 1D
@ IN SOA n1 admin.dingchen.local. ( 1 1D 2H 1D 1D )
IN NS n1
n1 IN A 100.0.0.104
websrc IN A 100.0.0.105
www IN CNAME websrc
创建 http 的站点目录
bash
[root@pool-100-0-0-123 ~]# echo 100.0.0.123 > /var/www/html/index.html
[root@pool-100-0-0-123 ~]# systemctl restart httpd
[root@centos7 ~]# echo 100.0.0.105 > /var/www/html/index.html
[root@centos7 ~]# systemctl restart httpd
[root@centos7 ~]# echo 100.0.0.106 > /var/www/html/index.html
[root@centos7 ~]# systemctl restart httpd
客户端访问测试
bash
root@client:~# curl www.dingchen.local
100.0.0.123:bj
[root@pool-100-0-0-6 ~]# curl www.dingchen.local
100.0.0.106:other
[root@centos7 ~]# curl www.dingchen.local
100.0.0.105:sh