1、rpm包安装httpd 2.2
系统环境:
[root@zhaochj ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m [root@zhaochj ~]# uname -r 2.6.32-358.el6.x86_64 [root@zhaochj ~]# ifconfig | grep Bcast: inet addr:192.168.0.200 Bcast:192.168.0.255 Mask:255.255.255.0
查看当前yum源中可用的httpd安装包:
[root@zhaochj ~]# yum list all *httpd* Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.btte.net * extras: mirrors.btte.net * updates: mirrors.btte.net Available Packages httpd.x86_64 2.2.15-31.el6.centos updates httpd-devel.i686 2.2.15-31.el6.centos updates httpd-devel.x86_64 2.2.15-31.el6.centos updates httpd-manual.noarch 2.2.15-31.el6.centos updates httpd-tools.x86_64 2.2.15-31.el6.centos updates
安装httpd:
[root@zhaochj ~]# yum -y install httpd
查看生成的配置文件:
[root@zhaochj ~]# rpm -qc httpd /etc/httpd/conf.d/welcome.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf/magic /etc/logrotate.d/httpd ……
httpd配置相关的目录结构:
[root@zhaochj httpd]# pwd /etc/httpd [root@zhaochj httpd]# tree . ├── conf │ ├── httpd.conf │ ├── httpd.conf.back #对原配置文件做备份 │ └── magic ├── conf.d │ ├── README │ └── welcome.conf ├── logs -> ../../var/log/httpd ├── modules -> ../../usr/lib64/httpd/modules └── run -> ../../var/run/httpd
配置hosts文件:
[root@zhaochj httpd]# vim /etc/hosts 192.168.0.200 zhaochj #增加此行
配置主配置文件,启用ServerName:
[root@zhaochj httpd]# vim conf/httpd.conf ServerName 192.168.1.200:80 #启用ServerName,并修改为
测试配置文件:
[root@zhaochj httpd]# httpd -t Syntax OK
启用httpd服务:
[root@zhaochj httpd]# service httpd start Starting httpd: [ OK ]
查看httpd的版本:
[root@zhaochj ~]# httpd -v Server version: Apache/2.2.15 (Unix) Server built: Oct 16 2014 14:48:21
查看httpd的使用的MPM,默认是prefork:
[root@zhaochj httpd]# httpd -l Compiled in modules: core.c prefork.c http_core.c mod_so.c
修改MPM为worker,并验证:
[root@zhaochj httpd]# vim /etc/sysconfig/httpd HTTPD=/usr/sbin/httpd.worker #启用此行 [root@zhaochj httpd]# service httpd restart [root@zhaochj httpd]# ps aux | grep httpd
2、源码安装httpd 2.2
实验环境IP有变化:
[root@zhaochj ~]# ifconfig | grep Bcast: inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
所使用的软件(这里获取:http://pan.baidu.com/s/1mgDoGWw):
apr-1.4.8.tar.gz apr-util-1.3.9.tar.gz httpd-2.2.25.tar.bz2
安装apr
[root@zhaochj apr-1.4.8]# tar xf apr-1.4.8 [root@zhaochj apr-1.4.8]# cd apr-1.4.8 [root@zhaochj apr-1.4.8]# ./configure --prefix=/usr/local/apr1.4 [root@zhaochj apr-1.4.8]# make && make install
安装apr-util
[root@zhaochj apr-util-1.3.9]# tar xf apr-util-1.3.9 [root@zhaochj apr-util-1.3.9]# cd apr-util-1.3.9 [root@zhaochj apr-util-1.3.9]# ./configure --prefix=/usr/local/apr-util_1.3 --with-apr=/usr/local/apr1.4/ [root@zhaochj apr-util-1.3.9]# make && make install
安装pcre
[root@zhaochj software]# yum -y install pcre-devel
安装httpd2.2
[root@zhaochj httpd-2.2.25]# ./configure --prefix=/usr/local/apache22 --sysconfdir=/etc/httpd22 --with-apr=/usr/local/apr1.4 --with-apr-util=/usr/local/apr-util_1.3 --enable-deflate --enable-rewrite --enable-headers --enable-mods-shared=most --enable-modules=most --enable-ssl --enable-so --enable-cgi --with-mpm=prefork [root@zhaochj httpd-2.2.25]# make && make install
说明:
--enable-mods-shared=most #把大多数功能以模块化安装,像“--enable-deflate,--enable-rewrite”等这些模块已经在“--enable-mods-shared=most”里了,只是一种习惯把模块单独再写出来
--enable-modules=most #表示将大部分模块静态编译到httpd二进制文件中
查看生成的目录:
[root@zhaochj apache22]# pwd /usr/local/apache22 [root@zhaochj apache22]# ls bin build cgi-bin error htdocs icons include lib logs man manual modules [root@zhaochj apache22]# ls /etc/httpd22/ extra httpd.conf magic mime.types original
编辑配置文件,启用ServerName
[root@zhaochj apache22]# vim /etc/httpd22/httpd.conf ServerName 192.168.1.10:80
拷贝脚本文件:
[root@zhaochj apache22]# cp bin/apachectl /etc/rc.d/init.d/httpd22
启动服务及验证:
[root@zhaochj httpd22]# service httpd22 start [root@zhaochj apache22]# ps aux | grep httpd
查看源码编译时的编译参数:
[root@zhaochj apache22]# cat build/config.nice
查看httpd的版本:
[root@zhaochj ~]# /usr/local/apache22/bin/apachectl -v Server version: Apache/2.2.25 (Unix) Server built: Jan 14 2015 14:01:18
查看编译的模块:
[root@zhaochj ~]# /usr/local/apache22/bin/apachectl -l
3、从httpd2.2.25升级到httpd2.2.29
解压httpd2.2.29.tar.bz,进入解压目录:
[root@zhaochj software]# tar xf httpd-2.2.29.tar.bz2 [root@zhaochj software]# cd httpd-2.2.29/
copy旧版的configure.nice文件到当前目录并作相应修改:
[root@zhaochj httpd-2.2.29]# cp /usr/local/apache22/build/config.nice ./ [root@zhaochj httpd-2.2.29]# vim config.nice #! /bin/sh # # Created by configure "./configure" \ "--prefix=/usr/local/apache229" \ #安装目录与旧版本区分开 "--sysconfdir=/etc/httpd229" \ #配置文件与旧版本区分开,以下的参数都可以适当的增加或修改 "--enable-deflate" \ "--enable-rewrite" \ "--enable-headers" \ "--enable-mods-shared=most" \ "--enable-modules=most" \ "--enable-ssl" \ "--enable-so" \ "--enable-cgi" \ "--with-mpm=prefork" \ "$@"
编译、配置、安装:
[root@zhaochj httpd-2.2.29]# ./config.nice [root@zhaochj httpd-2.2.29]# make && make install
新版本查看:
[root@zhaochj httpd-2.2.29]# /usr/local/apache229/bin/apachectl -v Server version: Apache/2.2.29 (Unix) Server built: Jan 15 2015 13:19:43
一些说明:
httpd的版本顺利升级后,应修改新版本服务的监听端口,不要与旧版本监听的端口冲突,通过一断时间的测试后再正式投入生产环境。