您好,登錄后才能下訂單哦!
這篇文章主要講解了“java環境中怎么使用tomcat+mysql技術”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“java環境中怎么使用tomcat+mysql技術”吧!
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
感謝各位的閱讀,以上就是“java環境中怎么使用tomcat+mysql技術”的內容了,經過本文的學習后,相信大家對java環境中怎么使用tomcat+mysql技術這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。