任务需求:客户端通过访问 www.nihao.com 后,能够通过 dns 域名解析,访问到 nginx 服务中由 nfs 共享的首页文件,内容为:Very good, you have successfully set up the system. 各个主机能够实现时间同步,并且都开启防火墙来保证服务安装。
作用 | 系统 | IP | 主机名 | 软件 |
---|---|---|---|---|
web 服务器 | redhat9.5 | 192.168.121.8 | web | nginx,nfs-utils |
nfs 服务器 | redhat9.5 | 192.168.121.9 | nfs | nfs-utils |
DNS 主服务器 | redhat9.5 | 192.168.121.18 | dns1 | bind |
DNS 从服务器 | redhat9.5 | 192.168.121.28 | dns2 | bind |
客户端 | redhat9.5 | 192.168.121.7 | client | bind-utils |
web
[root@localhost ~]# hostnamectl hostname web
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.121.8/24 ipv4.gateway 192.168.121.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
nfs
[root@localhost ~]# hostnamectl hostname nfs
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.121.9/24 ipv4.gateway 192.168.121.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
dns1
[root@localhost ~]# hostnamectl hostname dns1
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.121.18/24 ipv4.gateway 192.168.121.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
dns2
[root@localhost ~]# hostnamectl hostname dns2
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.121.28/24 ipv4.gateway 192.168.121.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
client
[root@localhost ~]# hostnamectl hostname client
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.121.7/24 ipv4.gateway 192.168.121.2 ipv4.dns "192.168.121.18 192.168.121.28" connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
关闭几台服务器的selinux:
sed -i 's/SELINUX=enforcing/SELINUX=Permissive/g' /etc/selinux/config
setenforce 0
安装chrony
dnf install chrony -y
启动并设置开机自启动
systemctl start chronyd
systemctl enable chronyd
[root@nfs ~]# dnf install nfs-utils -y
[root@nfs ~]# mkdir /nfs/data -p
[root@nfs ~]# cat > /etc/exports <
> EOF
[root@nfs ~]# echo Very good, you have successfully set up the system. > /nfs/data/index.html
[root@nfs ~]# systemctl start nfs-server
[root@nfs ~]# systemctl enabel nfs-server
[root@nfs ~]# firewall-cmd --permanent --add-service=nfs
[root@nfs ~]# firewall-cmd --reload
[root@web ~]# dnf install nginx -y
[root@web ~]# dnf install nfs-utils -y
[root@web ~]# mkdir -p /usr/share/nginx/html
[root@web ~]# mount 192.168.121.9:/nfs/data /usr/share/nginx/html
[root@web ~]# cat /etc/nginx/nginx.conf
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
[root@web ~]# systemctl start nginx
[root@web ~]# systemctl enable nginx
[root@web ~]# firewall-cmd --permanent --add-serverice=http
[root@web ~]# firewall-cmd --reload
[root@dns1 ~]# dnf install bind -y
[root@dns1 ~]# vi /etc/named.conf
options {
listen-on port 53 { 192.168.121.18; };
directory "/var/named";
};zone "nihao.com" IN{
type master;
file "nihao.com";
}
[root@dns1 ~]# vi /var/named/nihao.com
$TTL 1D
@ IN SOA @ admin.nihao.com.(
0
1D
2H
3W
2D
)
@ IN NS dns1.nihao.com.
@ IN NS dns2.nihao.com.
www IN A 192.168.121.8
[root@dns1 ~]# systemctl start named
[root@dns1 ~]# systemctl enable named
[root@dns1 ~]# firewall-cmd --permanent --add-service=dns
[root@dns1 ~]# firewall-cmd --reload
[root@dns2~]# dnf install bind -y
[root@dns2 ~]# vi /etc/named.conf
options {
listen-on port 53 { 192.168.121.28; };
directory "/var/named";
};zone "nihao.com" IN{
type slave;
file "slaves/nihao.com";master {192.168.121.28; };
}
[root@dns2 ~]# systemctl start named
[root@dns2 ~]# systemctl enable named
[root@dns2 ~]# firewall-cmd --permanent --add-service=dns
[root@dns2 ~]# firewall-cmd --reload
[root@client~]# dnf install bind -y
[root@client ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.121.18
nameserver 192.168.121.28
[root@client ~]# curl http://www.nihao.com
Very good, you have successfully set up the system.
配置完成