RHCE综合实验
任务需求:客户端通过访问 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 |
1.环境准备
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
2.时间同步
安装chrony
dnf install chrony -y
启动并设置开机自启动
systemctl start chronyd
systemctl enable chronyd
3.NFS服务器配置
3.1安装NFS服务(192.168.121.9,主机名:nfs)
[root@nfs ~]# dnf install nfs-utils -y
3.2创建共享文件夹并设置权限
[root@nfs ~]# mkdir /nfs/data -p
[root@nfs ~]# cat > /etc/exports <<EOF
> /nfs/data 192.168.121.0/24(rw,sync)
> EOF
3.3创建首页文件
[root@nfs ~]# echo Very good, you have successfully set up the system. > /nfs/data/index.html
3.4启动NFS服务并放开防火墙端口
[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
4.Web服务器配置 (192.168.121.8,主机名:web)
4.1安装nginx和NFS客户端
[root@web ~]# dnf install nginx -y
[root@web ~]# dnf install nfs-utils -y
4.2挂载NFS共享
[root@web ~]# mkdir -p /usr/share/nginx/html
[root@web ~]# mount 192.168.121.9:/nfs/data /usr/share/nginx/html
4.3配置nginx
[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 {
}
4.4启动nginx并开放防火墙端口
[root@web ~]# systemctl start nginx
[root@web ~]# systemctl enable nginx
[root@web ~]# firewall-cmd --permanent --add-serverice=http
[root@web ~]# firewall-cmd --reload
5.DNS主服务器配置(192.168.121.18,主机名:dns1)
5.1安装bind
[root@dns1 ~]# dnf install bind -y
5.2配置主配置文件
[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";
}
5.3创建区域文件
[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
5.4启动bind并放通防火墙端口
[root@dns1 ~]# systemctl start named
[root@dns1 ~]# systemctl enable named
[root@dns1 ~]# firewall-cmd --permanent --add-service=dns
[root@dns1 ~]# firewall-cmd --reload
6 DNS从服务器配置(192.168.121.28,主机名:dns2)
6.1安装Bind
[root@dns2~]# dnf install bind -y
6.2配置主配置文件
[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; };
}
6.3启动Bind并开放防火墙端口
[root@dns2 ~]# systemctl start named
[root@dns2 ~]# systemctl enable named
[root@dns2 ~]# firewall-cmd --permanent --add-service=dns
[root@dns2 ~]# firewall-cmd --reload
7.客户端配置(192.168.121.7,主机名:client)
7.1安装bind工具
[root@client~]# dnf install bind -y
7.2查看DNS
[root@client ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.121.18
nameserver 192.168.121.28
7.3测试访问
[root@client ~]# curl http://www.nihao.com
Very good, you have successfully set up the system.
配置完成