CentOS 6.5使用源码编译安装httpd服务

版权声明:转载或者应用请注明出处 https://blog.csdn.net/qq_35180983/article/details/82466999

httpd是一个开源软件,且一般用作web服务器来使用。目前最流行的web服务器软件叫做httpd, 在早期的http server就叫做apache,到了http server 2.0以后就改名为httpd了。 所以有时候听到apache服务器和httpd服务器其实都是指得是一个意思。

1、Apache的特点

功能强大、配置简单、速度快、应用广泛、性能稳定可靠,并可做代理服务器或负载均衡来使用,

运用:

  • 使用Apache运行静态HTML网页、图片(处理静态小文件能力不及Nginx)。
  • 使用Apache结合PHP引擎运行PHP、Perl、Python等程序
  • 使用Apache结合Tomcat/Resion运行JSP,JAVA等程序
  • 使用Apache作代理、负载均衡、rewrite规则过滤等等。

2、安装开发包组

[root@hadoop01]#yum groupinstall "development tools"
[root@hadoop01]#yum install openssl-devel pcre-devel expat-devel

 安装需要的工具

yum install gcc

注意:安装前检查是否已经存在httpd、如果已经存在先卸载(使用rpm -e  --nodeps)

[root@httpd /]# rpm -qa httpd
rpm -e --nodeps 加 rpm -qa httpd 查看到的包名
rpm命令-qa参数
-q 查询的意思
-a 所有软件包
-e 移除的意思
--nodeps 不做软件间的依赖检查
更过参数使用man rpm 或 rpm --help查看

3、安装Apache

下载httpd软件包:wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.34.tar.gz,如下,下载完成:

[root@hadoop01 local]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.34.tar.gz
--2018-09-06 19:49:13--  http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.34.tar.gz
Resolving mirror.bit.edu.cn... 202.204.80.77, 2001:da8:204:2001:250:56ff:fea1:22
Connecting to mirror.bit.edu.cn|202.204.80.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9098780 (8.7M) [application/octet-stream]
Saving to: “httpd-2.4.34.tar.gz”

100%[======================================>] 9,098,780    188K/s   in 53s     

2018-09-06 19:50:06 (168 KB/s) - “httpd-2.4.34.tar.gz” saved [9098780/9098780]

解压,测试安装环境并编译安装:

解压:tar zxvf httpd-2.4.34.tar.gz 

然后进入加压后的目录:cd httpd-2.4.34,我们遇到不熟悉的软件是可参考这两个文件:README   INSTALL

[root@hadoop01 httpd-2.4.34]# ls
ABOUT_APACHE     CHANGES         httpd.dsp       LICENSE           ROADMAP
acinclude.m4     CMakeLists.txt  httpd.mak       Makefile.in       server
Apache-apr2.dsw  config.layout   httpd.spec      Makefile.win      srclib
Apache.dsw       config.log      include         modules           support
apache_probes.d  config.nice     INSTALL         NOTICE            test
ap.d             configure       InstallBin.dsp  NWGNUmakefile     VERSIONING
build            configure.in    LAYOUT          os
BuildAll.dsp     docs            libhttpd.dep    README
BuildBin.dsp     emacs-style     libhttpd.dsp    README.cmake
buildconf        httpd.dep       libhttpd.mak    README.platforms
[root@hadoop01 httpd-2.4.34]# more README

                          Apache HTTP Server

  What is it?
  -----------

  The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
  web server.  Originally designed as a replacement for the NCSA HTTP
  Server, it has grown to be the most popular web server on the
  Internet.  As a project of the Apache Software Foundation, the
  developers aim to collaboratively develop and maintain a robust,
  commercial-grade, standards-based server with freely available
  source code.

  The Latest Version
  ------------------

  Details of the latest version can be found on the Apache HTTP
  server project page under http://httpd.apache.org/.

  Documentation
  -------------

  The documentation available as of the date of this release is
  included in HTML format in the docs/manual/ directory.  The most
  up-to-date documentation can be found at
  http://httpd.apache.org/docs/2.4/.

  Installation
  ------------

  Please see the file called INSTALL.  Platform specific notes can be
  found in README.platforms.

  Licensing
  ---------

  Please see the file called LICENSE.

  Cryptographic Software Notice
  -----------------------------

  This distribution may include software that has been designed for use
  with cryptographic software.  The country in which you currently reside
  may have restrictions on the import, possession, use, and/or re-export
  to another country, of encryption software.  BEFORE using any encryption
  software, please check your country's laws, regulations and policies
  concerning the import, possession, or use, and re-export of encryption
  software, to see if this is permitted.  See <http://www.wassenaar.org/>
  for more information.

  The U.S. Government Department of Commerce, Bureau of Industry and
  Security (BIS), has classified this software as Export Commodity 
  Control Number (ECCN) 5D002.C.1, which includes information security
  software using or performing cryptographic functions with asymmetric
  algorithms.  The form and manner of this Apache Software Foundation
  distribution makes it eligible for export under the License Exception
  ENC Technology Software Unrestricted (TSU) exception (see the BIS 
  Export Administration Regulations, Section 740.13) for both object 
  code and source code.

  The following provides more details on the included files that
  may be subject to export controls on cryptographic software:

    Apache httpd 2.0 and later versions include the mod_ssl module under
       modules/ssl/
    for configuring and listening to connections over SSL encrypted
    network sockets by performing calls to a general-purpose encryption
    library, such as OpenSSL or the operating system's platform-specific
    SSL facilities.

    In addition, some versions of apr-util provide an abstract interface
    for symmetrical cryptographic functions that make use of a
    general-purpose encryption library, such as OpenSSL, NSS, or the
    operating system's platform-specific facilities. This interface is
    known as the apr_crypto interface, with implementation beneath the
    /crypto directory. The apr_crypto interface is used by the
    mod_session_crypto module available under
      modules/session
    for optional encryption of session information.

    Some object code distributions of Apache httpd, indicated with the
    word "crypto" in the package name, may include object code for the
    OpenSSL encryption library as distributed in open source form from
    <http://www.openssl.org/source/>.

  The above files are optional and may be removed if the cryptographic
  functionality is not desired or needs to be excluded from redistribution.
  Distribution packages of Apache httpd that include the word "nossl"
  in the package name have been created without the above files and are
  therefore not subject to this notice.

  Contacts
  --------

     o If you want to be informed about new code releases, bug fixes,
       security fixes, general news and information about the Apache server
       subscribe to the apache-announce mailing list as described under
       <http://httpd.apache.org/lists.html#http-announce>

     o If you want freely available support for running Apache please see the
       resources at <http://httpd.apache.org/support.html>

     o If you have a concrete bug report for Apache please see the instructions
       for bug reporting at <http://httpd.apache.org/bug_report.html>

     o If you want to participate in actively developing Apache please
       subscribe to the `[email protected]' mailing list as described at
       <http://httpd.apache.org/lists.html#http-dev>

[root@hadoop01 httpd-2.4.34]# more INSTALL 

  APACHE INSTALLATION OVERVIEW

  Quick Start - Unix
  ------------------

  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html

     $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start

     NOTES: * Replace PREFIX with the filesystem path under which 
              Apache should be installed.  A typical installation
              might use "/usr/local/apache2" for PREFIX (without the
              quotes).

            * Consider if you want to use a previously installed APR and
              APR-Util (such as those provided with many OSes) or if you
              need to use the APR and APR-Util from the apr.apache.org
              project. If the latter, download the latest versions and
              unpack them to ./srclib/apr and ./srclib/apr-util (no
              version numbers in the directory names) and use
              ./configure's --with-included-apr option. This is required
              if you don't have the compiler which the system APR was
              built with.  It can also be advantageous if you are a
              developer who will be linking your code with Apache or using
              a debugger to step through server code, as it removes the
              possibility of version or compile-option mismatches with APR
              and APR-Util code. As a convenience, prepackaged source-code
              bundles of APR and APR-Util are occasionally also provided
              as a httpd-2.X.X-deps.tar.gz download.

            * If you are a developer building Apache directly from
              Subversion, you will need to run ./buildconf before running
              configure. This script bootstraps the build environment and
              requires Python as well as GNU autoconf and libtool. If you
              build Apache from a release tarball, you don't have to run
              buildconf.

            * If you want to build a threaded MPM (for instance worker)
              on  FreeBSD, be aware that threads do not work well with
              Apache on FreeBSD versions before 5.4-RELEASE. If you wish
              to try a threaded Apache on an earlier version of FreeBSD,
              use the --enable-threads parameter to ./configure in
              addition to the --with-mpm parameter.

            * If you are building directly from Subversion on Mac OS X
              (Darwin), make sure to use GNU Libtool 1.4.2 or newer. All
              recent versions of the developer tools on this platform
              include a sufficiently recent version of GNU Libtool (named
              glibtool, but buildconf knows where to find it).

  For a short impression of what possibilities you have, here is a
  typical example which configures Apache for the installation tree
  /sw/pkg/apache with a particular compiler and flags plus the two
  additional modules mod_rewrite and mod_speling for later loading
  through the DSO mechanism:

     $ CC="pgcc" CFLAGS="-O2" \
     ./configure --prefix=/sw/pkg/apache \
     --enable-rewrite=shared \
     --enable-speling=shared 

  The easiest way to find all of the configuration flags for Apache 2.4
  is to run ./configure --help.


  Quick Start - Windows
  ---------------------

  For complete documentation, see manual/platform/windows.html.en or
  <http://httpd.apache.org/docs/2.4/platform/windows.html>


  Postscript
  ----------

  To obtain help with installation problems, please see the resources at
  <http://httpd.apache.org/support.html>

  Thanks for using the Apache HTTP Server, version 2.4.

                                     The Apache Software Foundation
                                     http://www.apache.org/

测试安装环境: ./configure

[root@hadoop01 httpd-2.4.34]# ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.

这里报错,缺少apr,下载apr及apr-util:

apr是Apache Portable Runtime的缩写,中文译为Apache可移植运行环境,是httpd所必须的,apr-util同理。

apr及apr-util下载地址:http://apr.apache.org/download.cgi

[root@hadoop01 local]# wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz
[root@hadoop01 local]# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
[root@hadoop01 local]# tar -zxvf apr-1.6.3.tar.gz
[root@hadoop01 local]# tar -zxvf apr-util-1.6.1.tar.gz

然后对apr进行安装:

[root@hadoop01 apr-1.6.3]# cd apr-1.6.3 
[root@hadoop01 apr-1.6.3]# ./configure
[root@hadoop01 apr-1.6.3]# make && make install

 然后对apr-util进行安装:

[root@hadoop01 local]# cd apr-util-1.6.1
[root@hadoop01 apr-util-1.6.1]# ./configure --with-apr=/usr/local/apr/
[root@hadoop01 apr-util-1.6.1]# make && make install

 重新安装httpd服务:

[root@hadoop01 local]# cd httpd-2.4.34
[root@hadoop01 httpd-2.4.34]# ./configure 
[root@hadoop01 httpd-2.4.34]# make && make install

稍等片刻后,安装成功:

做软连接:

[root@hadoop01 apache2]#  ln -s /usr/local/apache2/bin/* /usr/local/bin/

 检查:

[root@hadoop01 apache2]# apachectl -t
AH00557: httpd: apr_sockaddr_info_get() failed for httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@hadoop01 apache2]# cd ./conf/
[root@hadoop01 conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@hadoop01 conf]# pwd
/usr/local/apache2/conf

在这里修改配置一下文件
[root@hadoop01 conf]# vim httpd.conf
修改:
ServerName www.httpd.com:80
保存退出

[root@hadoop01 conf]# apachectl -t
Syntax OK

然后启动:apachectl start,出现如下问题:

[root@hadoop01 conf]# apachectl start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

说明80端口被占用:

[root@hadoop01 conf]# netstat -lnp|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3624/nginx          
unix  2      [ ACC ]     STREAM     LISTENING     22183  2809/nautilus       /tmp/orbit-brz/linc-af9-0-20431005da76d
unix  2      [ ACC ]     STREAM     LISTENING     18180  2504/Xorg           @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     20735  2804/gconf-helper   /tmp/orbit-brz/linc-af4-0-7e6a0173cda7a

ps -ef|grep httpd,或者用netstat -lnp|grep 80察看占用的进程,可以发现nginx占用着80端口,关闭其或者杀掉这个进程

[root@hadoop01 sbin]# netstat -lnp|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4024/nginx          
unix  2      [ ACC ]     STREAM     LISTENING     22183  2809/nautilus       /tmp/orbit-brz/linc-af9-0-20431005da76d
unix  2      [ ACC ]     STREAM     LISTENING     18180  2504/Xorg           @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     20735  2804/gconf-helper   /tmp/orbit-brz/linc-af4-0-7e6a0173cda7a
[root@hadoop01 sbin]# kill -9 4024
[root@hadoop01 sbin]# netstat -lnp|grep 80
unix  2      [ ACC ]     STREAM     LISTENING     22183  2809/nautilus       /tmp/orbit-brz/linc-af9-0-20431005da76d
unix  2      [ ACC ]     STREAM     LISTENING     18180  2504/Xorg           @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     20735  2804/gconf-helper   /tmp/orbit-brz/linc-af4-0-7e6a0173cda7a
[root@hadoop01 sbin]# apachectl start
[root@hadoop01 sbin]# lsof -i :80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   67656   root    4u  IPv6 257638      0t0  TCP *:http (LISTEN)
httpd   67657 daemon    4u  IPv6 257638      0t0  TCP *:http (LISTEN)
httpd   67658 daemon    4u  IPv6 257638      0t0  TCP *:http (LISTEN)
httpd   67659 daemon    4u  IPv6 257638      0t0  TCP *:http (LISTEN)
[root@hadoop01 sbin]# ps -ef | grep httpd
root      67656      1  0 23:02 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    67657  67656  0 23:02 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    67658  67656  0 23:02 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    67659  67656  0 23:02 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
root      67772  67293  0 23:04 pts/4    00:00:00 grep httpd
[root@hadoop01 sbin]# 

 最后,查看防火墙状态,如果没有关闭,关闭防火墙

[root@hadoop01 sbin]# service iptables status 
iptables: Firewall is not running.

service iptables status : 查看防火墙的状态
service iptables start : 启动防火墙
service iptables stop : 停止防火墙

chkconfig iptables off :开机不加载防火墙
chkconfig iptables --level 35 on  : 以35级别启动服务器开启防火墙

猜你喜欢

转载自blog.csdn.net/qq_35180983/article/details/82466999