1.解压Apache

tar zxvf httpd-2.4.18.tar.gz


把apr和apr-util包解压到Apache里的srclib目录里面

tar zxvf apr-1.4.6.tar.gz -C /home/software/httpd-2.4.18/srclib/

tar zxvf apr-util-1.5.2.tar.gz -C /home/software/httpd-2.4.18/srclib/

cd  /home/software/httpd-2.4.18/srclib/


修改一下包名


mv apr-1.4.6 apr
mv apr-util-1.5.2 apr-util


安装apr

cd apr

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

make install

安装apr-util

cd apr-util

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

make install



安装pcre

tar zxvf pcre-8.38.tar.gz

cd pcre-8.38

./configure

make

make install


安装Apache

cd /home/software/httpd-2.4.18


./configure --prefix=/usr/local/apache --enable-so --enable-modules=most --enable-mods-shared=all --enable-proxy --enable-rewrite --with-mpm=worker --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util


make
make install


编译安装mod_fastcgi模块,并在httpd.conf中加载库文件

tar zxvf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
wget http://leeon.me/upload/other/byte-compile-against-apache24.diff

patch -p1 <byte-compile-against-apache24.diff 

//apache2.4下安装mod_fastcgi 2.4.6 ,需要打补丁


cp Makefile.AP2 Makefile

vim Makefile 将Makefile中的路径改成你的apache的安装路径

make && make install //安装成功后,会自动把mod_fastcgi.so复制到/usr/local/apache/modules目录



httpd.conf中添加

LoadModule fastcgi_module modules/mod_fastcgi.so

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so


LoadModule jk_module modules/mod_jk.so



httpd.conf最后面添加如下行:

<FilesMatch \.php$>

         SetHandler "proxy:fcgi://127.0.0.1:9000"

</FilesMatch>



添加apache用户,修改UserGroup为:

User apache

Group apache

ServerName localhost:80


优化Apache

在33行添加


Timeout 60
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 5
UseCanonicalName Off
HostnameLookups Off
ServerSignature Off
ServerTokens Prod

在最后面添加:

<IfModule mpm_worker_module>
    ServerLimit           20
    StartServers          4
    MaxClients           300
    MinSpareThreads       25
    MaxSpareThreads       75
    ThreadsPerChild       30
    MaxRequestsPerChild   0
</IfModule>


增加关于加载mod_jk的配置文件

Include conf/extra/mod_jk.conf


安装配置tomcat


1.查找java相关得列表

     yum -y list java*


2.使用root用户安装
 
  yum -y install java-1.6.0-openjdk*

我们安装jdk1.6相关得全部包。



3.确认是否安装成功

  java -version

4.默认情况下jdk安装得路径
    /usr/lib/jvm

由于我们得机器可能同时安装好几个版本得jdk,所以在/etc/alternatives目录下会有一个java链接到具体的java命令。
而这个/etc/alternatives/java会被/usr/bin/java链接。从而java命令就被设置到了shell环境中。


Tomcat 官网tomcat.apache.org

下载apache-tomcat-7.0.68.tar.gz

tar zxvf  apache-tomcat-7.0.68.tar.gz         解压

mv apache-tomcat-7.0.68 /usr/local/tomcat     移动并改名



vi   /usr/local/tomcat/bin/catalina.sh
添加  98行上下
CATALINA_HOME=/usr/local/tomcat       指定tomcat的路径    


JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64          不要盲目复制,注意jdk版本指定jdk的目录

 (find / -name java     查看路径)



编译生成mod_jk


tar -zxvf tomcat-connectors-1.2.41-src.tar.gz

cd tomcat-connectors-1.2.41-src/native/

./buildconf.sh

./configure --with-apxs=/usr/local/apache/bin/apxs

make

cp ./apache-2.0/mod_jk.so /usr/local/apache/modules/


查看一下   ll /usr/local/apache/modules/mod_jk.so


在/usr/local/apache/conf/extra下面建立两个配置文件mod_jk.conf和workers.properties。

vi mod_jk.conf


JkWorkersFile /usr/local/apache/conf/extra/workers.properties

# Where to put jk logs
JkLogFile /usr/local/apache/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理
JkMount /servlet/* worker1
JkMount /*.jsp worker1


vi workers.properties


# Defining a worker named worker1 and of type ajp13
worker.list=worker1

# Set properties for worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300





最后编辑Tomcat的配置文件server.xml,在HOST段中加入:

vi /usr/local/tomcat/conf/server.xml



<Context path="" docBase="/usr/local/apache/htdocs/" debug="0" reloadable="true" crossContext="true"/>
在/var/wwwroot下建立一个index.jsp,启动Apache和Tomcat,用浏览器访问http://localhost/,应该可以看到正确的页面了。


启动tomcat

/usr/local/tomcat/bin/startup.sh


启动httpd

/usr/local/apache/bin/httpd -k start


到此,Apache和Tomcat整合就完成了