Linux下Tomcat的安装配置
一.下载安装对应的jdk,并配置Java环境。
以root权限建立“tomcat”用户,然后把jdk上传到tomcat用户下
给jdk-6u5-linux-x64.bin授权:
[tomcat@localhost~]$chmod 755 jdk-6u5-linux-x64.bin
执行解压jdk-6u5-linux-x64.bin
[tomcat@localhost~]$ ./jdk-6u5-linux-x64.bin
以root权限把解压出来的jdk放到/usr/local目录下如:
[root@localhosttomcat]#mv jdk1.6.0_45 /usr/local
配置环境变量:
在/home/tomcat /.bash_profile中加入以下内容:
[tomcat@localhost~]$vi /home/tomcat/.bash_profile
export JAVA_HOME=/usr/local/jdk1.6.0_45
export PATH=:$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
保存退出
首先按一下“Esc”然后以“:wq!”回车进行保存退出
然后在执行一下这个文件,命令如下:
[tomcat@localhost~]$source /home/tomcat /.bash_profile
查看java环境变量是否生效
[tomcat@localhost~]$ java -version
javaversion "1.6.0_45"
Java(TM)SE Runtime Environment (build 1.6.0_45-b06)
JavaHotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)
测试成功
二.下载安装tomcat(http://tomcat.apache.org/)
把下载的tomcat压缩包上传到tomcat用户下,然后根据不同安装包进行解压:
[tomcat@localhost~]$ unzip apache-tomcat-6.0.43.zip
或
[tomcat@localhost~]$tar –zxvf apache-tomcat-6.0.43.tar.gz
[tomcat@localhost~]$ cd apache-tomcat-6.0.43/bin
[tomcat@localhostbin]$chmod +x *.sh
配置内存大小
[tomcat@localhostbin]$vi catalina.sh
添加:
JAVA_OPTS="-Xms512m-Xmx1024m -XX:PermSize=256M -XX:MaxNewSize=512m -XX:MaxPermSize=512m-Djava.awt.headless=true"
或者
JAVA_OPTS="-Xms2048m –Xmx4096m-XX:PermSize=2048M -XX:MaxNewSize=2048m -XX:MaxPermSize=2048m-Djava.awt.headless=true"
根据实际情况添加内存大小
启动tomcat同时输出日志
正常情况下,执行startup.sh脚本启动tomcat,
执行结果如下:
[tomcat@localhost bin]$ ./startup.sh Using CATALINA_BASE: /home/tomcat/apache-tomcat-6.0.43 Using CATALINA_HOME: /home/tomcat/apache-tomcat-6.0.43 Using CATALINA_TMPDIR: /home/tomcat/apache-tomcat-6.0.43/temp Using JRE_HOME: /usr/local/jdk1.6.0_45 Using CLASSPATH: /home/tomcat/apache-tomcat-6.0.43/bin/bootstrap.jar [tomcat@localhost bin]$ |
要查看日志,还得cd 到logs目录下,然后执行tai -f命令才能查看日志,多了几步操作。如果能够在执行脚本的同时输出日志,是不是可以稍微提高一点点工作效率,接下来就设置一下:
[tomcat@localhostbin]$ vi catalina.sh
elif [ "$1" = "start" ] ; then ........................... if [ "$1" = "-security" ] ; then if [ $have_tty -eq 1 ]; then echo "Using Security Manager" fi shift "$_RUNJAVA" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ -Djava.security.manager \ -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \ -Dcatalina.base="$CATALINA_BASE" \ -Dcatalina.home="$CATALINA_HOME" \ -Djava.io.tmpdir="$CATALINA_TMPDIR" \ org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 & tail -f ${CATALINA_OUT} else "$_RUNJAVA" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ -Dcatalina.base="$CATALINA_BASE" \ -Dcatalina.home="$CATALINA_HOME" \ -Djava.io.tmpdir="$CATALINA_TMPDIR" \ org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 & tail -f ${CATALINA_OUT} fi |
再次启动tomcat,
[tomcat@localhost bin]$ nohup ./startup.sh & [2] 29643 [tomcat@localhost bin]$ nohup: 忽略输入并把输出追加到"nohup.out" [tomcat@localhost bin]$ tail -f nohup.out 2015-2-1 17:06:36 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8009 2015-2-1 17:06:36 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/32 config=null 2015-2-1 17:06:36 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/32 config=null 2015-2-1 17:06:36 org.apache.catalina.startup.Catalina start 信息: Server startup in 1148 ms 2015-2-1 17:06:36 org.apache.catalina.startup.Catalina start 信息: Server startup in 1148 ms |
日志输出了,OK,搞定!
启动tomcat服务命令:
[tomcat@localhostbin] nohup ./start.sh &
查看tomcat启动日志命令:
[tomcat@localhostbin]tail –f nohup.out