相信你已经看过之前的文章了,那么这一篇文章就很容易理解了。如果你的基础不太好,暂时理解不了也没关系,先保存下来,后面基础补一补在回过头来看看。
Tomcat + MySQL
========================================================
方案一: Tomcat Tomcat1
方案二: Apache (负载均衡器) Tomcat2
Tomcat3
Tomcat1
方案三: Nginx (负载均衡器) Tomcat2
Tomcat3
========================================================
一、Tomcat Http Server
1. JAVA环境
[root@Tomcat ~]# java -version
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
[root@Tomcat ~]# vim /etc/profile
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH
[root@Tomcat ~]# source /etc/profile
[root@Tomcat ~]# env |grep JAVA
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/
2. Tomcat
安装Tomcat
[root@master jsp]# tar xf apache-tomcat-7.0.34.tar.gz -C /usr/local/
[root@master jsp]# cd /usr/local/
[root@master local]# ln -s apache-tomcat-7.0.34/ tomcat
定义Tomcat所需的环境变量
[root@master local]# vim /etc/profile //定义Tomcat环境变量
CATALINA_HOME=/usr/local/tomcat //Tomcat安装目录
export CATALINA_HOME
[root@master local]# source /etc/profile
[root@master local]# env |grep HOME
CATALINA_HOME=/usr/local/tomcat
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/
HOME=/root
启动Tomcat
方法一:
[root@master ~]# /usr/local/tomcat/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/java/jdk1.7.0_11
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@master ~]# netstat -tnlp |grep java
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 6191/java
tcp 0 0 :::8009 :::* LISTEN 6191/java
tcp 0 0 :::8080 :::* LISTEN 6191/java
[root@master ~]# /usr/local/tomcat/bin/shutdown.sh //停止
========================================================
方法二:System V脚本
#[root@master ~]# vim /etc/init.d/tomcat
#!/bin/bash
# Init file for Tomcat server daemon
#
# chkconfig: 2345 96 14
# description: Tomcat server daemon
JAVA_OPTS='-Xms64m -Xmx128m'
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/
CATALINA_HOME=/usr/local/tomcat
export JAVA_OPTS JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh $*
[root@master ~]# chmod a+x /etc/init.d/tomcat
[root@master ~]# chkconfig --add tomcat
[root@master ~]# chkconfig tomcat --list
tomcat 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@master ~]# chkconfig tomcat on
[root@master ~]#
[root@master ~]# service tomcat stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@master ~]# 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/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
========================================================
3. 测试
http://192.168.2.251:8080/
二、Tomcat连接MySQL
1. 安装MySQL(见上一篇文章,如何编译mysql)
2. 为Tomcat提供连接Mysql的类文件
[root@master jsp]# tar xf mysql-connector-java-5.0.8.tar.gz
[root@master jsp]# cd mysql-connector-java-5.0.8
[root@master mysql-connector-java-5.0.8]# cp mysql-connector-java-5.0.8-bin.jar /usr/local/tomcat/lib/
[root@master jsp]# service tomcat stop
[root@master jsp]# service tomcat start
三、部署JavaCenter_Home
1. Tomcat默认的网站目录
[root@master jsp]# ls /usr/local/tomcat/webapps/ //默认网站的基目录base
docs examples host-manager manager ROOT
[root@master jsp]# ls /usr/local/tomcat/webapps/ROOT //默认网站的主目录
asf-logo.png bg-nav-item.png favicon.ico tomcat.gif WEB-INF
asf-logo-wide.gif bg-nav.png index.jsp tomcat.png
bg-button.png bg-upper.png RELEASE-NOTES.txt tomcat-power.gif
bg-middle.png build.xml tomcat.css tomcat.svg
[root@master ~]# cd /usr/local/tomcat/webapps/ROOT/
[root@master ROOT]# rm -rf * //删除默认网站内容
2. 部署JavaCenter_Home
[root@master jsp]# unzip JavaCenter_Home_2.0_Source_UTF8
[root@master jsp]# cd JavaCenter_Home_2.0_Source_UTF8
[root@master JavaCenter_Home_2.0_Source_UTF8]# ls
source
[root@master JavaCenter_Home_2.0_Source_UTF8]# cd source/
[root@master source]# ls
src WebRoot
[root@master source]# cd WebRoot/
[root@master WebRoot]#
[root@master WebRoot]# ls
admin attachment cp.jsp editor.jsp image js.jsp network.jsp template xmlrpc.jsp
admincp.jsp avatar.jsp crossdomain.xml errors index.jsp link.jsp rss.jsp theme
api config.properties data favicon.ico install magic.jsp source userapp.jsp
app.jsp contact.jsp do.jsp help.jsp invite.jsp META-INF space.jsp WEB-INF
[root@master WebRoot]# cp -rf * /usr/local/tomcat/webapps/ROOT/
[root@master source]# service tomcat stop
[root@master source]# service tomcat start
http://www.blog.com //是否支持连接数据库
http://www.blog.com/install //导库、连库