资源列表
操作系统 | IP | 主机名 |
Centos7 | 192.168.10.51 | nginx |
Centos7 | 192.168.10.52 | DNS1 |
Centos7 | 192.168.10.53 | DNS2 |
基础环境
- 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
- 关闭内核安全机制
setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
- 修改主机名
hostnamectl set-hostname nginx
hostnamectl set-hostname DNS1
hostnamectl set-hostname DNS2
搭建网站服务器(在nginx节点操作)
#yum下载nginx
yum -y install epel-release && yum -y install nginx
vim /etc/nginx/nginx.conf
#将域名设置为www.lll.com
server {
listen 80;
listen [::]:80;
server_name www.lll.com;
root /usr/share/nginx/html;
#配置网页文件
echo 'nginx!!!' > /usr/share/nginx/html/index.html
systemctl restart nginx
systemctl enable nginx
构建主DNS服务器(在DNS1节点操作)
使用yum安装bind以及相关依赖包
yum -y install bind bind-utils bind-libs bind-chroot
修改配置文件
# 备份配置文件
cp /etc/named.conf{,bak}
# 将配置文件修改为以下内容,涉及到IP的要按自己环境修改
cat /etc/named.conf
options {
listen-on port 53 { 192.168.10.52; };
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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { 192.168.10.0/24; };
};
zone "lll.com" IN {
type master;
file "lll.com.zone";
allow-transfer {192.168.10.53;};
};
zone "10.168.192.in-addr.arpa" IN {
type master;
file "192.168.10.arpa";
allow-transfer {192.168.10.53;};
};
######################################################################################
# 建立正向区域数据文件
## 复制模板配置文件再修改
cp -p /var/named/named.localhost /var/named/lll.com.zone
cat /var/named/lll.com.zone
$TTL 1D
@ SOA lll.com. admin.lll.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ NS nginx.lll.com.
nginx A 192.168.10.51
www A 192.168.10.51
* A 192.168.10.51
###############################################################################
# 建立反向区域数据文件
## 复制模板配置文件再修改
cp -p /var/named/named.loopback /var/named/192.168.10.arpa
cat /var/named/192.168.10.arpa
$TTL 1D
@ SOA lll.com. admin.lll.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS nginx.lll.com.
51 PTR www.lll.com.
51 PTR nginx.lll.com.
##################################################################################
# 重新设置权限
chown named:named /etc/named.conf
chown named:named /var/named/lll.com.zone
chown named:named /var/named/192.168.10.arpa
# 配置文件检查
named-checkconf -z /etc/named.conf
named-checkzone lll.com lll.com.zone
named-checkzone 10.168.192.in-addr.arpa 192.168.10.arpa
启动服务
systemctl start named
systemctl enable named
配置从域名服务器(在DNS2节点操作)
cat /etc/named.conf
zone "lll.com" IN {
type slave;
masters {192.168.10.52;};
file "slaves/lll.com.zone";
};
zone "10.168.192.in-add.arpa" IN {
type slave;
masters {192.168.10.52;};
file "slaves/192.168.10.arpa";
};
#启动DNS服务器
systemctl start named
[root@localhost named]# ls /var/named/slaves/
lll.com.zone
在客户机配置DNS
vi /etc/sysconfig/network-scripts/ifcfg-ens33
DNS1=192.168.10.52
DNS2=192.168.10.53
[root@localhost ~]# curl www.lll.com
nginx!!!!
[root@localhost ~]# nslookup www.lll.com
;; Got SERVFAIL reply from 8.8.8.8, trying next server
Server: 192.168.10.52
Address: 192.168.10.52#53
Name: www.lll.com
Address: 192.168.10.51
;; Got SERVFAIL reply from 8.8.8.8, trying next server