网站需求:
1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息,[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料,网站访问缴费网站(http://www.openlab.com/money网站访问缴费网站)。
3.要求 (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
架设一台NFS服务器,并按照以下要求配置
1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,
并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom可以完全访问该目录
一.访问openlab及其三个子网:
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# yum install -y httpd
OS 5.0 kB/s | 1.9 kB 00:00
everything 5.2 kB/s | 1.9 kB 00:00
EPOL 5.1 kB/s | 1.9 kB 00:00
debuginfo 6.1 kB/s | 2.2 kB 00:00
source 5.5 kB/s | 2.2 kB 00:00
update 5.2 kB/s | 1.9 kB 00:00
update-source 6.3 kB/s | 2.2 kB 00:00
Package httpd-2.4.55-3.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# vim /etc/nginx/conf.d/test_httpd.conf
server {
listen 192.168.168.131:80;
root /www/name/openlab;
server_name www.openlab.com;
location / {
index index.html;
}
}
server {
listen 192.168.168.131:80;
root /www/name/openlab/student;
server_name www.openlab.com/student;
location / {
index index.html;
}
}
server {
listen 192.168.168.131:80;
root /www/name/openlab/data;
server_name www.openlab.com/data;
location / {
index index.html;
}
}
server {
listen 192.168.168.131:80;
root /www/name/openlab/money;
server_name www.openlab.com/money;
location / {
index index.html;
}
}
[root@localhost ~]# mkdir -pv /www/name/openlab/{student,data,money}
mkdir: 已创建目录 '/www/name'
mkdir: 已创建目录 '/www/name/openlab'
mkdir: 已创建目录 '/www/name/openlab/student'
mkdir: 已创建目录 '/www/name/openlab/data'
mkdir: 已创建目录 '/www/name/openlab/money'
[root@localhost ~]# echo welcome to openlab > /www/name/openlab/index.html
[root@localhost ~]# echo 这是学生信息网 > /www/name/openlab/student/index.html
[root@localhost ~]# echo 这是教学资料网 > /www/name/openlab/data/index.html
[root@localhost ~]# echo 这是缴费网 > /www/name/openlab/money/index.html
[root@localhost ~]# systemctl restart nginx
可以使用另一台虚拟机来验证访问网站,所以必须在其/etc/hosts文件中添加网站对应IP地址
[root@localhost ~]# vim /etc/hosts
# Loopback entries; do not change.
# For historical reasons, localhost precedes localhost.localdomain:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# See hosts(5) for proper format and other examples:
# 192.168.1.10 foo.mydomain.org foo
# 192.168.1.13 bar.mydomain.org bar
192.168.168.131 www.openlab.com
192.168.168.131 www.openlab.com/student
192.168.168.131 www.openlab.com/data
192.168.168.131 www.openlab.com/money
[root@localhost ~]# curl http://www.openlab.com
welcome to openlab
[root@localhost ~]# curl http://www.openlab.com/student/
这是学生信息网
[root@localhost ~]# curl http://www.openlab.com/data/
这是教学资料网
[root@localhost ~]# curl http://www.openlab.com/money/
这是缴费网
二.学生只能通过song和tian访问
#增加用户:
[root@localhost ~]# htpasswd -c /etc/nginx/users song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd -c /etc/nginx/users tian
New password:
Re-type new password:
Adding password for user tian
#修改配置文件
[root@localhost ~]# vim /etc/nginx/conf.d/test_httpd.conf
server {
listen 192.168.168.131:80;
root /www/name/openlab/student;
server_name www.openlab.com/student;
location / {
index index.html;
auth_basic on;
auth_basic_user_file /etc/nginx/users;
}
}
访问缴费网时需要https
[root@localhost ~]# vim /etc/nginx/conf.d/test_https.conf
server {
listen 192.168.168.131:443 ssl;
root /www/name/openlab/money/;
ssl_certificate /etc/pki/tls/certs/openlab.crt;
ssl_certificate_key /etc/pki/tls/private/openlab.key;
location / {
index index.html;
}
}
[root@localhost ~]# openssl req -utf8 -new -key openlab.key -x509 -days 365 -out openlab.crt
Could not read private key from openlab.key
[root@localhost ~]# openssl genrsa -out /etc/pki/tls/private/openlab.key
[root@localhost ~]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:86
State or Province Name (full name) [Some-State]:xi'an
Locality Name (eg, city) []:shannxi
Organization Name (eg, company) [Internet Widgits Pty Ltd]:open
Organizational Unit Name (eg, section) []:ce
Common Name (e.g. server FQDN or YOUR name) []:local
Email Address []:admin
[root@localhost ~]# systemctl restart nginx
1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
服务器配置
#安装对应包
[root@localhost ~]#yum install rpcbind
OS 2.2 kB/s | 1.9 kB 00:00
everything 2.6 kB/s | 1.9 kB 00:00
EPOL 4.3 kB/s | 1.9 kB 00:00
debuginfo 4.0 kB/s | 2.2 kB 00:00
source 4.1 kB/s | 2.2 kB 00:00
update 357 B/s | 1.9 kB 00:05
update-source 410 B/s | 2.2 kB 00:05
Package rpcbind-1.2.6-8.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost ~]# yum install nfs-utils
Last metadata expiration check: 0:00:13 ago on 2024年01月14日 星期日 09时15分38秒.
Package nfs-utils-2:2.6.2-4.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
#关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start nfs-server
#创建对应文件夹
[root@localhost ~]# mkdir /nfs/shared -pv
mkdir: 已创建目录 '/nfs'
mkdir: 已创建目录 '/nfs/shared'
[root@localhost ~]# mkdir /nfs/upload -pv
mkdir: 已创建目录 '/nfs/upload'
[root@localhost ~]# mkdir /home/tom -pv
mkdir: 已创建目录 '/home/tom'
#分别创建5个文件,方便在客户端查看是否共享
[root@localhost ~]# touch /nfs/shared/{1..5}
[root@localhost ~]# touch /nfs/upload/{1..5}
[root@localhost ~]# touch /home/tom/{1..5}
#编辑配置文件
[root@localhost ~]# vim /etc/exports
/nfs/shared *(ro,anonuid=210,anongid=210)
/nfs/upload 192.168.168.136/24(rw,anonuid=210,anongid=210)
/home/tom 192.168.168.136/24(rw,anonuid=210,anongid=210)
#导出配置
[root@localhost ~]# exportfs -r
客户端配置
#安装对应包
[root@localhost ~]# yum install -y nfs-utils -y
OS 4.8 kB/s | 1.9 kB 00:00
everything 3.5 kB/s | 1.9 kB 00:00
EPOL 1.9 kB/s | 1.9 kB 00:01
debuginfo 2.7 kB/s | 2.2 kB 00:00
source 4.3 kB/s | 2.2 kB 00:00
update 2.3 kB/s | 1.9 kB 00:00
update-source 4.2 kB/s | 2.2 kB 00:00
Package nfs-utils-2:2.6.2-4.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
#创建对应文件夹(存放共享文件)
[root@localhost ~]# mkdir /nfs
[root@localhost ~]# mkdir /nfs/shared
[root@localhost ~]# mkdir /nfs/upload
#挂载对应文件
[root@localhost ~]# mount 192.168.168.131:/nfs/shared /nfs/shared
[root@localhost ~]# mount 192.168.168.131:/nfs/upload /nfs/upload
[root@192 ~]# mount 192.168.168.131:/home/tom /nfs/tom
#验证是否挂载成功
[root@localhost ~]# ll /nfs/shared
总计 0
-rw-r--r--. 1 root root 0 1月16日 11:53 1
-rw-r--r--. 1 root root 0 1月16日 11:53 2
-rw-r--r--. 1 root root 0 1月16日 11:53 3
-rw-r--r--. 1 root root 0 1月16日 11:53 4
-rw-r--r--. 1 root root 0 1月16日 11:53 5
[root@localhost ~]# ll /nfs/upload/
总计 0
-rw-r--r--. 1 root root 0 1月16日 11:53 1
-rw-r--r--. 1 root root 0 1月16日 11:53 2
-rw-r--r--. 1 root root 0 1月16日 11:53 3
-rw-r--r--. 1 root root 0 1月16日 11:53 4
-rw-r--r--. 1 root root 0 1月16日 11:53 5
[root@localhost ~]# ll /nfs/tom/
总计 0
-rw-r--r--. 1 root root 0 1月16日 11:53 1
-rw-r--r--. 1 root root 0 1月16日 11:53 2
-rw-r--r--. 1 root root 0 1月16日 11:53 3
-rw-r--r--. 1 root root 0 1月16日 11:53 4
-rw-r--r--. 1 root root 0 1月16日 11:53 5
[root@localhost ~]# touch /nfs/upload/6
[root@localhost ~]# ll /nfs/upload/
总计 0
-rw-r--r--. 1 root root 0 1月16日 11:53 1
-rw-r--r--. 1 root root 0 1月16日 11:53 2
-rw-r--r--. 1 root root 0 1月16日 11:53 3
-rw-r--r--. 1 root root 0 1月16日 11:53 4
-rw-r--r--. 1 root root 0 1月16日 11:53 5
-rw-r--r--. 1 210 210 0 1月16日 12:00 6