如何编译安装apache WEB服务

Lamp之-Apache服务生产实战应用指南
Apache是什么?
Apache HTTP SERVER是Apache软件基金会的一个高性能、功能强大,健壮可靠、又很灵活的
开放源代码的web服务软件。
apache对linux的支持相当好。Apache有多种产品,可以支持SSL技术,支持多个虚拟主机。
2.安装Apache。
2.1卸载系统默认的安装Apache软件包。
[zxin10@web ~]$ rpm -qa httpd*
httpd-2.2.15-39.el6.centos.x86_64
httpd-tools-2.2.15-39.el6.centos.x86_64
#卸载
[root@web ~]#  rpm -e --nodeps httpd-2.2.15-39.el6.centos.x86_64
[root@web ~]# rpm -e --nodeps httpd-tools-2.2.15-39.el6.centos.x86_64
#下载镜像
[root@web tools]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.2.34.tar.gz
[root@web tools]# tar zxvf httpd-2.2.34.tar.gz 
#切换到解压后的apache软件包目录
yum install  zlib-devel  -y (也许报错)
#初始化apache安装配置
./configure \
--prefix=/application/apache2.2.34 \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite
编译并安装
make
make install
创建软连接:
[root@c601 httpd-2.2.34]# ln -s /application/apache2.2.34 /application/apache
#到此apache安装完成
[root@c601 tools]# /application/apache/bin/apachectl -l #检查模块
[root@c601 tools]# /application/apache/bin/apachectl -M
#启动apache服务
[root@c601 tools]# /application/apache/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for c601.zte
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@c601 tools]# netstat -lntup|grep 80
tcp        0      0 :::80                       :::*                        LISTEN      27173/httpd         
[root@c601 tools]# lsof -i tcp:80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   27173   root    4u  IPv6  27416      0t0  TCP *:http (LISTEN)
httpd   27175 daemon    4u  IPv6  27416      0t0  TCP *:http (LISTEN)
httpd   27176 daemon    4u  IPv6  27416      0t0  TCP *:http (LISTEN)
httpd   27177 daemon    4u  IPv6  27416      0t0  TCP *:http (LISTEN)
[root@c601 tools]# ps -ef |grep httpd|grep -v grep
root     27173     1  0 19:08 ?        00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon   27174 27173  0 19:08 ?        00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon   27175 27173  0 19:08 ?        00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon   27176 27173  0 19:08 ?        00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon   27177 27173  0 19:08 ?        00:00:00 /application/apache2.2.34/bin/httpd -k start
#测试网站
[root@c601 tools]# curl 192.168.0.252
<html><body><h1>It works!</h1></body></html
#查看错误日志
[root@c601 tools]# tail -200 /application/apache/logs/error_log 
[Sun Jan 28 19:08:30 2018] [notice] Digest: generating secret for digest authentication ...
[Sun Jan 28 19:08:30 2018] [notice] Digest: done
[Sun Jan 28 19:08:30 2018] [notice] Apache/2.2.34 (Unix) DAV/2 configured -- resuming normal operations
[Sun Jan 28 19:10:37 2018] [error] [client 192.168.0.102] File does not exist: /application/apache2.2.34/htdocs/favicon.ico, referer: http://192.168.0.252/


#部署一个简单的网站


#查看站点目录
[root@c601 tools]# grep -i Documentroot /application/apache/conf/httpd.conf 
# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/application/apache2.2.34/htdocs"
# This should be changed to whatever you set DocumentRoot to.
    # access content that does not live under the DocumentRoot.


#"/application/apache2.2.34/htdocs" <--这个是apache的主站点目录
#这里我们进入到/application/apache2.2.34/htdocs下,删除掉apache默认的首页index.html,然后新建立一个index.html,加入
如下网页内容后保存:
<html>
<head><title>baizuo's blog.</title></head>
<body>
HI,I am baizuo,My blog address is 
<a href="http://blog.csdn.net/baizuo_1/">http://http://blog.csdn.net/baizuo_1/</a>
</body>
</html>
#然后在浏览器端浏览网页。


附录:
附录相关安装信息:
[root@c601 tools]# /application/apache/bin/apachectl -V
Server version: Apache/2.2.34 (Unix)
Server built:   Jan 28 2018 18:59:51
Server's Module Magic Number: 20051115:43
Server loaded:  APR 1.5.2, APR-Util 1.5.4
Compiled using: APR 1.5.2, APR-Util 1.5.4
Architecture:   64-bit
Server MPM:     Worker
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/worker"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/application/apache2.2.34"
 -D SUEXEC_BIN="/application/apache2.2.34/bin/suexec"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"


附录:(./configure后参数说明)
--prefix=/application/apache2.2.34 \ 
表示制定apache安装路径为/application/apache2.2.34。如果不指明安装路径。则默认的安装路径为/usr/local/apache2
--enable-deflate \
提供对内容的压缩传输编码支持,一般html,js,css等内容的站点,使用此参数功能会大大提高传输速度,提升访问体验。
在生产环境中,这个是apach调优的一个重要选项之一。
--enable-expires \
激活允许通过文件控制http的expires和cache-control头内容,即对网站图片,js,css等内容,提供在客户端浏览器缓存的设置。
这是apache调优的重要选项之一。
--enable-headers \
提供允许对http请求头的控制。
--enable-modules=most \
--enable-so \
激活apache服务的DSO支持,即在以后可以以DSO的方式编译安装共享模块,这个模块本身不能以DSO方式编译。
--with-mpm=worker \
选择apache mpm模式为worker模式,因worker模式原理更多的使用线程处理请求,所以可以处理更多的开发请求,而系统资源的开销
小于基于进程的MPM prefork。如果不指定此参数,默认的参数为prefork进程模式。这是apache调优的一个重要选项之一。
--enable-rewrite
提供基于URL规则的重写功能,即根据已知URL地址,转成其他想要的URL地址。如前文讲到的伪静态功能就是这个模块实现的。
这个是apache生产环境中必要的一个重要功能。
附录:web服务出现问题时如何排查?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章