一、安装jdk
tar zxvf jdk.tar.gz #解压缩
mv jdk1.7.0_72 /usr/local/java #改名#移动
vi /etc/profile
#末尾加入:
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source /etc/profile
java -version
二、安装tomcat7
tar zxvf tomcat7.tar.gz
mv apache-tomcat-7.0.55 /usr/local/tomcat7
cd /usr/local/tomcat7
rm -rf ./webapps
mkdir ./webapps
设置自动启动
建立一个启动脚本:
vi /etc/init.d/tomcat
内容为:
#!/bin/bash
# Tomcat auto-start
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid
export JAVA_HOME=/usr/local/java
case $1 in
start)
sh /usr/local/tomcat7/bin/startup.sh
;;
stop)
sh /usr/local/tomcat7/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat7/bin/shutdown.sh
sh /usr/local/tomcat7/bin/startup.sh
;;
esac
exit 0
chmod 755 /etc/init.d/tomcat
添加到系统自服务:
update-rc.d -f tomcat defaults
service tomcat start/stop
修改jvm启动参数:
修改catalina.sh,注释后增加
JAVA_OPTS="$JAVA_OPTS -Xms2g -Xmx2g -Xmn768m -XX:PermSize=128m -XX:MaxPermSize=128m -XX:+UseConcMarkSweepGC -Djava.security.egd=file:/dev/./urandom"
//开启JMC远程访问和flight record
-Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=10.168.226.158 -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
-Duser.timezone=GMT+8 //时区
-Dfile.encoding=utf-8 //文件编码
注意:
-Djava.security.egd=file:/dev/./urandom 用于解决阻塞式随机数生成所引发的启动缓慢问题