设置防火墙默认的区域
虚拟机server
[root@server0 ~]# firewall-cmd --set-default-zone=trusted
虚拟机desktop
[root@desktop0 ~]# firewall-cmd --set-default-zone=trusted
#######################################################
普通NFS服务
NFS共享概述
• Network File System,网络文件系统
– 用途:为客户机提供共享使用的文件夹
– 协议:NFS(TCP/UDP 2049)、RPC(TCP/UDP 111)
• 所需软件包:nfs-utils
• 系统服务:nfs-server
服务端:虚拟机server
1.检测nfs-utils软件包的安装
[root@server0 ~]# rpm -q nfs-utils
nfs-utils-1.3.0-0.el7.x86_64
2.创建共享的目录
[root@server0 ~]# mkdir /nsd
[root@server0 ~]# echo haha > /nsd/1.txt
[root@server0 ~]# ls /nsd
3.修改配置文件
[root@server0 ~]# vim /etc/exports
– 文件夹路径 客户机地址(权限) 客户机地址(权限) … …
/nsd *(ro) #允许所有客户端以只读方式访问
4.重起nfs-server服务
[root@server0 ~]# systemctl restart nfs-server
客户端:虚拟机desktop
1.挂载访问
[root@desktop0 ~]# mkdir /mnt/abc
[root@desktop0 ~]# ls /mnt/abc
[root@desktop0 ~]# showmount -e 172.25.0.11 #显示服务端共享信息
[root@desktop0 ~]# mount 172.25.0.11:/nsd /mnt/abc/
[root@desktop0 ~]# df -h
2.开机自动挂载
_netdev:声明网络设备
在具备网络参数(IP地址、子网掩码、网关地址、DNS服务器地址)之后,挂载本设备
[root@desktop0 ~]# vim /etc/fstab
172.25.0.11:/nsd /mnt/abc nfs defaults,_netdev 0 0
[root@desktop0 ~]# umount /mnt/abc/
[root@desktop0 ~]# df -h
[root@desktop0 ~]# mount -a
[root@desktop0 ~]# df -h
##########################################################
HTTP服务基础
• 基于 B/S (Browser/Server)架构的网页服务
– 服务端提供网页
– 浏览器下载并显示网页
• Hyper Text Markup Language(html),超文本标记语言
• Hyper Text Transfer Protocol(http),超文本传输协议 默认端口:80
实现Web服务的软件:httpd、nginx、tomcat、…
虚拟机server:
1.安装httpd
[root@server0 ~]# yum -y install httpd
2.重起httpd服务
[root@server0 ~]# systemctl restart httpd
3.书写一个页面文件
默认的路径为:/var/www/html/index.html
[root@server0 ~]# echo ‘
NSD1911’ > /var/www/html/index.html
[root@server0 ~]# cat /var/www/html/index.html
虚拟机desktop
[root@desktop0 ~]# firefox 172.25.0.11
####################################################
Apache(软件基金会)
#####################################################
RHEL7中的Web服务
• 软件包:httpd
• 系统服务:httpd
• 提供的默认配置
– Listen:监听地址:端口(80)
– ServerName:本站点注册的DNS名称(空缺)
– DocumentRoot:网页文件根目录(/var/www/html)
– DirectoryIndex:起始页/首页文件名(index.html)
DNS服务器:将域名解析为IP地址 虚拟机classroom
域名: server0.example.com
www0.example.com
webapp0.example.com
[root@desktop0 ~]# nslookup server0.example.com
[root@desktop0 ~]# nslookup www0.example.com
[root@desktop0 ~]# nslookup webapp0.example.com
#########################################################
– DocumentRoot:网页文件根目录
虚拟机server:
1.建立新的网页文件存放目录
]# mkdir /var/www/myweb
]# echo ‘
wo shi myweb’ > /var/www/myweb/index.html
2.修改主配置文件
[root@server0 ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot “/var/www/myweb”
[root@server0 ~]# systemctl restart httpd
虚拟机desktop
[root@desktop0 ~]# firefox 172.25.0.11
#######################################################
客户端:firefox http://172.25.0.11:80
---->服务端 172.25.0.11--------》httpd---->/etc/httpd/conf/httpd.conf
---->DocumentRoot /var/www/myweb ---->index.html
– DocumentRoot:网页文件根目录=寻找网页文件路径的起始点
网络路径:在浏览器输入的路径
实际路径:网页文件存放的路径
客户端网络路径:firefox http://172.25.0.11
服务端实际路径:/var/www/myweb
172.25.0.11=/var/www/myweb
客户端网络路径:firefox http://172.25.0.11/stu
服务端实际路径:/var/www/myweb/stu
客户端网络路径:firefox http://172.25.0.11/abc/test
服务端实际路径:/var/www/myweb/abc/test
客户端网络路径:firefox http://172.25.0.11/haha/xixi
服务端实际路径:/var/www/myweb/haha/xixi
DocumentRoot /var/www/myweb
客户端网络路径:firefox http://172.25.0.11/var/www/myweb/xixi
服务端实际路径:/var/www/myweb/var/www/myweb/xixi
虚拟机server:
]# mkdir /var/www/myweb/test
]# echo ‘
wo shi test’ > /var/www/myweb/test/index.html
]# firefox 172.25.0.11/test
########################################################
自定义Web网页文件根目录
虚拟机server:
1.建立自定义目录
[root@server0 ~]# mkdir /haxi
[root@server0 ~]# echo ‘
wo shi haxi’ > /haxi/index.html
2.指定新的网页文件根目录
[root@server0 ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot “/haxi”
3.重起httpd服务
[root@server0 ~]# systemctl restart httpd
4.修改SELinux模式
[root@server0 ~]# getenforce #查看SELinux当前的运行模式
Enforcing
[root@server0 ~]# setenforce 0 #修改SELinux运行的模式
[root@server0 ~]# getenforce
Permissive
[root@server0 ~]# vim /etc/selinux/config
SELINUX=permissive
5.关于httpd服务访问控制
针对网页文件存放的路径,实行的访问控制
自动继承父目录的访问控制规则
<Directory “/var/www”>
Require all granted #允许所有人访问
/var/www/student #允许所有人访问
/var/www/student/test #允许所有人访问
<Directory /var/www/student/test/abc>
Require all denied #拒绝所有人访问
/var/www/student/test/abc #拒绝所有人访问
/var/www/student/test/abc/dc #拒绝所有人访问
/var/www/student/tc #允许所有人访问
主配置文件规则配置:
<Directory “/”>
Require all denied #拒绝所有人访问
<Directory “/var/www”>
Require all granted #允许所有人访问
[root@server0 ~]# vim /etc/httpd/conf/httpd.conf
…
<Directory “/haxi”> #针对与/haxi进行访问控制
Require all granted #允许所有人访问
[root@server0 ~]# systemtcl restart httpd #重起httpd服务
[root@server0 ~]# firefox 172.25.0.11
#######################################################
主配置文件:/etc/httpd/conf/httpd.conf
调用配置文件:/etc/httpd/conf.d/*.conf
虚拟Web主机
– 由同一台服务器提供多个不同的Web站点
• 区分方式
– 基于域名的虚拟主机
– 基于端口的虚拟主机
– 基于IP地址的虚拟主机
为每个虚拟站点添加配置
<VirtualHost 本机IP地址:端口>
ServerName 此站点的DNS名称
DocumentRoot 此站点的网页根目录
虚拟机server:
[root@server0 ~]# vim /etc/httpd/conf.d/hehe.conf
<VirtualHost *:80> #本机的所有地址都提供虚拟Web主机功能
ServerName www0.example.com #指定域名
DocumentRoot /var/www/qq #指定存放网页文件路径
<VirtualHost *:80>
ServerName webapp0.example.com
DocumentRoot /var/www/baidu
[root@server0 ~]# cd /var/www/
[root@server0 www]# mkdir qq baidu
[root@server0 www]# echo ‘
企鹅’ > qq/index.html
[root@server0 www]# echo ‘
度娘’ > baidu/index.html
[root@server0 /]# systemctl restart httpd
一旦使用虚拟Web主机的功能,所有的网站都必须利用虚拟Web主机的功能呈现
[root@server0 /]# vim /etc/httpd/conf.d/hehe.conf
<VirtualHost *:80>
ServerName www0.example.com
DocumentRoot /var/www/qq
<VirtualHost *:80>
ServerName webapp0.example.com
DocumentRoot /var/www/baidu
<VirtualHost *:80>
ServerName server0.example.com
DocumentRoot /var/www/myweb
[root@server0 /]# systemctl restart httpd
[root@server0 /]# firefox server0.example.com
##########################################################