Tomcat 部署


1、JDK的安装

版本:jdk-7-linux-x64.tar.gz

下载:http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz

JDK(Java Development Kit)是Sun Microsystems针对Java开发员的产品。自从Java推出以来,JDK已经成为使用最广泛的Java SDK。JDK 是整个Java的核心,包括了Java运行环境、Java工具和Java基础类库。

1)建立JDK存放的目录

# mkdir -pv /opt/java/jvm

2)解压到/opt/java/jvm下

# tar xf jdk-7-linux-x64.tar.gz -C /opt/java/jvm/

# ll /opt/java/jvm/


3)java环境变量设置(vi /etc/profile 在末行加入下面四条)


# vi /etc/profile

JAVA_HOME=/opt/java/jvm/jdk1.7.0

PATH=$JAVA_HOME/bin:$PATH:$HOME/bin

CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar

export PATH JAVA_HOME CLASSPATH CATALINA_HOME


注:表格中是需要输入的内容

4)执行刚才的脚本,使配置文件生效

# source /etc/profile

# java -version


Tomcat install

wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz


# tar xf apache-tomcat-7.0.47.tar.gz

# mv apache-tomcat-7.0.47 /opt/tomcat

启动tomcat

# /opt/tomcat/bin/startup.sh

用浏览器访问本地的8080看到那只猫就成功了


编写测试页面

# cd /opt/tomcat/webapps/ROOT/

# echo '<%= new java.util.Date() %>' > test.jsp


http://ip:8080/test.jsp

看到当前时间就ok了!


关闭tomcat

# /opt/tomcat/bin/shutdown.sh


service管理脚本:

# vim /etc/init.d/tomcat

#!/bin/bash

#

# tomcat7 This shell script takes care of starting and stopping Tomcat

#

# chkconfig: - 80 20

#

### BEGIN INIT INFO

# Provides: tomcat7

# Required-Start: $network $syslog

# Required-Stop: $network $syslog

# Default-Start:

# Default-Stop:

# Description: Release implementation for Servlet 2.5 and JSP 2.1

# Short-Description: start and stop tomcat

### END INIT INFO


## Source function library.

#. /etc/rc.d/init.d/functions

export JAVA_HOME=/opt/java/jvm/jdk1.7.0

export JAVA_OPTS="-Dfile.encoding=UTF-8 \

-Dcatalina.logbase=/var/log/tomcat7 \

-Dnet.sf.ehcache.skipUpdateCheck=true \

-XX:+DoEscapeAnalysis \

-XX:+UseConcMarkSweepGC \

-XX:+CMSClassUnloadingEnabled \

-XX:+UseParNewGC \

-XX:MaxPermSize=128m \

-Xms512m -Xmx512m"

export PATH=$JAVA_HOME/bin:$PATH

TOMCAT_HOME=/opt/tomcat7

SHUTDOWN_WAIT=10

tomcat_pid() {

echo `ps aux|grep org.apache.catalina.startup.Bootstrap|grep -v grep | awk '{ print $2 }'`

}

start() {

pid=$(tomcat_pid)

if [ -n "$pid" ]

then

echo "Tomcat is already running (pid: $pid)"

else

# Start tomcat

echo "Starting tomcat"

ulimit -n 100000

/bin/sh $TOMCAT_HOME/bin/startup.sh

fi

return 0

}

stop() {

pid=$(tomcat_pid)

if [ -n "$pid" ]

then

echo "Stoping Tomcat"

/bin/sh $TOMCAT_HOME/bin/shutdown.sh


let kwait=$SHUTDOWN_WAIT

count=0;

until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]

do

echo -n -e "\nwaiting for processes to exit";

sleep 1

let count=$count+1;

done


if [ $count -gt $kwait ]; then

echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"

kill -9 $pid

fi

else

echo "Tomcat is not running"

fi

return 0

}


case $1 in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

status)

pid=$(tomcat_pid)

if [ -n "$pid" ]

then

echo "Tomcat is running with pid: $pid"

else

echo "Tomcat is not running"

fi

;;

esac

exit 0

# chmod +x /etc/init.d/tomcat

# chkconfig tomcat on


tomcat cronolog 切割

wget http://cronolog.org/download/cronolog-1.6.2.tar.gz


# tar zxvf cronolog-1.6.2.tar.gz

# cd cronolog-1.6.2

# ./configure --prefix=/opt/cronolog

# make

# make install


修改tomcat bin目录下的catalina.sh文件中的

Java代码

org.apache.catalina.startup.Bootstrap “$@” start \

>> "$CATALINA_BASE"/logs/catalina.out 2>&1 &


Java代码 (位置大概在392行左右,修改else后面那个,一般用security启动)


org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \

| /opt/cronolog/sbin/cronolog "$CATALINA_OUT" >> /dev/null &



# touch "$CATALINA_OUT" 将这行注释掉