码迷,mamicode.com
首页 > Web开发 > 详细

马哥-搭建简易的Apache服务

时间:2019-11-02 23:46:26      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:text   targe   wal   lld   test   ocs   插入   -o   upd   

1.查看httpd的服务状态:显示httpd单元,无法找到服务。
[root@localhost ~]#systemctl status httpd
Unit httpd.service could not be found.

2. 使用yum安装httpd服务,下面是安装过程:

[root@localhost ~]#yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be install
--> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos fo
--> Processing Dependency: /etc/mime.types for package: httpd-2
--> Processing Dependency: libaprutil-1.so.0()(64bit) for packa
--> Processing Dependency: libapr-1.so.0()(64bit) for package: 
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be i
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================
 Package                          Arch                        V
===============================================================
Installing:
 httpd                            x86_64                      2
Installing for dependencies:
 apr                              x86_64                      1
 apr-util                         x86_64                      1
 httpd-tools                      x86_64                      2
 mailcap                          noarch                      2

Transaction Summary
===============================================================
Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-5.el7.x86_64.rpm                              
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                         
(3/5): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm              
(4/5): mailcap-2.1.41-2.el7.noarch.rpm                         
(5/5): httpd-2.4.6-90.el7.centos.x86_64.rpm                    
---------------------------------------------------------------
Total                                                          
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-5.el7.x86_64                          
  Installing : apr-util-1.5.2-6.el7.x86_64                     
  Installing : httpd-tools-2.4.6-90.el7.centos.x86_64          
  Installing : mailcap-2.1.41-2.el7.noarch                     
  Installing : httpd-2.4.6-90.el7.centos.x86_64                
  Verifying  : apr-1.4.8-5.el7.x86_64                          
  Verifying  : mailcap-2.1.41-2.el7.noarch                     
  Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64          
  Verifying  : apr-util-1.5.2-6.el7.x86_64                     
  Verifying  : httpd-2.4.6-90.el7.centos.x86_64                

Installed:
  httpd.x86_64 0:2.4.6-90.el7.centos                           

Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7   apr-util.x86_64 0:1.5.2-6.el7   ht

Complete!

3.再次查看httpd服务的状态

[root@localhost ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disab
   Active: inactive (dead) #显示死了,也就是关闭状态
     Docs: man:httpd(8)
           man:apachectl(8)

4.使用start开启httpd服务

[root@localhost ~]#systemctl start httpd

使用ss -nlt确认80端口打开

[root@localhost /etc/httpd/conf.d]#ss -nlt
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128    127.0.0.1:631                 *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    127.0.0.1:6010                *:*                  
LISTEN     0      128     *:58699               *:*                  
LISTEN     0      128     *:111                 *:*                  
LISTEN     0      5      192.168.122.1:53                  *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      128     [::1]:631                  [::]:*                  
LISTEN     0      100     [::1]:25                   [::]:*                  
LISTEN     0      128     [::1]:6010                 [::]:*                  
LISTEN     0      128      [::]:38016                [::]:*                  
LISTEN     0      128      [::]:111                  [::]:*                  
LISTEN     0      128      [::]:80                   [::]:*                  
LISTEN     0      128      [::]:22                   [::]:*   

5.再次检查httpd服务的状态

 [root@localhost ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disab
   Active: active (running) since Fri 2019-10-11 19:16:34 CST;  #显示服务已经跑起来了,已启用
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 9866 (httpd)
   Status: "Processing requests..."
    Tasks: 6
   CGroup: /system.slice/httpd.service
           ├─9866 /usr/sbin/httpd -DFOREGROUND
           ├─9867 /usr/sbin/httpd -DFOREGROUND
           ├─9868 /usr/sbin/httpd -DFOREGROUND
           ├─9869 /usr/sbin/httpd -DFOREGROUND
           ├─9870 /usr/sbin/httpd -DFOREGROUND
           └─9871 /usr/sbin/httpd -DFOREGROUND

Oct 11 19:16:34 localhost.localdomain systemd[1]: Starting The 
Oct 11 19:16:34 localhost.localdomain httpd[9866]: AH00558: htt
Oct 11 19:16:34 localhost.localdomain systemd[1]: Started The A
Hint: Some lines were ellipsized, use -l to show in full.

6.使用浏览器访问自己的虚拟机的IP地址,如果访问不了,检查是否添加了桥接网卡,没有的话就手动添加一块

技术图片

7.如果添加了桥接网卡,通过浏览器还是连接不上虚拟机IP地址的话,可以使用下面的命令关闭防火墙

[root@localhost ~]#systemctl disable --now firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.           

8.关闭防火墙后,再次确认httpd服务是否开启

[root@localhost ~]#systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disab
   Active: active (running) since Fri 2019-10-11 19:16:34 CST;  #显示服务已经跑起来了,已启用
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 9866 (httpd)
   Status: "Processing requests..."
    Tasks: 6
   CGroup: /system.slice/httpd.service
           ├─9866 /usr/sbin/httpd -DFOREGROUND
           ├─9867 /usr/sbin/httpd -DFOREGROUND
           ├─9868 /usr/sbin/httpd -DFOREGROUND
           ├─9869 /usr/sbin/httpd -DFOREGROUND
           ├─9870 /usr/sbin/httpd -DFOREGROUND
           └─9871 /usr/sbin/httpd -DFOREGROUND

Oct 11 19:16:34 localhost.localdomain systemd[1]: Starting The 
Oct 11 19:16:34 localhost.localdomain httpd[9866]: AH00558: htt
Oct 11 19:16:34 localhost.localdomain systemd[1]: Started The A
Hint: Some lines were ellipsized, use -l to show in full.                           

9.确认开启httpd服务后,此时就可以使用浏览器进行访问了

技术图片

马哥-搭建简易的Apache服务

标签:text   targe   wal   lld   test   ocs   插入   -o   upd   

原文地址:https://blog.51cto.com/14547542/2447180

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!