系统&服务管理进阶01

管理运行级别

RHEL6:运行级别 300

0:关机 0个服务

1:单用户模式(基本功能的实现,破解Linux密码) 50个服务

2:多用户字符界面(不支持网络) 80个服务

3:多用户字符界面(支持网络)服务器默认运行级别 100个服务

4:未定义 0个服务

5:图形界面     300个服务

6:重起 0个服务

切换运行级别:init   数字

RHEL7:运行模式(运行级别)

字符模式:multi-user.target

图形模式:graphical.target

当前直接切换到字符模式

]# systemctl isolate multi-user.target   #相当于原来的init 3

当前直接切换到图形模式

]# systemctl isolate graphical.target    #相当于原来的init 5

查看每次开机默认进入模式

[root@svr7 /]# systemctl get-default

设置永久策略,每次开机自动进入multi-user.target

[root@svr7 /]# systemctl  set-default   multi-user.target

[root@svr7 /]# reboot

二、Web服务器简介

  • 基于 B/S (Browser/Server)架构的网页服务
    • 服务端提供网页
    • 浏览器下载并显示网页
  • Hyper Text Markup Language,超文本标记语言
  • Hyper Text Transfer  Protocol,超文本传输协议

三步骤策略:装包、配置、启服务

实现Web功能软件:httpd、Nginx、Tomcat

httpd由软件基金会Apache

虚拟机A:构建基本Web服务

]# yum -y install httpd

]# rpm  -q  httpd

]# echo NSD Web Server >    /var/www/html/index.html

]# > /etc/resolv.conf

]# systemctl restart httpd       #重新启动服务

]# curl  http://192.168.4.7    #测试访问

NSD  Web  Server

  • 显示测试页面(欢迎页面)的原因

1.没有书写任何的网页文件

2.书写的页面文件,没有命名成index.html

3.存放网页文件目录,访问规则为拒绝所有客户端访问

  • 提供的默认配置
    • Listen:监听地址:端口(80)
    • ServerName:本站点注册的DNS名称(空缺)
    • DocumentRoot:网页根目录(/var/www/html)
    • DirectoryIndex:起始页/首页文件名(index.html)

主配置文件:/etc/httpd/conf/httpd.conf

常见错误:

[root@svr7 ~]# systemctl  restart httpd

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

[root@svr7 ~]# journalctl -xe

DocumentRoot:网页文件根目录(/var/www/html)

虚拟机A
]# mkdir   /var/www/myweb
]# echo  wo shi myweb > /var/www/myweb/index.html
]# vim    /etc/httpd/conf/httpd.conf
…….此处省略一万字
DocumentRoot    "/var/www/myweb"                #修改配置
…….此处省略一万字

]# systemctl  restart  httpd    #重启服务
]# curl  http://192.168.4.7
wo shi myweb

Web服务针对存放网页的目录

默认继承

/     #拒绝所有客户端访问

/var/www   #允许所有客户端访问

总结:只有网页文件放到/var/www下,客户端才可以访问

   /webroot

  /var/www/myweb     #允许所有客户端访问

  /var/www/myweb/cbd     #允许所有客户端访问

  /var    #拒绝所有客户端访问

  1. 基于网页文件目录,进行访问控制

当子目录没有规则,默认继承上一级目录规则

   针对此目录有单独配置,则不继承上一级目录规则

总结:只有网页文件放到/var/www下,客户端才可以访问

容器式格式 

容器式格式:
<Directory />
    Require all denide   #拒绝所有人
<Directory>


<Dirctory  "/var/www">
    Require all granted  #允许所有人.
</Directory>



虚拟机A:                     

]# mkdir   /webroot

]# echo wo shi webroot  >  /webroot/index.html

]# vim   /etc/httpd/conf/httpd.conf

…….此处省略一万字

DocumentRoot    "/webroot"

<Directory   "/webroot">   #针对于/webroot路径

    Require all granted       #允许所有人访问

</Directory>

…….此处省略一万字

]# systemctl restart httpd    #重启服务

]# curl http://192.168.4.7      

 wo shi webroot

客户端:curl  http://192.168.4.7---->服务端---->http协议---->httpd进程---》/etc/httpd/conf/httpd.conf---->DocumentRoot ---->/webroot----->index.html

客户端:curl  http://192.168.4.7    #网络路径

服务端:/webroot/index.html      #实际路径

http://192.168.4.7 = DocumentRoot  /webroot

客户端:curl  http://192.168.4.7/abc

服务端:/webroot/abc/index.html      #实际路径

  1. 网络路径与实际路径

DocumentRoot ---》/webroot

网络路径:curl   http://192.168.4.7

实际服务:/webroot

访问过程:客户端curl   http://192.168.4.7--->服务端192.168.4.7---》80---》httpd---》/etc/httpd/conf/httpd.conf---》DocumentRoot ---》/webroot---》index.html

网络路径:curl   http://192.168.4.7/abc

实际服务: /webroot/abc/index.html

虚拟机A

]# mkdir   /webroot/abc

]# echo wo shi abc > /webroot/abc/index.html



]# curl   http://192.168.4.7/abc/

 

  1. Listen:监听IP地址: 监听端口(80)

端口:数字编号起到标识作用,标识协议

  http协议默认端口:80

建议自定义端口时大于1024端口的极限65535

[root@svr7 ~]#vim  /etc/httpd/conf/httpd.conf
…….此处省略一万字
Listen  80
Listen  8100             
…….此处省略一万字
[root@svr7 ~]# systemctl   restart httpd

[root@svr7 ~]#curl  192.168.4.7:8100
[root@svr7 ~]#curl  192.168.4.7  #默认是80端口

 

<VirtualHost    *:80>
        ServerName   www.qq.com
        DocunentRoot /var/www/qq
<VirtualHost   *:80>
<VirtualHost     *:80>
        SeverName   www.lol.com
        DocunmentRoot /var/www/lol
<VirtualHost     *:80>

三、虚拟Web主机

  • 虚拟Web主机
    • 由同一台服务器提供多个不同的Web站点
  • 区分方式
    • 基于域名的虚拟主机
    • 基于端口的虚拟主机
    • 基于IP地址的虚拟主机

  • 配置文件路径
    • /etc/httpd/conf/httpd.conf  #主配置文件
    • /etc/httpd/conf.d/*.conf   #调用配置文件

  • 为每个虚拟站点添加配置

<VirtualHost   IP地址:端口>

       ServerName  此站点的DNS名称

       DocumentRoot  此站点的网页根目录

</VirtualHost>

虚拟机A:

[root@svr7 ~]# vim  /etc/httpd/conf.d/haha.conf

<VirtualHost    *:80>          #在所有IP地址监听80

   ServerName   www.qq.com        #网站的域名

   DocumentRoot   /var/www/qq   #网页文件路径

</VirtualHost>

<VirtualHost    *:80>

   ServerName    www.lol.com

   DocumentRoot   /var/www/lol

</VirtualHost>

]# mkdir  /var/www/qq   /var/www/lol

]# echo wo  shi  QQ  >  /var/www/qq/index.html

]# echo wo  shi  lol  >  /var/www/lol/index.html

]# systemctl  restart   httpd

采用/etc/hosts文件直接解析域名,只为本机解析

]# vim   /etc/hosts

…….此处省略一万字

192.168.4.7   www.qq.com    www.lol.com

]# curl  http://www.qq.com

]# curl  http://www.lol.com

]# mkdir  /var/www/qq   /var/www/lol

]# echo wo  shi  QQ  >  /var/www/qq/index.html

]# echo wo  shi  lol  >  /var/www/lol/index.html

]# systemctl  restart   httpd



采用/etc/hosts文件直接解析域名,只为本机解析

]# vim   /etc/hosts

…….此处省略一万字

192.168.4.7   www.qq.com    www.lol.com

]# curl  http://www.qq.com

]# curl  http://www.lol.com

 

将事先写好的页面(web.zip)传递到虚拟机上:

将事先写好的页面(web.zip),传递到虚拟机A

Linux真机上:

[root@localhost ~]# scp  /root/下载/web.zip  root@192.168.4.7:/root

windows真机上:

]# ls /root/web.zip
/root/web.zip
]# mkdir /nb
]# unzip /root/web.zip -d /nb
]# ls /nb/
]# ls /nb/web/
]# ls /nb/web/html/

]#cp -r /nb/web/html/*   /var/www/
]# ls  /var/www/

]# vim /etc/httpd/conf.d/xixi.conf 
<VirtualHost  *:80>
   ServerName  www.nb1.com
   DocumentRoot  /var/www/nsd01
</VirtualHost>
<VirtualHost  *:80>  
   ServerName  www.nb2.com
   DocumentRoot  /var/www/nsd02
</VirtualHost>
<VirtualHost  *:80>
   ServerName  www.nb3.com
   DocumentRoot  /var/www/nsd03
</VirtualHost>
<VirtualHost  *:80>
   ServerName  www.nb4.com
   DocumentRoot  /var/www/nsd04
</VirtualHost>
[root@svr7 ~]# systemctl  restart  httpd
[root@svr7 ~]# vim  /etc/hosts
…….此处省略一万字
192.168.4.7  www.nb1.com
192.168.4.7  www.nb2.com
192.168.4.7  www.nb3.com
192.168.4.7  www.nb4.com

 一旦使用虚拟Web主机功能,所有的网站都必须使用虚拟Web进行呈现

虚拟机A
[root@svr7 ~]# vim /etc/httpd/conf.d/haha.conf
…….此处省略一万字
<VirtualHost  *:80>
   ServerName    www.xixi.com
   DocumentRoot    /webroot
</VirtualHost>
[root@svr7 ~]# systemctl restart httpd
[root@svr7 ~]# vim /etc/hosts
…….此处省略一万字
192.168.4.7   www.qq.com   www.lol.com   www.xixi.com
[root@svr7 ~]# curl  http://www.xixi.com

  1. 基于端口的虚拟Web主机
]# vim  /etc/httpd/conf.d/haha.conf
<VirtualHost   *:80>
   ServerName  www.qq.com
   DocumentRoot   /var/www/qq
</VirtualHost>
Listen  8080                #httpd程序监听8080端口
<VirtualHost   *:8080>    #网站使用8080端口
   ServerName   www.qq.com
   DocumentRoot    /var/www/lol
</VirtualHost>
[root@svr7 ~]# systemctl restart httpd
[root@svr7 ~]# curl  www.qq.com:8080
[root@svr7 ~]# curl  www.qq.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值