1. 编辑zone文件
[root@master ~]# vim /var/named/chroot/etc/example.com.zone $ORIGIN . $TTL 3600 ; 1 hour example.com IN SOA op.example.com. dns.example.com. ( 2004 ; serial #自增+1,生产中可通过加时间戳来设定 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.example.com. $ORIGIN example.com. chegva A 1.2.3.4 op A 1.2.3.4 a A 1.2.3.4 a A 192.168.122.100 a A 192.168.122.102 #增加一条A解析 cname CNAME a.example.com. mx MX 5 192.168.122.101 [root@master ~]# rndc reload WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf) server reload successful
2. 测试结果
[root@master ~]# nslookup a.example.com 127.0.0.1 Server: 127.0.0.1 Address: 127.0.0.1#53 Name: a.example.com Address: 192.168.122.102 #虽然3个IP都解析到了,但拿到第一个IP,实际上已经解析出结果 Name: a.example.com Address: 1.2.3.4 Name: a.example.com Address: 192.168.122.100 [root@master ~]# nslookup a.example.com 127.0.0.1 Server: 127.0.0.1 Address: 127.0.0.1#53 Name: a.example.com Address: 1.2.3.4 #再执行一次,轮询到1.2.3.4这个IP Name: a.example.com Address: 192.168.122.100 Name: a.example.com Address: 192.168.122.102 [root@master ~]# nslookup a.example.com 127.0.0.1 Server: 127.0.0.1 Address: 127.0.0.1#53 Name: a.example.com Address: 192.168.122.100 #依次轮询,DNS只有轮询的算法 Name: a.example.com Address: 192.168.122.102 Name: a.example.com Address: 1.2.3.4
注意: DNS可以作负载均衡,但主要有两点不足
只有轮询算法
DNS解析只是一个记录类型,不会去探测后边的服务是死是活。因此,DNS负载均衡功能要慎用!