设为首页 收藏本站
查看: 678|回复: 1

[经验分享] Apache服务简介及编译安装详解

[复制链接]

尚未签到

发表于 2018-11-17 13:03:53 | 显示全部楼层 |阅读模式
  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/
  [root@centos4 ~]#yum -y install gcc
  [root@centos1 ~] wget  http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  [root@centos1 ~]tar xf httpd-2.4. 7.tar.gz
  [root@centos1 ~]# cd httpd-2.4.7
  [root@centos1 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. 这里出现报错
  [root@centos4 ~]# tar xf apr-1.4.6.tar.gz    解压并安装依赖包
  [root@centos4 ~]#cd /apr-1.4.6
  [root@centos4 apr-1.4.6]# ./configure
  [root@centos4 apr-1.4.6]# make && make install
  [root@centos4 apr-1.4.6]# cd ..
  [root@centos4 ~]# tar xf apr-util-1.4.1     解压并安装工具组件依赖包
  [root@centos4 ~]# cd apr-util-1.4.1
  [root@centos4 apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  [root@centos4 apr-util-1.4.1]# make && make install
  [root@centos4 ~]# tar xf pcre-8.34.tar.gz   解压并安装这个正则表达式函数库依赖包
  [root@centos4 ~]# cd pcre-8.34
  [root@centos4 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++软件
  [root@centos4 pcre-8.34]# yum -y install gcc-c++
  [root@centos4 pcre-8.34]# ./configure
  [root@centos4 pcre-8.34]# make && make install
  ……………………………………………………………….省略若干
  ln -sf pcre_version.3            /usr/local/share/man/man3/pcre32_version.3
  make[3]: Leaving directory `/root/pcre-8.34'
  make[2]: Leaving directory `/root/pcre-8.34'
  make[1]: Leaving directory `/root/pcre-8.34'  出现这些证明编译安装完成
  [root@centos4 ~]# tar xf zlib-1.2.3.tar.gz    安装依赖的库文件或者yum安装zlib zlib-devel
  [root@centos4 ~]# cd zlib-1.2.3
  [root@centos4 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 vs[n]printf() or s[n]printf()... using vs[n]printf()
  Checking for vsnprintf() in stdio.h... Yes.
  Checking for return value of vsnprintf()... Yes.
  Checking for errno.h... Yes.
  Checking for mmap support... Yes.
  [root@centos4 zlib-1.2.3]# 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[4]: *** [mod_deflate.la] 错误 1
  make[4]: Leaving directory `/root/httpd/httpd-2.4.7/modules/filters'
  make[3]: *** [shared-build-recursive] 错误 1
  make[3]: Leaving directory `/root/httpd/httpd-2.4.7/modules/filters'
  make[2]: *** [shared-build-recursive] 错误 1
  make[2]: Leaving directory `/root/httpd/httpd-2.4.7/modules'
  make[1]: *** [shared-build-recursive] 错误 1
  make[1]: Leaving directory `/root/httpd/httpd-2.4.7'
  make: *** [all-recursive] 错误 1
  [root@centos4 zlib-1.2.3]# make && make install
  [root@centos4 zlib-1.2.3]# cd ..
  [root@centos4 ~]# cd httpd-2.4.7
  [root@centos4 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
  [root@centos4 httpd-2.4.7]#make && make install
  [root@centos4 httpd-2.4.7]# /usr/local/apache2/bin/apachectl start   启动Apache
  到这里Apache就已经安装完成了。
  [root@centos4 httpd-2.4.7]# /usr/local/apache2/bin/apachectl -l  可以查看安装的模块
  [root@centos4 httpd-2.4.7]# /usr/local/apache2/bin/apachectl -t  检查配置文件语法是否有误
四、创建httpd启动脚本并设置开机自启
1、复制Apache的启动文件到/etc/init.d下面并改名
  [root@centos4 ~]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
2、修改复制的启动文件
  [root@centos4 ~]# vim /etc/init.d/httpd
  #!/bin/bash    这行下面增加两行文字
  # chkconfig: 35 70 30
  #35指的是在3和5级别开启该服务   70:指的是开机启动服务在70位,30指的是关机关闭服务在30位,一般启动服务的顺序和关闭顺序的和100。
  # description: Apache   描述信息,这里的#不再试注释符
3、设置开机自启动
  [root@centos4 ~]# chkconfig --add httpd
  [root@centos4 ~]# chmod +x /etc/init.d/httpd
  [root@centos4 ~]# chkconfig httpd on
  [root@centos4 ~]# systemctl restart httpd
4、启动Apache时常见错误解决方法
(1)常见错误1
  有时候Apache启动时会报以下错误:
  [root@centos4 ~]# /usr/local/apache2/bin/apachectl start

  AH00558: httpd: Could not>  解决方法,在配置文件中添加服务器主机名即可:
  [root@centos4 ~]# vim /usr/local/apache2/conf/httpd.conf
  ServerName localhost:80
(2)常见错误2
  修改Apache相关配置文件出现以下错误
  [root@centos4 ~]# 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”命令进行查看。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-636254-1-1.html 上篇帖子: APACHE 2.2.15+TOMCAT6.0.26配置负载均衡 下篇帖子: apache 对目录下的文件开启文本浏览模式

尚未签到

发表于 2018-11-17 14:16:23 | 显示全部楼层
很详细,不过小弟还是不知道怎么表达

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表