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

Web服务介绍 & httpd安装

时间:2016-11-01 21:39:11      阅读:746      评论:0      收藏:0      [点我收藏+]

标签:yum   web服务   rpm   源码安装   www   

Web简介


什么是Web

    WWWWorld Wide Web,万维网

    英国人TimBerners-Lee1989年欧洲共同体的一个大型科研机构工作时发明的

    Web是一种超文本信息系统,其主要实现方式是超文本连接

     

Web特点

    1Web页面的图形化和易于链接

    2Web与操作系统、浏览器平台无关

    3、分布式

    4、动态习惯

    5、交互性


Web工作原理

HTTPHyper Text Transfer Protocol,超文本传输协议):提供了访问超文本信息的功能,是Web浏览器和Web服务器之间的应用层通信协议

HTTP协议是用于分布式写作超文本信息系统的、通用的、面向对象的协议

Web使用HTTP协议传输各种超文本页面和数据

URL,统一资源标识符:是一个世界通用的负责给万维网上的资源(如网页)定位的系统

 

静态网站和动态网站的区别

1、静态网站

    没有任何程序开发的网站,纯HTML编写;网页文件名是htmlhtm结尾的


    优点:打开速度相对比较快;网站容易被搜索引擎收录;比较安全,重要数据不会丢失

    缺点:不能直接对网站内容进行修改,实现不了交互等功能


2、动态网站

    通过后台程序,可以方便的对整个网站内容进行修改、删除操作

    这些程序都要使用数据库才能完成动态的操作

     

    动态网站的开发语言有:ASP , JSP , PHP , ASP.NET

    数据库:AccessMySQLOracleSQL Server

 

    常用组合:

        ASP --> AccessMySQL

        PHP --> MySQL

        JSP  --> MySQLOracle

     

    优点:维护方便,能实现需要的各种需求;查询信息方便

    缺点:要用到数据库,对数据的安全和保密性要求较高;动态网站不利于搜索引擎记录;制作成本较高

     

Web错误代码

    如果出现错误会返回一个表示该请求状态的数字代码,该状态代码记录在Web服务器日志中,同时可以可能在Web浏览器中显示


    Web错误代码:

        错误代码描述

        400错误的请求

        401未经授权

        403禁止访问:访问被拒绝

        404找不到文件或目录

        405用户访问该页的HTTP动作未被许可

        408请求时间超时

        410系统资源已经不存在

        411需要内容长度头

        412客户端设置的前提条件在Web服务器上评估时失败

        413请求实体太大

        414请求URL太大

        415不支持的媒体类型

        500服务器内部错误

        501标题值指定的配置没有执行

        502Web服务器作为网关或代理服务器时收到无效的响应

        503服务不可用

 

Apache简介

Apache HTTPServer,简称ApacheApache软件基金会的一个开放源代码的网页服务器

可运行在UNIXWindowsLinux等系统中

    快速、可靠并且可以通过简单的API扩展,将PerlPython等解释器编译到服务器中

 

    Apache源于NCSA httpd 服务器,经过多次修改发展而成。

    特点:简单、速度快、性能稳定、并可以作为代理服务器使用

 

Apache的特性

    支持HTTP/1.1通信协议

    拥有简单而强有力的基于文件的配置过程

    支持通用网关接口(CGI

    支持基于端口号、IP地址和域名的虚拟主机

    支持多种方式的HTTP认证

    集成Perl代理模块

    支持实时监控服务器状态和定制服务器日志

    支持服务器端包含指令(SSI

    支持安全Socket层(SSL

    提供用户会话过程的跟踪

    支持FastCGI

    通过第三方模块可以支持Java Servlets


Apache服务安装

    httpd软件包介绍

    httpd-2.2.15-53.el6.centos.x86_64.rpm               #Apache服务主程序软件包

    httpd-devel-2.2.15-53.el6.centos.x86_64.rpm         #Apache库程序

    httpd-manual-2.2.15-53.el6.centos.noarch.rpm        #Apache服务器手册

    httpd-tools-2.2.15-53.el6.centos.x86_64.rpm         #Apache服务器使用工具

    

安装httpd

    -> rpm安装

-> yum安装

    -> 源码编译安装

 

rpm安装


CentOS 6.8

1、挂载系统光盘

[root@localhost ~]# ls /mnt/cdrom/
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
images           RPM-GPG-KEY-CentOS-6


 

2、rpm安装httpd

1)、安装httd主程序包

[root@localhost Packages]# rpm -ivh httpd-2.2.15-53.el6.centos.x86_64.rpm 
warning: httpd-2.2.15-53.el6.centos.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...               ########################################### [100%]
   1:httpd                ########################################### [100%]


 

2)、安装帮助手册

[root@localhost Packages]# rpm -ivh httpd-manual-2.2.15-53.el6.centos.noarch.rpm 
warning: httpd-manual-2.2.15-53.el6.centos.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...               ########################################### [100%]
   1:httpd-manual          ########################################### [100%]


 

3)httpd-tools工具

[root@localhost Packages]# rpm -ivh httpd-tools-2.2.15-53.el6.centos.x86_64.rpm 
warning: httpd-tools-2.2.15-53.el6.centos.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
package httpd-tools-2.2.15-53.el6.centos.x86_64 is already installed


 

4)、库程序

[root@localhost Packages]# rpm -ivh httpd-devel-2.2.15-53.el6.centos.x86_64.rpm 
warning: httpd-devel-2.2.15-53.el6.centos.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
apr-devel is needed by httpd-devel-2.2.15-53.el6.centos.x86_64
apr-util-devel is needed by httpd-devel-2.2.15-53.el6.centos.x86_64
 
[root@localhost Packages]# rpm -ivh apr-devel-1.3.9-5.el6_2.x86_64.rpm 
warning: apr-devel-1.3.9-5.el6_2.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...               ########################################### [100%]
   1:apr-devel             ########################################### [100%]
[root@localhost Packages]# rpm -ivh apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm 
warning: apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
expat-devel is needed by apr-util-devel-1.3.9-3.el6_0.1.x86_64
[root@localhost Packages]# rpm -ivh expat-devel-2.0.1-11.el6_2.x86_64.rpm 
warning: expat-devel-2.0.1-11.el6_2.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...               ########################################### [100%]
   1:expat-devel           ########################################### [100%]
[root@localhost Packages]# rpm -ivh apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm 
warning: apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing...               ########################################### [100%]
   1:apr-util-devel        ########################################### [100%]
[root@localhost Packages]# rpm -ivh httpd-devel-2.2.15-53.el6.centos.x86_64.rpm 
warning: httpd-devel-2.2.15-53.el6.centos.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...               ########################################### [100%]
   1:httpd-devel           ########################################### [100%]
 
[root@localhost Packages]# rpm -qa | grep httpd
httpd-manual-2.2.15-53.el6.centos.noarch
httpd-devel-2.2.15-53.el6.centos.x86_64
httpd-tools-2.2.15-53.el6.centos.x86_64
httpd-2.2.15-53.el6.centos.x86_64
 
[root@localhost Packages]# service httpd start
Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1 for ServerName
                                                           [  OK  ]
 
[root@localhost ~]# service httpd status
httpd (pid  2753) is running...


 

技术分享 

 

CentOS 7

1、挂载系统光盘

[root@localhost ~]# ls /mnt/cdrom/
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL


 

2、rpm安装httpd

1)、安装httd主程序包,依赖httpd-tools

[root@localhost Packages]# rpm -ivh httpd-2.4.6-40.el7.centos.x86_64.rpm 
warning: httpd-2.4.6-40.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a0eb5: NOKEY
error: Failed dependencies:
/etc/mime.types is needed by httpd-2.4.6-40.el7.centos.x86_64
httpd-tools = 2.4.6-40.el7.centos is needed by httpd-2.4.6-40.el7.centos.x86_64
 
[root@localhost Packages]# rpm -ivh httpd-tools-2.4.6-40.el7.centos.x86_64.rpm 
warning: httpd-tools-2.4.6-40.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key D f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:httpd-tools-2.4.6-40.el7.centos  ################################# [100%]
[root@localhost Packages]# rpm -ivh mailcap-2.1.41-2.el7.noarch.rpm 
warning: mailcap-2.1.41-2.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mailcap-2.1.41-2.el7             ################################# [100%]
[root@localhost Packages]# rpm -ivh httpd-2.4.6-40.el7.centos.x86_64.rpm 
warning: httpd-2.4.6-40.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:httpd-2.4.6-40.el7.centos        ################################# [100%]


 

2)、安装帮助手册

[root@localhost Packages]# rpm -ivh httpd-manual-2.4.6-40.el7.centos.noarch.rpm 
warning: httpd-manual-2.4.6-40.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:httpd-manual-2.4.6-40.el7.centos ################################# [100%]


 

3)、库程序

[root@localhost Packages]# rpm -ivh httpd-devel-2.4.6-40.el7.centos.x86_64.rpm 
warning: httpd-devel-2.4.6-40.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
apr-devel is needed by httpd-devel-2.4.6-40.el7.centos.x86_64
apr-util-devel is needed by httpd-devel-2.4.6-40.el7.centos.x86_64
 
[root@localhost Packages]# rpm -ivh apr-devel-1.4.8-3.el7.x86_64.rpm 
warning: apr-devel-1.4.8-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:apr-devel-1.4.8-3.el7            ################################# [100%]
[root@localhost Packages]# rpm -ivh apr-util-devel-1.5.2-6.el7.x86_64.rpm 
warning: apr-util-devel-1.5.2-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
expat-devel(x86-64) is needed by apr-util-devel-1.5.2-6.el7.x86_64
libdb-devel(x86-64) is needed by apr-util-devel-1.5.2-6.el7.x86_64
openldap-devel(x86-64) is needed by apr-util-devel-1.5.2-6.el7.x86_64
[root@localhost Packages]# rpm -ivh expat-devel-2.1.0-8.el7.x86_64.rpm 
warning: expat-devel-2.1.0-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:expat-devel-2.1.0-8.el7          ################################# [100%]
[root@localhost Packages]# rpm -ivh libdb-devel-5.3.21-19.el7.x86_64.rpm 
warning: libdb-devel-5.3.21-19.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:libdb-devel-5.3.21-19.el7        ################################# [100%]
[root@localhost Packages]# rpm -ivh openldap-devel-2.4.40-8.el7.x86_64.rpm 
warning: openldap-devel-2.4.40-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
cyrus-sasl-devel(x86-64) is needed by openldap-devel-2.4.40-8.el7.x86_64
[root@localhost Packages]# rpm -ivh cyrus-sasl-devel-2.1.26-19.2.el7.x86_64.rpm 
warning: cyrus-sasl-devel-2.1.26-19.2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
cyrus-sasl(x86-64) = 2.1.26-19.2.el7 is needed by cyrus-sasl-devel-2.1.26-19.2.el7.x86_64
[root@localhost Packages]# rpm -ivh cyrus-sasl-2.1.26-19.2.el7.x86_64.rpm 
warning: cyrus-sasl-2.1.26-19.2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:cyrus-sasl-2.1.26-19.2.el7       ################################# [100%]
[root@localhost Packages]# rpm -ivh cyrus-sasl-devel-2.1.26-19.2.el7.x86_64.rpm 
warning: cyrus-sasl-devel-2.1.26-19.2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:cyrus-sasl-devel-2.1.26-19.2.el7 ################################# [100%]
[root@localhost Packages]# rpm -ivh apr-util-devel-1.5.2-6.el7.x86_64.rpm 
warning: apr-util-devel-1.5.2-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
openldap-devel(x86-64) is needed by apr-util-devel-1.5.2-6.el7.x86_64
[root@localhost Packages]# rpm -ivh openldap-devel-2.4.40-8.el7.x86_64.rpm 
warning: openldap-devel-2.4.40-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:openldap-devel-2.4.40-8.el7      ################################# [100%]
[root@localhost Packages]# rpm -ivh apr-util-devel-1.5.2-6.el7.x86_64.rpm 
warning: apr-util-devel-1.5.2-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:apr-util-devel-1.5.2-6.el7       ################################# [100%]
[root@localhost Packages]# rpm -ivh httpd-devel-2.4.6-40.el7.centos.x86_64.rpm 
warning: httpd-devel-2.4.6-40.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:httpd-devel-2.4.6-40.el7.centos  ################################# [100%]
 
[root@localhost Packages]# rpm -qa | grep httpd
httpd-tools-2.4.6-40.el7.centos.x86_64
httpd-2.4.6-40.el7.centos.x86_64
httpd-manual-2.4.6-40.el7.centos.noarch
httpd-devel-2.4.6-40.el7.centos.x86_64
 
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)
 
[root@localhost Packages]# systemctl start httpd
 
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-10-28 18:47:37 EDT; 4s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2705 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─2705 /usr/sbin/httpd -DFOREGROUND
           ├─2706 /usr/sbin/httpd -DFOREGROUND
           ├─2707 /usr/sbin/httpd -DFOREGROUND
           ├─2708 /usr/sbin/httpd -DFOREGROUND
           ├─2709 /usr/sbin/httpd -DFOREGROUND
           └─2710 /usr/sbin/httpd -DFOREGROUND
 
Oct 28 18:47:37 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Oct 28 18:47:37 localhost.localdomain httpd[2705]: AH00558: httpd: Could not reliably...e
Oct 28 18:47:37 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
 
[root@localhost Packages]# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128              *:22                           *:*                  
LISTEN      0      100      127.0.0.1:25                           *:*                  
LISTEN      0      128             :::80                          :::*                  
LISTEN      0      128             :::22                          :::*                  
LISTEN      0      100            ::1:25                          :::* 
 
[root@localhost ~]# systemctl stop firewalld
或者
[root@localhost ~]# iptables -F


 

技术分享 

 

 

yum安装


1、查看和httpd相关的软件包

CentOS 6.8

[root@localhost ~]# yum list all httpd
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
cdrom                                                              | 4.0 kB     00:00 ... 
Available Packages
httpd.x86_64                          2.2.15-53.el6.centos                        cdrom
 
[root@localhost ~]# yum list all httpd*
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Installed Packages
httpd-tools.x86_64                        2.2.15-53.el6.centos                    @FTP 
Available Packages
httpd.x86_64                              2.2.15-53.el6.centos                    cdrom
httpd-devel.i686                          2.2.15-53.el6.centos                    cdrom
httpd-devel.x86_64                        2.2.15-53.el6.centos                    cdrom
httpd-manual.noarch                       2.2.15-53.el6.centos                    cdrom


 

2、查看httpd软件包的描述信息

[root@localhost ~]# yum info httpd
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.2.15
Release     : 53.el6.centos
Size        : 833 k
Repo        : cdrom
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.


 

3、安装httpd软件包

[root@localhost ~]# yum install -y httpd
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-53.el6.centos will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
==========================================================================================
 Package         Arch             Version                           Repository       Size
==========================================================================================
Installing:
 httpd           x86_64           2.2.15-53.el6.centos              cdrom           833 k
 
Transaction Summary
==========================================================================================
Install       1 Package(s)
 
Total download size: 833 k
Installed size: 3.0 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : httpd-2.2.15-53.el6.centos.x86_64                                      1/1 
  Verifying  : httpd-2.2.15-53.el6.centos.x86_64                                      1/1 
 
Installed:
  httpd.x86_64 0:2.2.15-53.el6.centos                                                     
 
Complete!
 
 
[root@localhost ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1 for ServerName
                                                           [  OK  ]
[root@localhost ~]# ss -tnl
State      Recv-Q Send-Q             Local Address:Port               Peer Address:Port 
LISTEN     0      128                           :::80                           :::*     
LISTEN     0      3                            ::1:53                           :::*     
LISTEN     0      3                 192.168.80.155:53                            *:*     
LISTEN     0      3                  172.18.16.147:53                            *:*     
LISTEN     0      3                     172.16.1.5:53                            *:*     
LISTEN     0      3                      127.0.0.1:53                            *:*     
LISTEN     0      128                           :::22                           :::*     
LISTEN     0      128                            *:22                            *:*     
LISTEN     0      100                          ::1:25                           :::*     
LISTEN     0      100                    127.0.0.1:25                            *:*     
LISTEN     0      128                          ::1:953                          :::*     
LISTEN     0      128                    127.0.0.1:953                           *:*


 

4、客户端访问

技术分享 

 

5、卸载httpd软件包

[root@localhost ~]# yum remove -y httpd
Loaded plugins: fastestmirror, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-53.el6.centos will be erased
--> Finished Dependency Resolution
 
Dependencies Resolved
 
==========================================================================================
 Package         Arch             Version                          Repository        Size
==========================================================================================
Removing:
 httpd           x86_64           2.2.15-53.el6.centos             @cdrom           3.0 M
 
Transaction Summary
==========================================================================================
Remove        1 Package(s)
 
Installed size: 3.0 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : httpd-2.2.15-53.el6.centos.x86_64                                      1/1 
  Verifying  : httpd-2.2.15-53.el6.centos.x86_64                                      1/1 
 
Removed:
  httpd.x86_64 0:2.2.15-53.el6.centos                                                     
 
Complete!


 

CentOS 7

1、查看和httpd相关的软件包

[root@localhost ~]# yum list all httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
httpd.x86_64                         2.4.6-40.el7.centos                   cdrom
 
[root@localhost ~]# yum list all httpd*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
httpd.x86_64                         2.4.6-40.el7.centos                   cdrom
httpd-devel.x86_64                   2.4.6-40.el7.centos                   cdrom
httpd-manual.noarch                  2.4.6-40.el7.centos                   cdrom
httpd-tools.x86_64                   2.4.6-40.el7.centos                   cdrom


 

2、查看httpd软件包的描述信息

[root@localhost ~]# yum info httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 40.el7.centos
Size        : 2.7 M
Repo        : cdrom/7/x86_64
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.


 

3、安装httpd软件包

[root@localhost ~]# yum install -y httpd
Loaded plugins: fastestmirror
cdrom                                                              | 3.6 kB  00:00:00     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos for package: httpd-2.4.6-40.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
==========================================================================================
 Package              Arch            Version                     Repository      Size
==========================================================================================
Installing:
 httpd               x86_64          2.4.6-40.el7.centos             cdrom          2.7 M
Installing for dependencies:
 httpd-tools          x86_64          2.4.6-40.el7.centos             cdrom           82 k
 mailcap             noarch          2.1.41-2.el7                   cdrom           31 k
 
Transaction Summary
==========================================================================================
Install  1 Package (+2 Dependent packages)
 
Total download size: 2.8 M
Installed size: 9.6 M
Downloading packages:
(1/3): httpd-tools-2.4.6-40.el7.centos.x86_64.rpm                    |  82 kB  00:00:00     
(2/3): mailcap-2.1.41-2.el7.noarch.rpm                             |  31 kB  00:00:00     
(3/3): httpd-2.4.6-40.el7.centos.x86_64.rpm                         | 2.7 MB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                 9.5 MB/s | 2.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-tools-2.4.6-40.el7.centos.x86_64                                1/3 
  Installing : mailcap-2.1.41-2.el7.noarch                                         2/3 
  Installing : httpd-2.4.6-40.el7.centos.x86_64                                     3/3 
  Verifying  : httpd-2.4.6-40.el7.centos.x86_64                                    1/3 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                        2/3 
  Verifying  : httpd-tools-2.4.6-40.el7.centos.x86_64                               3/3 
 
Installed:
  httpd.x86_64 0:2.4.6-40.el7.centos                                                      
 
Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-40.el7.centos          mailcap.noarch 0:2.1.41-2.el7         
 
Complete!
 
[root@localhost ~]# rpm -q httpd
httpd-2.4.6-40.el7.centos.x86_64
 
[root@localhost ~]# systemctl start httpd
 
[root@localhost ~]# ss -tnl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128               *:22                            *:*                  
LISTEN     0      100       127.0.0.1:25                            *:*                  
LISTEN     0      128              :::80                           :::*                  
LISTEN     0      128              :::22                           :::*                  
LISTEN     0      100             ::1:25                           :::*  
 
[root@localhost ~]# systemctl stop firewalld
或者
[root@localhost ~]# iptables -F


 

4、客户端访问

技术分享 

 

5、卸载httpd软件包

[root@localhost ~]# yum remove httpd
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be erased
--> Finished Dependency Resolution
 
Dependencies Resolved
 
==========================================================================================
 Package         Arch             Version                          Repository        Size
==========================================================================================
Removing:
 httpd           x86_64           2.4.6-40.el7.centos              @cdrom           9.4 M
 
Transaction Summary
==========================================================================================
Remove  1 Package
 
Installed size: 9.4 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : httpd-2.4.6-40.el7.centos.x86_64                                       1/1 
  Verifying  : httpd-2.4.6-40.el7.centos.x86_64                                       1/1 
 
Removed:
  httpd.x86_64 0:2.4.6-40.el7.centos                                                      
 
Complete!


 

源码编译安装


CentOS 6.8

软件包:httpd-2.2.9.tar.gz

 

[root@localhost ~]# tar xf httpd-2.2.9.tar.gz
[root@localhost ~]# cd httpd-2.2.9/
[root@localhost httpd-2.2.9]# ./configure --prefix=/usr/local/apache2.2 --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
[root@localhost httpd-2.2.9]# make
[root@localhost httpd-2.2.9]# make install
 
[root@localhost httpd-2.2.9]# echo ‘export PATH=/usr/local/apache2.2/bin:$PATH‘ > /etc/profile.d/apache.sh
[root@localhost httpd-2.2.9]# . /etc/profile.d/apache.sh
[root@localhost httpd-2.2.9]# echo $PATH
/usr/local/apache2.2/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
 
[root@localhost httpd-2.2.9]# httpd
httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1 for ServerName
[root@localhost httpd-2.2.9]# ss -tnl
State       Recv-Q Send-Q            Local Address:Port              Peer Address:Port 
LISTEN      0      128                          :::80                          :::*     
LISTEN      0      3                           ::1:53                          :::*     
LISTEN      0      3                192.168.80.155:53                           *:*     
LISTEN      0      3                 172.18.16.147:53                           *:*     
LISTEN      0      3                    172.16.1.5:53                           *:*     
LISTEN      0      3                     127.0.0.1:53                           *:*     
LISTEN      0      128                          :::22                          :::*     
LISTEN      0      128                           *:22                           *:*     
LISTEN      0      100                         ::1:25                          :::*     
LISTEN      0      100                   127.0.0.1:25                           *:*     
LISTEN      0      128                         ::1:953                         :::*     
LISTEN      0      128                   127.0.0.1:953                          *:*  
[root@localhost httpd-2.2.9]# ls /usr/local/apache2.2/bin/
ab            checkgid      envvars-std   htdigest      httxt2dbm     
apachectl     dbmmanage     htcacheclean  htpasswd      logresolve    
apxs          envvars       htdbm         httpd         rotatelogs 
 
[root@localhost httpd-2.2.9]# httpd -v
Server version: Apache/2.2.9 (Unix)
Server built:   Oct 27 2016 04:29:36
 
设置httpd服务开机自动启动
[root@localhost httpd-2.2.9]# cp /usr/local/apache2.2/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.2.9]# vi /etc/init.d/httpd 
#!/bin/sh
# chkconfig: 2345 10 15
# description: Startup script for the Apache HTTP Server
....
[root@localhost httpd-2.2.9]# chkconfig --add httpd
[root@localhost httpd-2.2.9]# chkconfig --list | grep httpd
httpd          0:off1:off2:on3:on4:on5:on6:off
 
[root@localhost ~]# chkconfig httpd off
[root@localhost ~]# chkconfig --list | grep httpd
httpd          0:off1:off2:off3:off4:off5:off6:off
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# chkconfig --list | grep httpd
httpd          0:off1:off2:on3:on4:on5:on6:off
 
 
注意:如果不添加chkconfig、description两行,出报下面的错误
[root@localhost httpd-2.2.9]# chkconfig --add httpd
service httpd does not support chkconfig
httpd文件添加行:2345是设为要启动的运行级别,10是启动优先级,90是杀死进程的优先级,谁优先谁先挂的意思。


 

技术分享 

 

CentOS 7

软件包:httpd-2.4.18.tar.gz

 

[root@localhost ~]# tar xf package/httpd-2.4.8.tar.gz
 
[root@localhost ~]# cd httpd-2.4.18/
 
[root@localhost httpd-2.4.18]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr --with-apr-util=/usr
 
[root@localhost httpd-2.4.18]# make 
 
[root@localhost httpd-2.4.18]# make install
 
[root@localhost httpd-2.4.18]# echo ‘export PATH=/usr/local/apache2/bin:$PATH‘ > /etc/profile.d/apache.sh
[root@localhost httpd-2.4.18]# cat /etc/profile.d/apache.sh
export PATH=/usr/local/apache2/bin:$PATH
[root@localhost httpd-2.4.18]# . /etc/profile.d/apache.sh 
[root@localhost httpd-2.4.18]# echo $PATH
/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
 
[root@localhost httpd-2.4.18]# apachectl 
 
[root@localhost httpd-2.4.18]# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port  
LISTEN      0      128              *:22                        *:*    
LISTEN      0      100      127.0.0.1:25                          *:*    
LISTEN      0      128             :::80                          :::*  
LISTEN      0      128             :::22                          :::*   
LISTEN      0      100            ::1:25                          :::*  
 
[root@localhost ~]# ls /usr/local/apache2/bin/
ab         checkgid   envvars-std   htdbm     httpd       rotatelogs
apachectl  dbmmanage  fcgistarter   htdigest  httxt2dbm
apxs       envvars    htcacheclean  htpasswd  logresolve
 
[root@localhost ~]# httpd -v
Server version: Apache/2.4.18 (Unix)
Server built:   Oct 28 2016 17:06:21


 

技术分享 

 

设置httpd开机自启动

[root@localhost ~]# cat /lib/systemd/system/http.service 
[Unit]
Description=HTTP Web Server
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl start
ExecReload=/usr/local/apache2/bin/apachectl restart
ExecStop=/usr/local/apache2/bin/apachectl stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
 
[root@localhost ~]# systemctl enable http.service
 
● http.service - HTTP Web Server
   Loaded: loaded (/usr/lib/systemd/system/http.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-10-28 18:42:00 EDT; 1s ago
  Process: 2622 ExecStart=/usr/local/apache2/bin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 2625 (httpd)
   CGroup: /system.slice/http.service
           ├─2625 /usr/local/apache2/bin/httpd -k start
           ├─2626 /usr/local/apache2/bin/httpd -k start
           ├─2627 /usr/local/apache2/bin/httpd -k start
           ├─2628 /usr/local/apache2/bin/httpd -k start
           ├─2629 /usr/local/apache2/bin/httpd -k start
           └─2630 /usr/local/apache2/bin/httpd -k start
 
Oct 28 18:41:59 localhost.localdomain systemd[1]: Starting HTTP Web Server...
Oct 28 18:42:00 localhost.localdomain apachectl[2622]: AH00558: httpd: Could not reli...e
Oct 28 18:42:00 localhost.localdomain systemd[1]: Started HTTP Web Server.
Hint: Some lines were ellipsized, use -l to show in full.
 
[root@localhost ~]# systemctl disable http.service









本文出自 “Linux路上” 博客,请务必保留此出处http://dreamlinuxc.blog.51cto.com/5733156/1868176

Web服务介绍 & httpd安装

标签:yum   web服务   rpm   源码安装   www   

原文地址:http://dreamlinuxc.blog.51cto.com/5733156/1868176

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