RPM格式安装httpd

httpd相关软件包说明:


软件包名称功能
httpd主软件包
httpd-develhttpd相关的开发包
httpd-manual官方帮助手册
httpd-toolshttpd相关的工具集


httpd的目录结构:

服务脚本:/etc/rc.d/init.d/httpd
工作目录:/etc/httpd
主配置文件:/etc/httpd/conf/httpd.conf
扩展配置文件:/etc/httpd/conf.d/*.conf
网站根目录:/var/www/html/
CGI脚本目录:/var/www/cgi-bin/
模块目录:/etc/httpd/modules(链接到/usr/lib64/httpd/modules)
日志目录:/etc/httpd/logs(链接到/var/log/httpd)
PID文件存放目录:/etc/httpd/run(链接到/var/run/httpd)
磁盘缓存目录:

/var/cache/mod_proxy

错误页面目录:/var/www/error
预设图标目录:

/var/www/icons

DAV相关目录:/var/lib/dav
启动脚本:

/usr/sbin/apachectl

主程序:

/usr/sbin/httpd

Event模型主程序:

/usr/sbin/httpd.event

Worker模型主程序:/usr/sbin/httpd.worker
密码文件生成工具:

/usr/bin/htpasswd

日志滚动工具:

/usr/sbin/rotatelogs

磁盘缓存清理工具:

/usr/sbin/htcacheclean

开机启动httpd读取的配置文件:/etc/sysconfig/httpd
默认欢迎页配置文件:

/etc/httpd/conf.d/welcome.conf


配置文件通用语法规则:

                 1,指令不区分大小写,但通常建议将首字母大写;

          2,指令的值可能会区分大小写(比如路径);

          3,指令和值之间用空格隔开即可;

          4,某些指令可以重复出现多次(如listen);

          5,紧跟在"#"符号后没有空格的为指令,是可以启用的,"#"符号后面紧跟有空格的为注释;


主配置文件构成:  

                 1,全局配置:对主服务器或虚拟主机都生效,并且有些功能是服务器自身的工作属性;

                 2,主服务器:与主站相关的设置;

                 3,虚拟主机:虚拟主机相关的设置;

                 注意:主服务器和虚拟主机不能同时启用;


安装httpd:  

yum -y install httpd      #安装httpd
chkconfig --list httpd    #查看开机启动列表
chkconfig httpd on        #设置开机自动启动


服务脚本参数:

Usage: service httpd {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}
start启动
stop停止
restart重新启动(不管服务当前是否在允许,都可以启动该服务)
condrestart

当服务在允许时,它可以重新启动该服务;如果服务未启动,它不能重启该服务

try-restart尝试重新启动
force-reload强制重新启动
reload
重新加载配置文件
status查看服务状态
fullstatus查看服务状态详细信息
graceful优雅重启
help查看帮助
configtest测试配置文件语法


源码编译安装httpd

关闭系统默认的httpd:

# service httpd stop

# chkconfig httpd off

解决依赖的组件及软件:

1,安装开发包:       

             # yum groupinstall "Development tools"

     # yum groupinstall "Server Platform Development"

     # yum groupinstall "Desktop Platform Development"

2,安装apr、arp-util:     

             # tar xf apr-1.5.1.tar.bz2 

     # ./configure --prefix=/usr/local/apr

     # make && make install


             # tar xf aprutil-1.5.3.tar.gz 

             # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

             # make && make install

3,安装pcre-devel:

             # yum -y install pcre-devel

编译安装httpd:

             # tar xf httpd-2.4.9.tar.bz2

             # ./configure \

     --prefix=/usr/local/apache \   //指定安装目录

     --sysconfdir=/etc/httpd24 \      //指定配置文件目录

     --enable-so \                  //启用动态模块加载功能

     --enable-ssl \                 //启用支持SSL

     --enable-cgi \                 //启用支持CGI

     --enable-rewrite \             //启用支持URL重写功能

     --with-zlib \                  //使用支持zlib压缩

     --with-pcre \                  //使用pcre  

     --with-apr=/usr/local/apr \    //指定apr目录

     --with-apr-util=/usr/local/apr-util \     //指定apr-util目录

     --enable-modules=most \                   //启用支持大多数模块

     --enable-mpms-shared=all \                //启用所有mpm模块为DSO模式

     --with-mpm=event                          //指定默认使用的mpm模块为event

启动httpd:

             # vi /etc/profile.d/httpd.sh

                  export PATH=/usr/local/apache/bin:$PATH 


             # . /etc/profile.d/httpd.sh

             # apachectl start

             # ps aux | grep httpd

添加服务启动脚本:

             # cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24

             # vi httpd24    //修改如下几行   

                  apachectl=/usr/local/apache/bin/apachectl

                  httpd=${HTTPD-/usr/local/apache/bin/httpd}

                  pidfile=${LOCKFILE-/usr/local/apache/logs/httpd.pid}

             # chkconfig --add httpd24

             # service httpd24 start

如何切换MPM:

            # vi /usr/local/apache/httpd.conf

                 LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

            # httpd -D DUMP_MODULES