linux版本:CentOS 6.2iso文件下載地址:http://mirrors.163.com/centos/6.2/isos/i386/CentOS-6.2-i386-bin-DVD1.iso
1. 安裝JDK先用java命令查看系統是否安裝了默認的openJDK,如果已安裝,建議用yum remove java卸載之。下載jdk:wget –chttp://download.oracle.com/otn-pub/java/jdk/7u5-b05/jdk-7u5-linux-i586.rpm安裝:rpm –ivh jdk-7u5-linux-i586.rpm配置環境變量(等到tomcat安裝好之後一起配置)
2. 安裝tomcatTomca下載地址:http://apache.etoak.com/tomcat/tomcat-7/v7.0.28/bin/apache-tomcat-7.0.28.tar.gz下載後解壓:tar -zxvf apache-tomcat-7.0.28移動到/usr/local/tomcat7:mv apache-tomcat-7.0.28 /usr/local/tomcat7設置目錄可執行權限 chmod +x /usr/local/tomcat7
配置環境變量 編輯profile文件:vim /etc/profile在文件中添加以下代碼:
export JAVA_HOME = /usr/java/jdk1.7.0_05
export CALSSPATH = $JAVA_HOME/lib/*.*
export PATH = $PATH:$JAVA_HOME/bin
export TOMCAT_HOME=/usr/local/tomcat7
export CATALINA_HOME=/usr/local/tomcat7
保存文件退出編輯。
使設置立即生效:source /etc/profile
至此,tomcat已經搭建完畢,下面所述的步驟主要是對tomcat的相關設置。
啟動tomcat: sh startup.sh 或者 sh /usr/local/tomcat7/bin/startup.sh此時可在浏覽器查看http://localhost:8080,如果沒有圖形界面,則需要打開端口才可訪問。打開防火牆端口命令如下:/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT #8080為端口/etc/rc.d/init.d/iptables save #保存/etc/init.d/iptables restart #重啟防火牆使得立即生效也可以在/etc/sysconfig/iptables文件中增加一行信息,-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT查看防火牆狀態的命令:/etc/init.d/iptables status關閉防火牆的命令:/etc/init.d/iptables stop修改tomcat端口為80
修改/usr/local/tomcat6/apache-tomcat-6.0.20/conf/中的server.xml文件將端口改為80
開啟80端口
在/etc/sysconfig/iptables中開放80端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 開機啟動
在/etc/rc.d/init.d中添加tomcat的啟動文件。#!/bin/bash
#
# tomcatd This shell script takes care of starting and stopping
# standalone tomcat
# chkconfig: 345 91 10
# description: tomcat service
# processname: tomcatd
# config file:# Source function library.
. /etc/rc.d/init.d/functions# Source networking configuration.
. /etc/sysconfig/network# Check that networking is up.
[ = "no" ] && exit 0prog=tomcatdexport JAVA_HOME=/usr/local/jdk/jdk1.7.0_05
export CATALINA_HOME=/usr/local/tomcat7
PATH=$PATH:$JAVA_HOME/binSTARTUP=$CATALINA_HOME/bin/startup.sh
SHUTDOWN=$CATALINA_HOME/bin/shutdown.shif [ ! -f $CATALINA_HOME/bin/startup.sh ]
then
echo "CATALINA_HOME for tomcatd not available"
exit
fistart() {
# Start daemons. echo -n $"Startting tomcat service: "
su - root -c $STARTUP
RETVAL=$?
return $RETVAL
}stop() {
# Stop daemons.
echo -n $"Stoping tomcat service: "
su - root -c $SHUTDOWN
RETVAL=$?
return $RETVAL
}# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esacexit $RETVAL將tomcat的默認字符編碼設置為UTF-8
在tomcat目錄下conf文件夾下的server.xml中添加
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
在tomcat下的lib文件夾中加入mysql的連接包修改catalina.sh
有時WEB系統比較大要添加tomcat的內存
if [ -z "$LOGGING_MANAGER" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi# ----- Execute The Requested Command -----------------------------------------
JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx512m -XX:MaxNewSize=512m -XX:MaxPermSize=512m"Tomcat管理用戶密碼設置,修改文件 tomcat/conf/tomcat-users.xml<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<user username="Tomcat" password="Tomcat" roles="admin-gui,admin,manager-gui,manager"/> 保存後重啟,即可登錄tomcat管理頁面。
本文出自 “夢想照進現實” 博客,請務必保留此出處http://lookingdream.blog.51cto.com/5177800/1833084