配置过程:

1、apache

[root@client ~]# yum install make gcc-c++ openssl openssl-devel -y

[root@client ~]# tar -jxvf httpd-2.2.11.tar.bz2

[root@client ~]# cd httpd-2.2.11

[root@client httpd-2.2.11]# ./configure --prefix=/usr/local/httpd --with-mpm=worker --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-mime-magic --enable-headers --enable-http --enable-cgi --enable-rewrite --enable-so --with-suexec-gidmin --with-suexec-logfile

[root@client httpd-2.2.11]# make && make install

加入到环境变量中:

[root@client ~]# vim /etc/profile

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

p_w_picpath

[root@client ~]# source /etc/profile

[root@client ~]# apachectl start

然后在浏览器访问一下,可以

p_w_picpath_thumb1

看看httpd启动的端口:

[root@client ~]# ps aux | grep httpd | grep -v grep

p_w_picpath

[root@client ~]# netstat -antlp | grep :80

p_w_picpath

2、安装 Sun Java JDK 和 Tomcat

[root@client ~]# sh jdk-6u26-linux-x64.bin

[root@client ~]# mv jdk1.6.0_26/ /usr/local/jdk

[root@client ~]# tar -zxvf apache-tomcat-7.0.8.tar.gz

[root@client ~]# mv apache-tomcat-7.0.8 /usr/local/tomcat

3、在安装 mod_jk 之前,需先设定  tomcat  与  java  的目录,可在  /etc/profile 写入环境变量。

[root@client ~]# vim /etc/profile

JAVA_HOME=/usr/local/jdk
JRE_HOME=/usr/local/jdk/jre
CATALINA_HOME=/usr/local/tomcat
CATALINA_BASE=/usr/local/tomcat
PATH=$PATH:${JAVA_HOME}/bin:${JRE_HOME}/bin:/usr/local/httpd/bin
CLASSPATH=./:${JAVA_HOME}/lib:${JRE_HOME}/lib:${CATALINA_HOME}/lib

export JAVA_HOME JRE_HOME CATALINA_HOME CATALINA_BASE CLASSPATH PATH

p_w_picpath

[root@client ~]# source /etc/profile

测试Java环境的安装

[root@client ~]# java -version

p_w_picpath

浏览器访问tomcat 8080 端口:

p_w_picpath

 

4、编译安装mod_jk

[root@client ~]# wget http://www.fayea.com/apache-mirror//tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz

[root@client ~]# tar -zxvf tomcat-connectors-1.2.37-src.tar.gz

[root@client ~]# cd tomcat-connectors-1.2.37-src/native/

[root@client native]# ./configure --with-apxs=/usr/local/httpd/bin/apxs

[root@client native]# make

[root@client native]# cp apache-2.0/mod_jk.so /usr/local/httpd/lib/

完成上面的步骤之后就可以设置apache了,让mod_jk模块生效。

[root@client native]# cd /usr/local/httpd/conf/

a)apache中加入mod_jk

[root@client conf]# vim httpd.conf

LoadModule jk_module lib/mod_jk.so
# mod_jk settings
Include ?usr/local/httpd/conf/mod_jk.conf

p_w_picpath

b)在/usr/local/httpd/conf/ 目录下加入文件mod_jk.conf

[root@client conf]# vim mod_jk.conf

JKWorkersFile /usr/local/httpd/conf/workers.properties
JkLogFile  /usr/local/httpd/logs/mod_jk.log
JkShmFile  /usr/local/httpd/logs/jk-runtime-status
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

# Sample JkMounts.  Replace these with the paths you would
# like to mount from your JSP server.
# syntax: JkMount ${URL_DIR}/*.jsp worker_name

JkMount /servlet/*.jsp worker1
JkMount /*.jsp worker1
JkMount /*.do worker1

 

p_w_picpath

手动添加日志文件:

[root@client conf]# touch /usr/local/httpd/logs/mod_jk.log

[root@client conf]# touch /usr/local/httpd/logs/jk-runtime-status

 

c)增加workers.properties

[root@client conf]# vim workers.properties

# BEGIN workers.properties
# setting tomcat_home and java_home
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/jdk

# worker.list defined worker_name, used by mod_jk.conf
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300

p_w_picpath

5、设置tomcat

处理apache的一些文件,需要tomcat的配合,预设的tomcat开启8009端口,因此只需要设置虚拟目录就行啦

涉及文件:/usr/local/tomcat/conf/server.xml

虚拟目录:/opt/webapps

[root@client ~]# vim /usr/local/tomcat/conf/server.xml

6、重启apache

[root@client ~]# apachectl -k restart

7、测试jsp文件

编写小的jsp时间函数:

[root@client ~]# echo 'The time is: <%= new java.util.Date() %>' &gt; /usr/local/tomcat/webapps/ROOT/test.jsp

p_w_picpath

p_w_picpath