Httpd 2.4新特性:
1、MPM可于运行时装载: --enable-mpms-shared=all --with-mpm=event 编译安装是指定MPM运行模块为event
2、Event MPM 支持event新的多路处理模块
3、异步读写
4、在每模块及每目录上指定日志级别
5、每请求配置: <If>,<ElseIf>,<Else>;
6、增强的表达式分析器;
7、毫秒级的Keepalive Timeout;
8、基于域名的虚拟主机不再需要NameVirtualHost指令;
9、降低了内存占用;
10、支持在配置文件中使用自定义变量;
11、对于基于IP的访问控制不再支持order all,deny allow from all
而是支持Require user
Usage:
Require user USERNAME
Require group GRPNAME
Require ip IPADDR 允许该IP地址访问
Require not ip IPADDR 拒绝该IP地址访问
IP
NETWORK/NETMASK
NETWORK/LENGTH
NET
172.16.0.0/255.255.0.0=172.16.0.0/16=172.16
Require host HOSTNAME
HOSTNAME : www.linux.com
DOMAIN : .linux.com
允许所有主机访问:
Require all granted
拒绝所有主机访问:
Require all deny
--enable-modules=most
新增的模块:
mod_proxy(之前版本也有)
mod_proxy_fcgi
mod_proxy_scgi
mod_proxy_express
mod_remoteip
mod_sesslon
mod_ratelimit
mod_request
等等
通过编译安装LAMP环境:
安装顺序:httpd --> mysql --> php --> xcache(php缓存程序)
Linux,Apache,Mysql,Php
以下演示安装httpd:2.4.4 php:5.4.13 Mysql:5.5(通用二进制格式,解压后即可使用)
1、 安装httpd 2.4.4需安装高版本的apr1.4以上的版本 apr-util1.4版本以上
[[email protected] ~]# rpm -q apr
apr-1.3.9-3.el6.x86_64
[[email protected] ~]# rpm -q apr-util
apr-util-1.3.9-3.el6.x86_64
*所以需要下载更高版本的arp和apr-util,但是原来的安装程序不能卸载,因为他们被其他程序依赖
需通过编译安装在其他目录下即可。
把apr和apr-util安装在/usr/local目录下,这个目录为第三方软件安装目录:
[[email protected] ~]# ls
anaconda-ks.cfg apr-util-1.4.1.tar.bz2 install.log
apr-1.4.6.tar.gz httpd-2.4.4.tar.gz install.log.syslog
安装顺序:apr-1.4.6 --> apr-util-1.4.1 --> httpd-2.4.4
[[email protected] ~]# tar -zxf apr-1.4.6.tar.gz
[[email protected] ~]# tar -xf apr-util-1.4.1.tar.bz2
[[email protected] ~]# tar -xf httpd-2.4.4.tar.gz
[[email protected] ~]# ls
anaconda-ks.cfg apr-util-1.4.1 install.log apr-1.4.6
apr-util-1.4.1.tar.bz2 apr-1.4.6.tar.gz httpd-2.4.4.tar.gz httpd-2.4.4
安装前需确认开发环境组是否安装:Development Tools(开发工具)和Development Libraries(开发库)
[[email protected] ~]# yum groupinstall "Development Tools"
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Group Process
[[email protected] ~]# yum groupinstall "Development Libraries"
[[email protected] ~]# cd apr-1.4.6
[[email protected] apr-1.4.6]# ./configure --prefix=/usr/local/apr #编译安装前,
--prefix指定编译安装路径
[[email protected] apr-1.4.6]# make
[[email protected] apr-1.4.6]# make install #至此编译安装apr完成(删除编译安装的软件,只需要把安装目录删除即可)
[[email protected] apr-1.4.6]# cd ~/apr-util-1.4.1
[[email protected] apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #编译安装apr-util需通过--prefix指定安装目录,以及--with-apr指定apr的安装路径。(必须2者都指定) 至此apr-util-1.4.1安装成功
[[email protected] apr-util-1.4.1]# cd ~/httpd-2.4.4
[[email protected] httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --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 #编译安装httpd需指定安装目录--prefix,主配置文件目录--sysconfdir
还需开通很多功能,--enable-so等功能,且必须指定apr和apr-util编译安装的位置。
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ #这里报错提示pcre-config没有安装,需安装pcre-devel
[[email protected] httpd-2.4.4]# yum install pcre-devel #安装pcre-devel
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Server | 3.7 kB 00:00
...
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:7.8-3.1.el6 set to be updated
--> Finished Dependency Resolution
......
Running Transaction
Installing : pcre-devel-7.8-3.1.el6.x86_64 1/1
Installed:
pcre-devel.x86_64 0:7.8-3.1.el6
Complete!
[[email protected] httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --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 #再重新执行一次编译
.......
checking for OpenSSL... checking for user-provided OpenSSL base directory... none
checking for OpenSSL version >= 0.9.7... FAILED #提示openssl version 错误,解决方法
安装openssl-devel
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
[[email protected] httpd-2.4.4]# yum install openssl-devel #安装openssl-devel
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.x86_64
..........
Installed:
openssl-devel.x86_64 0:1.0.0-4.el6
Dependency Installed:
keyutils-libs-devel.x86_64 0:1.4-1.el6 krb5-devel.x86_64 0:1.8.2-3.el6 libcom_err-devel.x86_64 0:1.41.12-3.el6 libselinux-devel.x86_64 0:2.0.94-2.el6 libsepol-devel.x86_64 0:2.0.41-3.el6 zlib-devel.x86_64 0:1.2.3-25.el6
Complete!
[[email protected] httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --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 #再重新执行一次编译
.........
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands #直到编译安装不再出现报错可以继续执行make
[[email protected] httpd-2.4.4]# make #一般./configure 编译报错都解决后,make和make一般都会成功
直接执行make和make install就可以了
[[email protected] httpd-2.4.4]# make install
......
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory `/root/httpd-2.4.4‘ #至此httpd编译安装完成
启动httpd前需把selinux关闭,否则无法启动:
[[email protected] httpd-2.4.4]# getenforce #查看selinux当前状态
Enforcing
[[email protected] httpd-2.4.4]# setenforce 0 #临时关闭selinux,重启失效。
[[email protected] httpd-2.4.4]# vim /etc/selinux/config #编辑selinux配置文档,使设置永久有效
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive #这项改成permissive或者disabled(建议改成permissive)
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[[email protected] httpd-2.4.4]# getenforce
Permissive #状态变为permissive
[[email protected] httpd-2.4.4]# cd /usr/local/apache
[[email protected] apache]# ls
bin build cgi-bin error htdocs icons include logs man manual modules
[[email protected] apache]# bin/apachectl start #测试启动apache服务
[[email protected] apache]# netstat -tlnp #查看监听的端口号
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1325/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1809/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1572/sshd
tcp 0 0 :::111 :::* LISTEN 1325/rpcbind
tcp 0 0 :::80 :::* LISTEN 14642/httpd
至此httpd服务就启动了,通过客户端访问ip即可
修改httpd.conf配置文档使得httpd.pid(httpd进程启动生成的文档,服务关闭后文档消失)文档生成路径修改为/var/run/httpd.pid,
[[email protected] apache]# bin/apachectl stop #停止httpd服务
[[email protected] apache]# vim /etc/httpd/httpd.conf #配置文件路径为编译安装httpd的时候设置的路径
..........
# least PidFile.
#
ServerRoot "/usr/local/apache"
PidFile "/var/run/httpd.pid" #新增该行内容(必须先停止httpd服务)
.........
***为了使得httpd可以通过service httpd stop|start|restart管理方式,需在/etc/init.d/新建一个脚本httpd启动脚本,脚本内容如下:
[[email protected] apache]# vim /etc/init.d/httpd
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to server
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
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 10 $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=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
kellproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl [email protected]
RETVAL=$?
;;
*)
echo $"Usage: $prog{start|stop|restart|condrestart|reload|status|fullstatus|graceful|help| configtest}"
exit 1
esac
exit $RETVAL
[[email protected] apache]# chmod +x /etc/init.d/httpd #赋予执行权限
[[email protected] apache]# service httpd restart #通过启用服务方式成功重新启动httpd服务
停止 httpd: [确定]
正在启动 httpd: [确定]
[[email protected] apache]# chkconfig --add httpd #把httpd服务添加到开机启动列表中
[[email protected] apache]# chkconfig --list #查看开机启动列表
NetworkManager 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
ebtables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
firstboot 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
gfs2 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
haldaemon 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 #默认开机不启动
ip6tables 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] apache]# chkconfig httpd on #设定httpd服务在级别2345默认开机启动(或者指定chkconfig --level 35 httpd on设定服务在级别35开机启动)
[[email protected] apache]# chkconfig --list #查看开机启动列表
NetworkManager 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
ebtables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
firstboot 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
gfs2 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
haldaemon 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 #默认开机启动
ip6tables 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] apache]# cd
[[email protected] ~]# vim /etc/profile.d/httpd.sh #把/usr/local/httpd/bin执行脚本命令路径放置在PATH变量中,使得该路径中的命令可以直接执行。
export PATH=$PATH:/usr/local/apache/bin #增加该行内容
然后重新登录下系统,/usr/local/apache/bin中的命令都可以直接执行,而不用加路径
[[email protected] ~]# httpd -t #检查httpd配置文件是否有语法错误
Syntax OK
[[email protected] ~]# echo $PATH
/usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apache/bin:/root/bin #已经把/usr/local/apache/bin目录加到了PATH变量中
[[email protected] ~]# vim /etc/httpd/httpd.conf #修改主配置文档中下面2行内容
[[email protected] ~]# httpd -t
Syntax OK
[[email protected] ~]# service httpd restart
停止 httpd: [确定]
正在启动 httpd: [确定]
[[email protected] ~]# httpd -M #查看当前启用的模块
Loaded Modules:
.......
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_prefork_module (shared) #默认模块已经修改为prefork模块了(以后需要切换其他模块只需 要修改主配置文档中上一步骤的内容即可)
unixd_module (shared)
status_module (shared)
........
2、开始安装mysql5.5.54版本
[[email protected] ~]# ls
anaconda-ks.cfg apr-util-1.4.1.tar.bz2 install.log.syslog httpd-2.4.4 mysql-5.5.54-linux2.6-x86_64.tar.gz
[[email protected] ~]# tar xf mysql-5.5.54-linux2.6-x86_64.tar.gz -C /usr/local #-C 指定解压目录
[[email protected] ~]# cd /usr/local
[[email protected] local]# ls
apache apr-util etc include lost+found mysql-5.5.54-linux2.6-x86_64
[[email protected] local]# ln -sv mysql-5.5.54-linux2.6-x86_64 mysql #创建软链接mysql
"mysql" -> "mysql-5.5.54-linux2.6-x86_64"
[[email protected] local]# ls
apache apr-util etc include lib64 mysql-5.5.54-linux2.6-x86_64
apr bin games lib libexec mysql
[[email protected] local]# cd mysql
[[email protected] mysql]# groupadd -r -g 306 mysql #-r指创建系统组,-g指定组ID
[[email protected] mysql]# useradd -r -g 306 -u 306 mysql #-r创建系统用户(不能登录系统的用户)
-u指定UID
[[email protected] mysql]# id mysql #查看用户信息,UID GID
uid=306(mysql) gid=306(mysql) 组=306(mysql)
[[email protected] mysql]# ls /home
donggen
[[email protected] mysql]# ll
总用量 72
drwxr-xr-x. 2 root root 4096 2月 17 09:33 bin
-rw-r--r--. 1 7161 31415 17987 11月 28 20:32 COPYING
drwxr-xr-x. 3 root root 4096 2月 17 09:33 data
drwxr-xr-x. 2 root root 4096 2月 17 09:33 docs
drwxr-xr-x. 3 root root 4096 2月 17 09:33 include
-rw-r--r--. 1 7161 31415 301 11月 28 20:32 INSTALL-BINARY
drwxr-xr-x. 3 root root 4096 2月 17 09:33 lib
drwxr-xr-x. 4 root root 4096 2月 17 09:33 man
drwxr-xr-x. 10 root root 4096 2月 17 09:34 mysql-test
-rw-r--r--. 1 7161 31415 2496 11月 28 20:32 README
drwxr-xr-x. 2 root root 4096 2月 17 09:33 scripts
drwxr-xr-x. 27 root root 4096 2月 17 09:33 share
drwxr-xr-x. 4 root root 4096 2月 17 09:33 sql-bench
drwxr-xr-x. 2 root root 4096 2月 17 09:33 support-files
[[email protected] mysql]# chown -R mysql.mysql /usr/local/mysql/* #-R递归把mysql目录下的所有文档 或目录都修改为mysql用户和mysql组
[[email protected] mysql]# ll
总用量 72
drwxr-xr-x. 2 mysql mysql 4096 2月 17 09:33 bin
-rw-r--r--. 1 mysql mysql 17987 11月 28 20:32 COPYING
drwxr-xr-x. 3 mysql mysql 4096 2月 17 09:33 data
drwxr-xr-x. 2 mysql mysql 4096 2月 17 09:33 docs
drwxr-xr-x. 3 mysql mysql 4096 2月 17 09:33 include
-rw-r--r--. 1 mysql mysql 301 11月 28 20:32 INSTALL-BINARY
drwxr-xr-x. 3 mysql mysql 4096 2月 17 09:33 lib
drwxr-xr-x. 4 mysql mysql 4096 2月 17 09:33 man
drwxr-xr-x. 10 mysql mysql 4096 2月 17 09:34 mysql-test
-rw-r--r--. 1 mysql mysql 2496 11月 28 20:32 README
drwxr-xr-x. 2 mysql mysql 4096 2月 17 09:33 scripts
drwxr-xr-x. 27 mysql mysql 4096 2月 17 09:33 share
drwxr-xr-x. 4 mysql mysql 4096 2月 17 09:33 sql-bench
drwxr-xr-x. 2 mysql mysql 4096 2月 17 09:33 support-files
[[email protected] mysql]#
** 由于mysql数据库随着时间的增长,数据会越来越大,所以应该把数据库数据放置在一个单独的可扩展的分区卷上,以便后期管理和备份,挂载在逻辑卷是比较好的方法如下:
apr-util-1.4.1.tar.gz下载地址:http://download.chinaunix.net/download.php?id=36061&ResourceID=470
apr-1.4.6.tar.gz下载地址:http://download.chinaunix.net/download.php?id=37842&ResourceID=470
httpd-2.4.4.tar.gz下载地址: http://download.csdn.net/download/www476907899/5208979
mysql-5.5.54通用二进制版本下载地址:http://mirrors.sohu.com/mysql/MySQL-5.5/