tomact+apache实现web网页动静结合
一.Tomact简介
1.tomact是apache软件基金会的一个核心项目。由apache、SUN 和其他的一些公司及个人共同研发的;tomact是一个开放源代码,运行servlet和JSP Web应用软件的基于Java的Web应用软件容器;;tomact是小型的轻量级应用服务器,适用于小型和中型系统或者是访问用户不是特别多的情况。
@1.servelet: server + applet 服务器端的小程序
@2.servelet容器:管理和运行servelet的。
优势:能够很好的处理动态页面,跨平台也不错。JSP
缺点:处理静态页面缓慢,配置文件的可配置性不强。
2.JSP:是一种以java作为脚本语言些的一个服务于http的应用程序
3.安装tomcat需要的软件包
apache-tomcat-6.0.16.tar.gz
jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
jdk-1_5_0_16-linux-i586.bin
JiveForumsPro4_crack.tar.gz
mysql-connector-java-3.1.14.tar.gz
二.具体配置
1.部署java环境
1.安装
[root@tx1 ~]# chmod +x jdk-1_5_0_16-linux-i586.bin
[root@tx1 ~]# cp -a jdk1.5.0_16/ /usr/local/java
2.配置java环境变量
[root@tx1 ~]# vim /etc/profile//设置一些path路径
JAVA_HOME=/usr/local/java
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME PATH CLASSPATH
[root@tx1 ~]# . /etc/profile//重启配置文件
[root@tx1 ~]# java -version //查看java版本
java version "1.5.0_16"
[root@tx1 tmp]# vim hello.java
public class hello {
public static void main(String[] args){
System.out.println("hello all");
}
}
[root@tx1 tmp]# javac hello.java
[root@tx1 tmp]# java hello
hello all
2.安装tomact
(1)解压
[root@tx1 ~]# tar zxvf apache-tomcat-6.0.16.tar.gz
[root@tx1 ~]# cp -a apache-tomcat-6.0.16 /usr/local/tomcat
(2)定义tomcat的环境变量:
[root@tx1 ~]# vim /etc/profile
CATALINA_BASE=/usr/local/tomcat
CATALINA_HOME=/usr/local/tomcat
PATH=$CATALINA_HOME/bin:$PATH
export CATALINA_BASE CATALINA_HOME PATH
[root@tx1 ~]# . /etc/profile
[root@tx1 bin]# pwd
/usr/local/tomcat/bin
[root@tx1 bin]# startup.sh //启动服务
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
测试
3.安装java论坛
[root@tx1 ]# tar zxvf JiveForumsPro4_crack.tar.gz
[root@tx1 ~]# cp -a jive/ /usr/local/tomcat/webapps/
4.安装mysql
[root@tx1 ~]# yum install -y mysql-server
[root@tx1 ~]# /etc/init.d/mysqld restart
[root@tx1 ~]# mysqladmin -u root password 123
[root@tx1 ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@tx1 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database jivedb; //创建数据库
Query OK, 1 row affected (0.00 sec)
mysql> grant all on jivedb.* to jiveuser@localhost identified by "123456";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;//更新权限
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@tx1 ~]# cd /usr/local/tomcat/webapps/jive/database
[root@tx1 database]# mysql -u root -p jivedb < jive_forums_mysql.sql
Enter password:
[root@tx1 database]#
安装mysql驱动
[root@tx1 ~]# tar zxvf mysql-connector-java-3.1.14.tar.gz
[root@tx1 ~]# cd mysql-connector-java-3.1.14
[root@tx1 mysql-connector-java-3.1.14]# cp mysql-connector-java-3.1.14-bin.jar /usr/local/tomcat/lib/
需要重启tomcat:
[root@tx1 ~]# . /etc/profile
[root@tx1 ~]# shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
[root@tx1 ~]# startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
三.apache与tomcat连接
[root@tx1 ~]# tar zxvf jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
[root@tx1 ~]# cp -r jakarta-tomcat-connectors-jk2-2.0.4-src /usr/local/tomcat-connect
[root@tx1 ~]# cd /usr/local/tomcat-connect/jk/native2
编译模块是有需求的:apxs
httpd-devel --> apxs
[root@tx1 ~]# yum install -y httpd httpd-devel
[root@tx1 native2]# which apxs
/usr/sbin/apxs
[root@tx1 native2] pwd
/usr/local/tomcat-connect/jk/native2
[root@tx1 native2]# ./configure --with-apxs2=/usr/sbin/apxs
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.//错误!!!
解决方法
[root@tx1 ~]# yum install gcc* -y
[root@tx1 native2]# ./configure --with-apxs2=/usr/sbin/apxs
[root@tx1 native2]# make
[root@tx1 native2]# make install
make: *** No rule to make target `install'. Stop.//错误!!!
解决方法
[root@tx1 native2]# cd /usr/local/tomcat-connect/jk/build/jk2/apache2
[root@tx1 apache2]# cp mod_jk2.so /etc/httpd/modules/
修改apache的配置文件,把新编译的模块添加进去:
[root@tx1 apache2]# vim /etc/httpd/conf/httpd.conf
200 LoadModule jk2_module modules/mod_jk2.so
[root@tx1 apache2]# cp /usr/local/tomcat-connect/jk/conf/workers2.properties /etc/httpd/conf/
[root@tx1 apache2]# vim /etc/httpd/conf/workers2.properties
[uri:/jive/*]
info=map the tomcat
[uri:/manager/*]
info=map the tomcat
[uri:/*.jsp]
info=map the tomcat
[root@tx1 apache2]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@tx1 apache2]# shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
[root@tx1 apache2]# startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
测试:如果你使用80端口能够访问jive论坛,那么成功。
本文出自 “tanxin” 博客,谢绝转载!