zhouu 发表于 2018-11-17 13:03:53

Apache服务简介及编译安装详解

  Apache服务简介及编译安装详解
一、Apache简介
  Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,是目前世界上使用最广泛的一种web server,它以跨平台,高效和稳定而闻名,可以运行在几乎所有广泛使用的计算机平台上。Apache的特点是简单、速度快、性能稳定,并可做代理服务器来使用。
  Apache是用C语言开发的基于模块化设计的web应用,总体上看起来代码的可读性高于php代码,它的核心代码并不多,大多数的功能都被分割到各种模块中,各个模块在系统启动时按需载入。
  支持SSL技术,支持多个虚拟主机。Apache是以进程的Prefork模式(还有基于线程的Worker模式)为基础的结构,进程要比线程消耗更多的系统开支,不太适合于多处理器环境,因此,在一个Apache Web站点扩容时,通常是增加服务器或扩充群集节点而不是增加处理器。

二、Apache 的特性
  Apacheweb服务器软件拥有以下特性:
  1.支持最新的HTTP/1.1通信协议
  2.拥有简单而强有力的基于文件的配置过程
  3.支持通用网关接口
  4.支持基于IP和基于域名的虚拟主机
  5.支持多种方式的HTTP认证
  6.集成Perl处理模块
  7.集成代理服务器模块
  8.支持实时监视服务器状态和定制服务器日志
  9.支持服务器端包含指令(SSI)
  10.支持安全Socket层(SSL)
  11.提供用户会话过程的跟踪
  12.支持FastCGI
  13.通过第三方模块可以支持JavaServlets
三、编译安装Apache步骤及参数详解
  源码的编译安装一般由3个步骤组成:
  配置(configure),通常依赖gcc编译器,binutils,glibc。配置软件特性,检查编译环境,生成 Makefile文件
  编译(make)
  安装(make install)
  apr和apr-utils下载地址:http://apr.apache.org/download.cgi
  PCRE下载地址:http://sourceforge.net/projects/pcre/files/pcre/8.32/
  #yum -y install gcc
   wgethttp://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  tar xf httpd-2.4. 7.tar.gz
  # cd httpd-2.4.7
  # ./configure \
  > --prefix=/usr/local/apache \       指定安装目录
  > --with-apr=/usr/local/apr \   指定依赖文件的安装目录
  > --with-apr-util=/usr/local/apr-util \ 指定依赖文件的安装目录
  > --enable-deflate \               压缩文本文件提高速度节约带宽
  > --enable-expires \               让浏览器缓存,减轻服务器压力,提高访问速度
  > --enable-headers \            激活http头
  > --enable-modules=most \         激活大多数模块
  > --enable-so \                  让apache核心装载DSO,但是不实际编译任何动态模块;
  > --with-mpm=worker \            让Apache工作在worker模式下
  > --enable-rewrite               激活伪静态功能
  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-unknown-linux-gnu
  checking host system type... x86_64-unknown-linux-gnu
  checking target system type... x86_64-unknown-linux-gnu
  configure:
  configure: Configuring Apache Portable Runtime library...
  configure:
  checking for APR... no
  configure: error: APR not found.Please read the documentation. 这里出现报错
  # tar xf apr-1.4.6.tar.gz    解压并安装依赖包
  #cd /apr-1.4.6
  # ./configure
  # make && make install
  # cd ..
  # tar xf apr-util-1.4.1   解压并安装工具组件依赖包
  # cd apr-util-1.4.1
  # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  # make && make install
  # tar xf pcre-8.34.tar.gz   解压并安装这个正则表达式函数库依赖包
  # cd pcre-8.34
  # ./configure
  checking for a BSD-compatible install... /usr/bin/install -c
  checking whether build environment is sane... yes
  checking for a thread-safe mkdir -p... /bin/mkdir -p
  ………………………………………………………省略若干
  checking for dirent.h... yes
  checking windows.h usability... no
  checking windows.h presence... no
  checking for windows.h... no
  configure: error: You need a C++ compiler for C++ support.   这里报错需要安装gcc-c++软件
  # yum -y install gcc-c++
  # ./configure
  # make && make install
  ……………………………………………………………….省略若干
  ln -sf pcre_version.3            /usr/local/share/man/man3/pcre32_version.3
  make: Leaving directory `/root/pcre-8.34'
  make: Leaving directory `/root/pcre-8.34'
  make: Leaving directory `/root/pcre-8.34'出现这些证明编译安装完成
  # tar xf zlib-1.2.3.tar.gz    安装依赖的库文件或者yum安装zlib zlib-devel
  # cd zlib-1.2.3
  # ./configure
  Checking for gcc...
  Building static library libz.a version 1.2.3 with gcc.
  Checking for unistd.h... Yes.
  Checking whether to use vsprintf() or sprintf()... using vsprintf()
  Checking for vsnprintf() in stdio.h... Yes.
  Checking for return value of vsnprintf()... Yes.
  Checking for errno.h... Yes.
  Checking for mmap support... Yes.
  # vim Makefile
  把第21行左右的CFLAGS=-O3 -DUSE_MMAP修改成CFLAGS=-O3 -DUSE_MMAP -fPIC
  或使用sed -i ‘s/CFLAGS=-O3 -DUSE_MMAP/CFLAGS=-O3 -DUSE_MMAP -fPIC/g’ Makefile
  注意:上面这个如果不修改安装httpd软件时就会报以下错误:
  collect2: ld returned 1 exit status
  make: *** 错误 1
  make: Leaving directory `/root/httpd/httpd-2.4.7/modules/filters'
  make: *** 错误 1
  make: Leaving directory `/root/httpd/httpd-2.4.7/modules/filters'
  make: *** 错误 1
  make: Leaving directory `/root/httpd/httpd-2.4.7/modules'
  make: *** 错误 1
  make: Leaving directory `/root/httpd/httpd-2.4.7'
  make: *** 错误 1
  # make && make install
  # cd ..
  # cd httpd-2.4.7
  # ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so--with-mpm=worker --enable-rewrite
  #make && make install
  # /usr/local/apache2/bin/apachectl start   启动Apache
  到这里Apache就已经安装完成了。
  # /usr/local/apache2/bin/apachectl -l可以查看安装的模块
  # /usr/local/apache2/bin/apachectl -t检查配置文件语法是否有误
四、创建httpd启动脚本并设置开机自启
1、复制Apache的启动文件到/etc/init.d下面并改名
  # cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
2、修改复制的启动文件
  # vim /etc/init.d/httpd
  #!/bin/bash    这行下面增加两行文字
  # chkconfig: 35 70 30
  #35指的是在3和5级别开启该服务   70:指的是开机启动服务在70位,30指的是关机关闭服务在30位,一般启动服务的顺序和关闭顺序的和100。
  # description: Apache   描述信息,这里的#不再试注释符
3、设置开机自启动
  # chkconfig --add httpd
  # chmod +x /etc/init.d/httpd
  # chkconfig httpd on
  # systemctl restart httpd
4、启动Apache时常见错误解决方法
(1)常见错误1
  有时候Apache启动时会报以下错误:
  # /usr/local/apache2/bin/apachectl start

  AH00558: httpd: Could not>  解决方法,在配置文件中添加服务器主机名即可:
  # vim /usr/local/apache2/conf/httpd.conf
  ServerName localhost:80
(2)常见错误2
  修改Apache相关配置文件出现以下错误
  # systemctl start httpd
  Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
  解决方法:
  出现以上错误原因大多是因为修改Apache相关配置文件时出现语法错误(例如:多了或少了空格,少写或错写标点符号);也有可能是修改了相关的目录路径,结果没有创建相关目录导致出现错误;还有可能是防火墙和selinux等相关的权限问题导致。具体报错原因可以使用”systemctl status httpd.service”或”journalctl –xe”命令进行查看。

king-baron 发表于 2018-11-17 14:16:23

很详细,不过小弟还是不知道怎么表达
页: [1]
查看完整版本: Apache服务简介及编译安装详解