32ijhgf 发表于 2016-8-25 10:29:08

Linux下编译安装httpd

                      本章学习内容      ---------介绍httpd      ----------rpm和yum不同      ----------编译安装优势      ----------编译httpd
1、Apache和http的关系

    http是一款超文本传输协议,早期的Apache团队利用此协议研发了一款web服务软件,叫做http。后来通过bug的修复和功能的完善,在http的基础上开发了另外一款软件,称为A Patchy Server,简称Apache,与Apache组织正好重名。后来Apache团队逐渐强大,最终成为一个开源软件基金会(ASF),http也不再是其唯一维护的一款软件,再将这款服务软件称为Apache显然不合适,所以我们可以称其为httpd。不过有时候因为历史的原因,我们还是会将Apache作为一款Web服务软件来称呼,而其We服务规范也成为业界的标准。
下面的过程为了更加严谨,我们使用httpd来描述这款软件。
2、介绍rpm包和源码安装的区别
    rpm包是将源码编译好的软件包,只要安装既可以提供服务,而源码包是最底层的代码,如果要使用,还要经过编译,显然不如rpm包方便,但是俩者各有优势,生产生活中,源码编译安装居多,如果要是练习使用的话,rpm包安装居多。
3、编译安装的优势
    <1>自定义软件功能
    <2>优化编译参数,提高性能
    <3>解决不必要的软件间依赖
    <4>方便清理与卸载
4、编译安装httpd-2.2.29
    <1>准备开发工具、开发环境和开发库

1
#yum groupinstall "Development Tools"




    <2>准备源码并解压缩至某目录

1
2
3
4
#tar -xf httpd-2.2.29.tar.bz2
#cd httpd-2.2.29/
#du -sh
42M    # 只有42M




    安装之前,可以查看README、INSTALL文档或者通过./configure --help来了解安装过程
    <3>执行.configure脚本,指定特性,检查外部环境,并根据其特性生成特定的makefile文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd
checking for killpg... yes
checking bstring.h usability... no
checking bstring.h presence... no
checking for bstring.h... no
checking for unistd.h... (cached) yes
checking for syslog... yes
checking sys/times.h usability... yes
checking sys/times.h presence... yes
checking for sys/times.h... yes
creating test/Makefile
...
#du -sh
44M    # 增大到44M




    <4>make工具编译,将.c源码根据makefile文件编译成应用程序

1
2
3
4
5
6
#make
bmod_status.la modules/generators/libmod_autoindex.la modules/generators/libmod_asis.la modules/generators/libmod_cgi.la modules/mappers/libmod_negotiation.la modules/mappers/libmod_dir.la modules/mappers/libmod_actions.la modules/mappers/libmod_userdir.la modules/mappers/libmod_alias.la modules/mappers/libmod_so.la server/mpm/prefork/libprefork.la os/unix/libos.la -lm /root/httpd-2.2.29/srclib/pcre/libpcre.la /root/httpd-2.2.29/srclib/apr-util/libaprutil-1.la /root/httpd-2.2.29/srclib/apr-util/xml/expat/libexpat.la /root/httpd-2.2.29/srclib/apr/libapr-1.la -lrt -lcrypt -lpthread -ldl
make: Leaving directory `/root/httpd-2.2.29'
...
#du -sh
74M    # 增大到74M   




    <5>make install,创建目录并复制文件

1
2
3
4
5
6
7
#make install
...
mkdir /usr/local/httpd/man
mkdir /usr/local/httpd/man/man1
mkdir /usr/local/httpd/man/man8
mkdir /usr/local/httpd/manual
make: Leaving directory `/root/httpd-2.2.29'




    <6>启动服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# pwd
/usr/local/httpd/bin
#./apachectl start
# 查看端口
#netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address         Foreign Address         State       PID/Program name   
tcp      0      0 192.168.122.1:53      0.0.0.0:*               LISTEN      2021/dnsmasq      
tcp      0      0 0.0.0.0:22            0.0.0.0:*               LISTEN      1577/sshd         
tcp      0      0 127.0.0.1:631         0.0.0.0:*               LISTEN      1575/cupsd         
tcp      0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1974/master         
tcp6       0      0 :::80                   :::*                  LISTEN      74875/httpd         
tcp6       0      0 :::22                   :::*                  LISTEN      1577/sshd         
tcp6       0      0 ::1:631               :::*                  LISTEN      1575/cupsd         
tcp6       0      0 ::1:25                  :::*                  LISTEN      1974/master




    <7>测试

1
2
3
4
5
6
7
8
# telnet测试服务是否可正常使用
# telnet 10.1.0.17
Trying 10.1.0.17...
telnet: connect to address 10.1.0.17: No route to host
# 清除防火墙规则
#iptables -F
# 连接
# links 10.1.0.17





    配置基本完成,为了以后操作方便,完成下面操作
    <8>二进制文件导入PATH环境变量中       基于文件的方式实现
1
2
3
4
5
6
7
8
#vim httpd.sh
#!/bin/bash
PATH=$PATH:/usr/local/httpd/bin
# 重读配置文件
#. /etc/profile.d/httpd.sh
# 查看PATH环境变量
#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/httpd2/bin:/root/bin:/usr/local/httpd/bin




    <9>导入库文件
       基于链接的方式实现

1
2
3
4
#vim /etc/ld.so.conf.d/httpd.conf
/usr/local/httpd/lib
# 重读库文件列表
ldcofig -v




    <10>导入头文件

1
2
#ln -sv /usr/local/httpd/include/ /usr/include/httpd
‘/usr/include/httpd’ -> ‘/usr/local/httpd/include/’




    <11>导入帮助手册

1
2
3
4
5
#vim /etc/man_db.conf
MANDATORY_MANPATH                     /usr/local/httpd/man
...
# 重读配置文件
#. /etc/man_db.conf





                   

页: [1]
查看完整版本: Linux下编译安装httpd