Linux下编译安装httpd

本章学习内容

        ———介绍httpd

        ———-rpm和yum不同

        ———-编译安装优势

        ———-编译httpd

1、Apache和http的关系

    http是一款超文本传输协议,早期的Apache团队利用此协议研发了一款web服务软件。后来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>准备开发工具、开发环境和开发库

[root@centos7/media/cdrom/Packages]#yum groupinstall "Development Tools"

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

[root@centos7~]#tar -xf httpd-2.2.29.tar.bz2 
[root@centos7~]#cd httpd-2.2.29/
[root@centos7~/httpd-2.2.29]#du -sh
42M    # 只有42M

    安装之前,可以查看README、INSTALL文档或者通过./configure –help来了解安装过程

    <3>执行.configure脚本,指定特性,检查外部环境,并根据其特性生成特定的makefile文件

[root@centos7~/httpd-2.2.29]#./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
...
[root@centos7~/httpd-2.2.29]#du -sh
44M    # 增大到44M

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

[root@centos7~/httpd-2.2.29]#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[1]: Leaving directory `/root/httpd-2.2.29'
...
[root@centos7~/httpd-2.2.29]#du -sh
74M    # 增大到74M	

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

[root@centos7~/httpd-2.2.29]#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[1]: Leaving directory `/root/httpd-2.2.29'

    <6>启动服务

[root@centos7 bin]# pwd
/usr/local/httpd/bin
[root@centos7 bin]#./apachectl start
# 查看端口
[root@centos7~]#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>测试

# telnet测试服务是否可正常使用
[root@centos6 ~]# telnet 10.1.0.17
Trying 10.1.0.17...
telnet: connect to address 10.1.0.17: No route to host
# 清除防火墙规则
[root@centos7~]#iptables -F
# 连接
[root@centos6 ~]# links 10.1.0.17

wKiom1e9O-KSCkwwAABatwDguuI688.jpg

    配置基本完成,为了以后操作方便,完成下面操作

    <8>二进制文件导入PATH环境变量中

       基于文件的方式实现

[root@centos7~]#vim httpd.sh
#!/bin/bash
PATH=$PATH:/usr/local/httpd/bin
# 重读配置文件
[root@centos7~]#. /etc/profile.d/httpd.sh 
# 查看PATH环境变量
[root@centos7~]#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/httpd2/bin:/root/bin:/usr/local/httpd/bin

    <9>导入库文件

       基于链接的方式实现

[root@centos7~]#vim /etc/ld.so.conf.d/httpd.conf
/usr/local/httpd/lib
# 重读库文件列表
ldcofig -v

    <10>导入头文件

[root@centos7~]#ln -sv /usr/local/httpd/include/ /usr/include/httpd
‘/usr/include/httpd’ -> ‘/usr/local/httpd/include/’

    <11>导入帮助手册

[root@centos7~]#vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/httpd/man
...
# 重读配置文件
[root@centos7~]#. /etc/man_db.conf

    

原创文章,作者:mfwing,如若转载,请注明出处:http://www.178linux.com/40046

赞 (0)
mfwingmfwing
上一篇 2016-08-25 10:09
下一篇 2016-08-25 10:09

相关推荐

  • Linux 第五天: (08月01日) Linux用户组管理

    Linux 第五天: (08月01日) Linux用户组管理         管理员 root,0普通用户 1-65535系统用户 1-499(centos6), 1-999(centos7)登录用户 500(centos6)+, 1000(centos7)+   /etc/passwd 用户及属性/etc/…

    Linux干货 2016-08-08
  • inode、软硬链接区分、ln命令

    inode、软硬链接区分、ln命令 一、inode inode记录的是文件的属性及文件实际放在那块数据块中的。inode包含以下数据: 1. 该文件的可被访问的权限(read/write/excute) 2. 该文件的属主、属组(owner、group) 3. 该文件的大小 4. 该文件创建或者状态改变的时间(Ctim…

    Linux干货 2016-08-02
  • httpd服务——CentOS7

    httpd-2.4 新特性:      (1)MPM支持运行为DSO机制;以模块形式按需加载      (2)event MPM生产环境可用      (3)异步读写机制      (4)支持每个模块…

    Linux干货 2016-10-12
  • N26-博客作业-week3

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 ~]# who | cut -d” ” -f1 | sort -u 2、取出最后登录到当前系统的用户的相关信息。 ~]# last -n 1 3、取出当前系统上被用户当作其默认shell的最多的那个shell。 ~]# cut /etc/pas…

    Linux干货 2017-02-19
  • 学习标准I/O和管道的心得体会

    重定向、标准输出、标准输入、标准错误、管道的命令整理

    2017-11-20
  • Linux学习练习及作业&day07-正则表达式&文本处理工具

    第一部分、使用基本的文本处理工具(非grep)练习以下5题。 1、找出ifconfig命令结果中本机的所有IPv4地址     [root@localhost ~]# ifconfig |head -2 |tail -1     …

    Linux干货 2016-08-08