Chinaunix首页 | 论坛 | 博客
  • 博客访问: 623722
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-08-18 22:09:21

httpd-2.4.16需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包,因为系统中原来就装的有,直接升级可能又会覆盖依赖关系,所以,这次选择使用编译源代码的方式进行
APR下载地址: /> 编译安装httpd需要用到这几个包,可以到各自的官网上下载
[root@www lamp]# ll
-rw-r--r-- 1 root root 1031613 Aug 18 01:30 apr-1.5.2.tar.gz
-rw-r--r-- 1 root root  874044 Aug 17 06:19 apr-util-1.5.4.tar.gz
-rw-r--r-- 1 root root 6899517 Aug 17 06:35 httpd-2.4.16.tar.gz
-rw-r--r-- 1 root root  571091 Aug 17 06:48 zlib-1.2.8.tar.gz
注意:安装时先date看一下系统时间确保系统时间要大于等于安装包的发布日期日期,否则在过去的时间去安装一个未来的包会报错。同步时间命令:hwclock -s
1.  编译安装apr
[root@www lamp]# tar xzf apr-1.5.2.tar.gz
[root@www lamp]# cd apr-1.5.2
[root@www apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@www apr-1.5.2]# make
[root@www apr-1.5.2]#mkdir /root/lamp/makelog
[root@www apr-1.5.2]# make install > /root/lamp/makelog/apr.install.log
(为了应对现安装错误,所以创建一个安装日志目录记录各个软件的安装信息)
2.  编译安装apr-util(先是apr然后是apr-util,因为apr-util依赖于apr)
[root@www lamp]# tar xzf apr-util-1.5.4.tar.gz 
[root@www lamp]# cd apr-util-1.5.4
[root@www apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  (一定要指定apr的安装位置)
[root@www apr-util-1.5.4]# make
[root@www apr-util-1.5.4]# make install > /root/lamp/makelog/apr-util.install.log  
3.  编译安装pcre(因为httpd依赖于pcre库,所以要先安装pcre)
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库,是一个用C语言编写的正则表达式函数库广泛使用在许多开源软件之中,
最著名的莫过于Apache HTTP服务器和PHP脚本语言、R脚本语言;
直接安装perc-devel即可
[root@www lamp]# yum list all | grep pcre
pcre.i686                               7.8-6.el6                        @anaconda-CentOS-201311271240.i386/6.5
pcre.i686                               7.8-7.el6                        base   
pcre-devel.i686                         7.8-7.el6                        base   
pcre-static.i686                        7.8-7.el6                        base   
[root@www lamp]# yum install pcre-devel.i686 
4.  编译安装zlib
一般系统默认安装的都有:
[root@www pcre2-10.10]# rpm -q zlib
zlib-1.2.3-29.el6.i686
如没有还要安装,此次重新编译安装
[root@www lamp]# tar xzf zlib-1.2.8.tar.gz 
[root@www lamp]# cd zlib-1.2.8
[root@www zlib-1.2.8]# ./configure #直接装即可
[root@www zlib-1.2.8]# make
[root@www zlib-1.2.8]# make install > /root/lamp/makelog/zlib.install.log
5.  编译安装httpd
[root@www lamp]# tar xzf httpd-2.4.16.tar.gz 
[root@www lamp]# cd httpd-2.4.16
[root@www httpd-2.4.16]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite  --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
其中:
--prefix=/usr/local/apache 指定安装路径
--sysconfdir=/etc/httpd 指定Apache的配置文件的目录
--enable-so 启用动态共享模块
--enable-rewrite 支持URL重写
--enable-ssl 支持SSL功能
--enable-cgi 支持CGI
--enable-cgid 支持线程方式的MPM,用worker和event需开启此项
--enable-modules=most 支持模块化
--enable-mods-shared=most 启用共享模块
--enable-mpms-shared=all 共享启用哪些MPM
--with-apr=/usr/local/apr 指定APR的安装位置
--with-apr-util=/usr/local/apr-util 指定apr-util的安装位置
--enable-proxy-fcgi 支持fast-cgi模式
具体的可以用./configure --help查看更多的内容
[root@www httpd-2.4.16]# make
[root@www httpd-2.4.16]# make install > /root/lamp/makelog/apache.log
注意:httpd服务受SElinux限制,如果无法启动清闲确保SElinux处于关闭或者暂时关闭状态;
6.  配置httpd
6.1  启动服务
此时不能用service httpd start 这启用的是rpm的不是自己编译安装的。编译安装的httpd控制格式为:
apachectl {start|stop|restart|reload|fullstatus|status|graceful|graceful-stop|configtest}  具体可用man apachectl 查看
在/etc/init.d/中只有rpm包版的httpd,并没有编译安装的httpd文件,所以要自己写(最简单的办法是根据rpm的httpd文件改写一下即可),所以此时无法启动;不过可以在
[root@www ~]# /usr/local/apache/bin/apachectl start #开启编译的httpd服务
[root@www ~]# service httpd status #关闭系统自带的httpd服务
httpd is stopped
[root@www ~]# elinks --dump 192.168.85.128
                 It works!
[root@www ~]# cd /usr/local/apache/htdocs/
[root@www htdocs]# ll
-rw-r--r-- 1 root root 45 Jun 11  2007 index.html
[root@www htdocs]# cat index.html 
<html><body><h1>It works!</h1></body></html>
6.2 在/usr/local/apache/logs目录中有个httpd.pid文件
[root@www apache]# ll logs/
-rw-r--r-- 1 root root  72 Aug 18 04:24 access_log
-rw-r--r-- 1 root root 277 Aug 18 04:24 error_log
-rw-r--r-- 1 root root   5 Aug 18 04:24 httpd.pid
如果想把它在/var/run中显示,在httpd的配置文件/etc/httpd/httpd.conf(注意:不是conf目录下的那个配置文件)中添加
PidFile "/var/run/httpd.pid" 即可;
具体过程:
此时的httpd服务处于开启状态
[root@www apache]# bin/apachectl start
httpd (pid 1998) already running
[root@www apache]# netstat -ntlp | grep :80
tcp        0      0 :::80                       :::*                        LISTEN      1998/httpd   
[root@www apache]# ll logs/ #pid文件存在
-rw-r--r-- 1 root root  72 Aug 18 04:24 access_log
-rw-r--r-- 1 root root 277 Aug 18 04:24 error_log
-rw-r--r-- 1 root root   5 Aug 18 04:24 httpd.pid
接下来关闭服务
[root@www apache]# bin/apachectl stop
[root@www apache]# netstat -ntlp | grep :80
/etc/httpd/httpd.conf添加PidFile "/var/run/httpd.pid"
[root@www apache]# vim /etc/httpd/httpd.conf 
ServerRoot "/usr/local/apache"
PidFile "/var/run/httpd.pid"
重启服务查看
[root@www apache]# bin/apachectl start
[root@www apache]# netstat -ntlp | grep :80
tcp        0      0 :::80                       :::*                        LISTEN      4695/httpd          
[root@www apache]# ll logs/
-rw-r--r-- 1 root root  72 Aug 18 04:24 access_log
-rw-r--r-- 1 root root 672 Aug 18 06:01 error_log
[root@www apache]# ll /var/run/ | grep httpd.pid
-rw-r--r--  1 root      root         5 Aug 18 06:01 httpd.pid
6.3  提供SysV服务脚本
原来的httpd服务的Sysv脚本为
[root@www apache]# ll /etc/rc.d/init.d/ | grep httpd
-rwxr-xr-x. 1 root root  3371 Aug 13  2013 httpd
接下来修改其中的内容为:
[root@www init.d]# cat httpd | sed "/^$/d" | sed "/^#/d"
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
HTTPD_LANG=${HTTPD_LANG-"C"}
INITLOG_ARGS=""
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart|try-restart)
        if status -p ${pidfile} $httpd >&/dev/null; then
                stop
                start
        fi
        ;;
  force-reload|reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac
exit $RETVAL
测试:
[root@www apache]# service httpd status
httpd (pid  4695) is running...
[root@www apache]# service  httpd stop
Stopping httpd: [  OK  ]
[root@www apache]# netstat -ntlp | grep :80
6.4  设置开机启动
6.4.1  
[root@www apache]# chkconfig --add httpd
[root@www apache]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@www apache]# chkconfig --level 35 httpd on
[root@www apache]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
6.4.2  这个没试过
echo "/usr/local/apache/bin/apachectl start >> /etc/rc.d/rc.local
该文件的原内容为:
[root@www apache]# cat /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local

6.5  像apachectl这样的命令也不能直接使用,不过只需将其加入到PATH变量中即可
[root@www ~]# vim  /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
写好之后不会立即生效,因为是Bash脚本,所以可以执行以下生效,也可以重新登陆;
Last login: Tue Aug 18 03:14:30 2015 from 192.168.85.1
[root@www ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apache/bin:/root/bin


阅读(360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~