Java SE Downloads
一、所需软件包
OS:CentOS-5.4-i386
httpd-2.2.9.tar.gz
apache-tomcat-6.0.32.tar.gz
#wget
jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
#wget
jdk-1_5_0_06-linux-i586.bin
二、apache安装
1、编译环境搭建
- # for i in gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel ; do yum install -y $i ;done
2、apache编译
- # tar xvf httpd-2.2.9.tar.gz
- # cd httpd-2.2.9
- # ./configure ——prefix=/usr/local/apache2 ——enable-so
- # make
- # make install
三、tomcat安装
- # tar xvf apache-tomcat-6.0.32.tar.gz
- # cp -ar apache-tomcat-6.0.32 /usr/local
- # ln -s apache-tomcat-6.0.32 tomcat
四、java环境配置
- # mkdir /usr/java
- # cp jdk-1_5_0_06-linux-i586.bin /usr/java
- # cd /usr/java
- # bash jdk-1_5_0_06-linux-i586.bin
这样java jdk将安装到系统/usr/java/jdk1.5.0_06中
五、编译生成mod_jk<用于连接apache与tomcat的桥梁>
- # tar xvf jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
- # cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/
- # ./configure --with-apxs2=/usr/local/apache2/bin/apxs
- # make
- # cd ../build/jk2/apache2/
- # /usr/local/apache2/bin/apxs -n jk2 -i mod_jk2.so
- # ll /usr/local/apache2/modules/
- total 788
- -rw-r--r-- 1 root root 8998 Jun 8 10:14 httpd.exp
- -rwxr-xr-x 1 root root 778870 Jun 8 10:21 mod_jk2.so
- # cd /usr/local/apache2/conf/
- # vi mod_jk2.conf
- 添加如下:
- # 指出mod_jk模块工作所需要的工作文件workers2.properties的位置
- JkWorkersFile /usr/local/apache2/conf/workers2.properties
- # Where to put jk logs
- JkLogFile /usr/local/apache2/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 workers2.properties
- 添加如下:
- # Define the communication channel
- [channel.socket:localhost:8009]
- info=Ajp13 forwarding over socket
- tomcatId=localhost:8009
-
- # Map the Tomcat examples webapp to the Web server uri space
- [uri:/*.jsp]
- info=Map the whole webapp
-
配置httpd.conf
在最后添加:
- LoadModule jk2_module modules/mod_jk2.so
六、配置tomcat启动脚本
- # cp /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat
- # vi /etc/init.d/tomcat
- 在第二行加入如下内容:
- # chkconfig: 345 88 14
- # description: Tomcat Daemon
- # processname: tomcat
- JAVA_HOME=/usr/java/jdk1.5.0_06
- CATALINA_HOME=/usr/local/tomcat
- # chmod 755 /etc/init.d/tomcat
- # chkconfig --add tomcat
- # chkconfig tomcat on
七、启动服务
- # /usr/local/apache2/bin/apachectl start
- # service tomcat start
- Using CATALINA_BASE: /usr/local/tomcat
- Using CATALINA_HOME: /usr/local/tomcat
- Using CATALINA_TMPDIR: /usr/local/tomcat/temp
- Using JRE_HOME: /usr/java/jdk1.5.0_06
- Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
- 出现这些说明tomcat启动成功
八、测试
出现“It works”
出现一个“猫”的log说明成功
九、整合apache与tomcat
# vi /usr/local/tomcat/conf/server.xml
- 找到如下一段:
- 128 <Host name="localhost" appBase="webapps"
- 129 unpackWARs="true" autoDeploy="true"
- 130 xmlValidation="false" xmlNamespaceAware="false">
- 在下面添加一行:定义主目录与apache相同
- <Context path="" docBase="/usr/local/apache2/htdocs" debug="0"/>
重启服务<顺序不能乱>
- # /usr/local/apache2/bin/apachectl stop
- # service tomcat stop
- # /usr/local/apache2/bin/apachectl start
- # service tomcat start
建立测试页面
# vi /usr/local/apache2/htdocs/time.jsp
填入: Hello! The time is <%= new java.util.Date() %>
链接测试:
访问与
与
出现各自相同的页面
......................
说明成功!