ubuntu配置jdk和tomcat+部署java项目[最佳实践]
2013-12-26 15:48 低调de草原狼 阅读(258) 评论(0) 编辑 收藏 举报每次裸机上配置一次jdk和tomcat,都要查询一次,真心麻烦,我想应该是要记下来并且以防自己以后会忘记,本文将从jdk,tomcat安装一直到最后的部署,全部记录一下,同时如果有朋友也是处于这样的情况,那么本文将会是最佳实践
版本:jdk1.7、tomcat7.0,有关下载,在此就不多说了
jdk的配置:
在/etc/profile文件的最后加上
# jdk JAVA_HOME=/root/soft/jdk1.7.0_10 PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar CATALINA_HOME=/root/guard/apache-tomcat-7.0.22 export JAVA_HOME export PATH export CLASSPATH export CATALINA_HOME
完成后source /etc/profile即可
测试:java -version
java version "1.7.0_10" Java(TM) SE Runtime Environment (build 1.7.0_10-b18) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
好的,这样jdk首先就配置好了
tomcat中server.xml的配置:
配置端口:
<Connector port="80" URIEncoding="UTF-8" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="5000" minSpareThreads="10" maxSpareThreads="50" acceptCount="1024" enableLookups="false" connectionTimeout="20000" redirectPort="8443"/>
配置Host:
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Alias>119.90.0.165</Alias> <Context docBase="/root/guard/apache-tomcat-7.0.22/project/guard2.0" path="" reloadable="true"/> </Host>
将bin目录下startup.sh、shutdown.sh、catalina.sh改为可执行权限,
当你startup.sh一下以后,在logs目录下会生成catalina.out的文件,将其改为可执行权限
当你启动的时候,可能会遇到内存溢出的报错,那么这个时候你需要修改下catalina.sh文件中
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
if [ $have_tty -eq 1 ]; then
JAVA_OPTS="$JAVA_OPTS -server -XX:PermSize=128M -XX:MaxPermSize=512m"
echo "Using CATALINA_BASE: $CATALINA_BASE"
echo "Using CATALINA_HOME: $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
if [ "$1" = "debug" ] ; then
echo "Using JAVA_HOME: $JAVA_HOME"
else
echo "Using JRE_HOME: $JRE_HOME"
fi
echo "Using CLASSPATH: $CLASSPATH"
if [ ! -z "$CATALINA_PID" ]; then
echo "Using CATALINA_PID: $CATALINA_PID"
fi
接下来,启动 在tomcat的路径下,启动命令为:
sh startup.sh && tail -f logs/catalina.out (&& 后边的命令可以查看启动日志)
停止服务:
sh shutdown.sh