分类: LINUX
2009-12-22 13:43:21
1、操作系统:Redhat AS4 update 2
2、软件包
jdk-1_5_0_09-linux-i586-rpm.bin
apache-tomcat-
存取软件包
#scp /opt
#scp /opt
3、配置环境
字符集、时区配置
1. 设定系统语言环境:/etc/sysconfig/i18n为zh_CN.GBK
#vi /etc/sysconfig/i18n
LANG="zh_CN.GBK"
SUPPORTED="zh_CN.GBK:zh:zh_CN.GB2312:zh:zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
2. 修改字符集设置:/etc/profile里面添加NLS_LANG设置
#vi /etc/profile
export NLS_LANG='SIMPLIFIED CHINESE_CHINA'.ZHS16GBK
3. 检查服务器的时区与时间是否为正确时区:China standard Time(CST) 中国标准时间。
#cat /etc/sysconfig/clock
看是否有以下3行显示
ZONE="Asia/Shanghai"
UTC=false
ARC=false
如果不是的话则需要做下面的修改步骤(或者执行timeconfig):
#mv /etc/localtime /etc/localtime.bak
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
将时区文件(/etc/sysconfig/clock)更改为以下内容:
ZONE=Asia/Shanghai
UTC=false
ARC=false
4、安装JDK
#cd /opt
#chmod a+x jdk-1_5_0_09-linux-i586-rpm.bin
#./jdk-1_5_0_09-linux-i586-rpm.bin
......
依照提示安装选择yes即可
#rpm -ivh jdk-1_5_0_09-linux-i586.rpm
rpm默认是安装在/usr/java目录下的
#cd /usr/java
#mv jdk
删除多余的空目录
#rmdir /usr/java
#vi /etc/profile
加入:
JAVA_HOME=/usr/local/XXX/jdk
CLASSPATH=$JAVA_HOME/jre/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
NLS_LANG='SIMPLIFIED CHINESE_CHINA'.ZHS16GBK
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin:$JAVA_HOME/jre/bin
注意:
$JAVA_HOME/bin:要放在最前面因为这个才是我们安装的jdk的路径,开发的程序一般都执行这个路径下的JDK.如果不放在最前面,执行的就有可能是系统自带的JDK了,有些时候会因为路径错误而报错。
删除系统原来的export这一行,加入如下一行:
export JAVA_HOME CLASSPATH PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC NLS_LANG
测试jdk路径
echo $JAVA_HOME
//查看jdk安装的根目录,我机器上的输出信息是
:/usr/local/caixun/jdk
echo $CLASSPATH
//查看环境变量,我机器上的输出信息是
:/usr/local/XXX/jdk
echo $PATH //查看路径,我机器上的输出信息是
:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/usr/local/caixun/jdk
备份源文件
# mv /usr/bin/java /usr/bin/java.bak
# mv /usr/bin/javac /usr/bin/javac.bak
注销环境
#su -
# java
# javac
查看版本号
#java -version
如果java 和javac运行了,说明java环境变量配置成功。
5、安装TOMCAT
#cd /opt
#tar zxvf apache-tomcat-
#mv apache-tomcat-
运行tomcat
#/usr/local/caixun/apache-tomcat-
使用IE测试:lynx 有画面则安装成功
性能优化:
修改/usr/local/XXX/apache-tomcat-
#vi /usr/local/XXX/apache-tomcat-
找到下面的配置修改:(76行)
maxThreads="300" minSpareThreads="150" maxSpareThreads="200"
enableLookups="false" redirectPort="8443" acceptCount="200"
connectionTimeout="20000" disableUploadTimeout="true" debug="0" />
保存后离开
修改/usr/local/caixun/apache-tomcat-
#vi /usr/local/caixun/apache-tomcat-
找到下面:
# JRE_HOME Must point at your Java Development Kit installation.
# Defaults to JAVA_HOME if empty.
#
# JAVA_OPTS (Optional) Java runtime options used when the "start",
# "stop", or "run" command is executed.
插入“JAVA_OPTS='-Xms
# JRE_HOME Must point at your Java Development Kit installation.
# Defaults to JAVA_HOME if empty.
#
# JAVA_OPTS (Optional) Java runtime options used when the "start",
# "stop", or "run" command is executed.
JAVA_OPTS='-Xms
保存后离开
6、用jsvc脚本让Tomcat自启动。
1.安装jsvc
#cd /usr/local/XXX/apache-tomcat-
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#sh support/buildconf.sh
#chmod 755 configure
#./configure --with-java=/usr/local/XXX/jdk
#make
2、添加脚本让tomcat自动启动
#useradd tomcat5 添加用户
#groupadd tomcat 添加组
#usermod -G tomcat tomcat5 把tomcat5加入tomcat组
#chown -R tomcat5 /usr/local/XXX/apache-tomcat-
#cp /usr/local/XXX/apache-tomcat-
#chmod 755 /etc/init.d/tomcat
#vi /etc/init.d/tomcat
删除原有内容添加如下内容,注意jdk路径
#!/bin/sh
#
# Startup Script for Tomcat5
#
# chkconfig: 345 88 14
# description: Tomcat Daemon
# processname: jsvc
# pidfile: /var/run/jsvc.pid
# config:
#
# Source function library.
. /etc/rc.d/init.d/functions
#
prog=tomcat
#
JAVA_HOME=/usr/local/XXX/jdk
CATALINA_HOME=/usr/local/XXX/apache-tomcat-
DAEMON_HOME=/usr/local/XXX/apache-tomcat-
#TOMCAT_USER=tomcat5
TOMCAT_USER=tomcat5
# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/local/XXX/apache-tomcat-
CATALINA_OPTS=
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
case "$1" in
start)
#
# Start Tomcat
#
$DAEMON_HOME/jsvc-src/jsvc \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
-wait 10 \
-pidfile $PID_FILE \
-outfile $CATALINA_HOME/logs/catalina.out \
-errfile '&1' \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap
#
# To get a verbose JVM
#-verbose \
# To get a debug of jsvc.
#-debug \
exit $?
;;
stop)
#
# Stop Tomcat
#
$DAEMON_HOME/jsvc-src/jsvc \
-stop \
-pidfile $PID_FILE \
org.apache.catalina.startup.Bootstrap
exit $?
;;
*)
echo "Usage tomcat.sh start/stop"
exit 1;;
esac
#service tomcat start 测试tomcat能不能启动
#chkconfig tomcat on
#chkconfig --list tomcat
完成自启动脚本