🌻 LVS + Keepalived+Bind搭建内网DNS集群
本次配置的所有服务器均为虚拟机,操作系统为Centos 7.6
所用到的工具:
系统镜像:下载地址
vmware:下载地址
| 服务器名称 | IP地址 |
|---|---|
| DNS-LVS主 | 192.168.40.1 |
| DNS-LVS备 | 192.168.40.2 |
| DNS-Bind-01 | 192.168.40.3 |
| DNS-Bind-02 | 192.168.40.4 |
| DNS-VIP | 192.168.40.5 |
DNS集群搭建
在每台服务器上安装ntpdate,确保时间同步;
yum -y install ntpdate
echo "" >> /var/spool/cron/root
crontab -l > crontabtmp && echo "0 * * * * ntpdate cn.ntp.org.cn" >> crontabtmp && crontab crontabtmp && rm -f crontabtmp
安装BIND软件
yum安装bind-chroot,顾名思义这个是可指定chroot的bind,比较安全
yum -y install bind-chroot bind-utils net-tools initscripts
systemctl enable named-chroot
bind-utils是bind软件提供的一组DNS工具包,里面有一些DNS相关的工具.主要有:dig,host,nslookup,nsupdate.使用这些工具可以进行域名解析和DNS调试工作.
编辑配置文件
这里开始DNS的配置,下面是配置named.conf,默认安装的路径为/etc/named.conf(主从DNS配置文件一样)
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
// listen-on port 53 { 127.0.0.1; };
// listen-on-v6 port 53 { ::1; };
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
// managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.ex.zones";
# Use with the following in named.conf, adjusting the allow list as needed:
key "rndc-key" {
algorithm hmac-md5;
secret "cKrXyRZKWD6rbhaZLcc8UA==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
# End of named.conf
LVS + keepalived
加载ip_vs内核模块
modprobe ip_vs
安装ntp,ipvsadm,编译环境等
yum -y install ntpdate ipvsadm wget gcc gcc-c++ make popt-devel kernel-devel openssl-devel libnl3-devel
安装keepalived
yum -y install epel-release
yum -y install keepalived
编辑配置文件/etc/keepalived/keepalived.conf(主)
! Configuration File for keepalived
global_defs {
# notification_email {
# 123@139.com
# }
# notification_email_from 123@139.com
# smtp_server 172.0.0.1
# smtp_connect_timeout 30
router_id LVS_1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.40.5/24
}
}
vrrp_instance LAN_GATEWAY {
state MASTER
interface ens33
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.40.5/24
}
}
virtual_server 192.168.40.5 53 {
delay_loop 1
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol UDP
real_server 192.168.40.3 53 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
connect_port 53
}
}
real_server 192.168.40.4 53 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
connect_port 53
}
}
}
virtual_server 192.168.40.5 53 {
delay_loop 1
lb_algo rr
lb_kind DR
persistence_timeout 20
protocol TCP
real_server 192.168.40.3 53 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 53
}
}
real_server 192.168.40.4 53 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 53
}
}
}
编辑配置文件/etc/keepalived/keepalived.conf(备)
! Configuration File for keepalived
global_defs {
# notification_email {
# 123@139.com
# }
# notification_email_from 123@139.com
# smtp_server 172.0.0.1
# smtp_connect_timeout 30
router_id LVS_1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 50
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.40.5/24
}
}
vrrp_instance LAN_GATEWAY {
state MASTER
interface ens33
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.40.5/24
}
}
virtual_server 192.168.40.5 53 {
delay_loop 1
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol UDP
real_server 192.168.40.3 53 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
connect_port 53
}
}
real_server 192.168.40.4 53 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
connect_port 53
}
}
}
virtual_server 192.168.40.5 53 {
delay_loop 1
lb_algo rr
lb_kind DR
persistence_timeout 20
protocol TCP
real_server 192.168.40.3 53 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 53
}
}
real_server 192.168.40.4 53 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 53
}
}
}