Linux下安装配置tomcat
1、 安装
Tomcat版本:6.0.29
Linux版本:Radhat Enterprise 5.5
Jdk版本:1.6.0_20
解压缩tomcat
#tar –zxvf apache-tomcat-6.0.
安装jdk
#rpm –ivh jdk-6u20-linux-i586.rpm
创建用户和组并设置目录权限
[root@centos data]# useradd tomcat
[root@centos data]# groupadd tomcat
[root@centos data]# chown -R tomcat:tomcat apache-tomcat-6.0.32
2、 设置
1)、 设置路经
使用命令编辑vi /etc/profile,在文件中加入如下几行
JAVA_HOME=/usr/java/jdk1.6.0_20
CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar:$CLASS_PATH
PATH=$JAVA_HOME/bin:$PATH
TOMCAT_HOME=/opt/apache-tomcat-6.0.32
CATALINA_HOME=$TOMCAT_HOME
PATH=$TOMCAT_HOME/bin:$PATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC CLASS_PATH JAVA_HOME TOMCAT_HOME CATALINA_HOME
到/opt/apache-tomcat-6.0.32/conf下,把以下几句加入startup.sh和shutdown.sh两个文件
JAVA_HOME=/usr/java/jdk1.6.0_20
CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar:$CLASS_PATH
linux安装jdk16PATH=$JAVA_HOME/bin:$PATH
TOMCAT_HOME=/opt/apache-tomcat-6.0.32
CATALINA_HOME=$TOMCAT_HOME
PATH=$TOMCAT_HOME/bin:$PATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC CLASS_PATH JAVA_HOME TOMCAT_HOME CATALINA_HOME
2)、 设置IP和Port
Tomcat缺省的Port number是8080.打开文件tomcat/l,到如下的字段:
“<Connector port=8080“
然后把8080改成80即可.
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
address="192.168.89.15" />
3)、 设置Tomcat管理用户
[root@linux5 conf]# l
<role rolename="admin”>
<user username="admin" password="admin" roles="admin,manager"/>
3、 启动tomcat
重启电脑后启动tomcat:
[root@linux5 bin]# pwd
/opt/apache-tomcat-6.0.32/bin
[root@linux5 bin]# ./startup.sh
Using CATALINA_BASE: /opt/apache-tomcat-6.0.32
Using CATALINA_HOME: /opt/apache-tomcat-6.0.32
Using CATALINA_TMPDIR: /opt/apache-tomcat-6.0.32/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-6.0.32/bin/bootstrap.jar
关闭tomcat:
[root@linux5 bin]# ./shutdown.sh
Using CATALINA_BASE: /opt/apache-tomcat-6.0.32
Using CATALINA_HOME: /opt/apache-tomcat-6.0.32
Using CATALINA_TMPDIR: /opt/apache-tomcat-6.0.32/temp
Using JRE_HOME: /usr/java/jdk1.6.0_20
Using CLASSPATH: /opt/apache-tomcat-6.0.32/bin/bootstrap.jar
4、 开机自动启动tomcat设置
[root@linux5 ~]# cd /etc/rc.d/init.d/
[root@linux5 init.d]# vi tomcat
以下为启动脚本内容
# !/bin/sh
# chkconfig: 345 90 11
# description: Starts and stops Tomcat (running as root)
TOMCAT_BIN=/data/apache-tomcat-6.0.32/bin
TOMCAT_USER=root
RETVAL=0
start() {
stop
su - $TOMCAT_USER -c $TOMCAT_BIN/startup.sh
sleep 10
if netstat -an | grep -w 80 >/dev/null
then
echo "Tomcat is running"
return 0
else
return 1
fi
}
stop() {
if netstat -an | grep -w 80 | grep LISTEN >/dev/null
then
# try to shutdown the server first
echo "Now Shutdown "
su - $TOMCAT_USER -c $TOMCAT_BIN/shutdown.sh
else
echo "Tomcat is not running"
return 0
fi
if netstat -an | grep -w 80 | grep LISTEN
then
sleep 10
echo "Now kill it"
ps -ef | grep java | grep $TOMCAT_USER | awk '{print "kill -9 ", $2;}' | sh
fi
if netstat -an | grep -w 80 | grep LISTEN >/dev/null
then
return 1 # still alive
else
echo "Tomcat is stopped"
return 0
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
start
;;
status)
if netstat -an |grep -w 80|grep LISTEN >/dev/null
then
echo "Tomcat is Running"
else
echo "Tomcat is Not Running"
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
[root@linux5 init.d]# chmod 755 tomcat
[root@linux5 init.d]# chkconfig --add tomcat
[root@linux5 init.d]# chkconfig --level 345 tomcat on
5、 日常启动关闭
启动:
[root@centos ~]# tomcat start
Tomcat is not running
Using CATALINA_BASE: /data/apache-tomcat-6.0.32
Using CATALINA_HOME: /data/apache-tomcat-6.0.32
Using CATALINA_TMPDIR: /data/apache-tomcat-6.0.32/temp
Using JRE_HOME: /usr/java/jdk1.6.0_22
Using CLASSPATH: /data/apache-tomcat-6.0.32/bin/bootstrap.jar
Tomcat is running
关闭:
[root@centos ~]# tomcat stop
Now Shutdown
Using CATALINA_BASE: /data/apache-tomcat-6.0.32
Using CATALINA_HOME: /data/apache-tomcat-6.0.32
Using CATALINA_TMPDIR: /data/apache-tomcat-6.0.32/temp
Using JRE_HOME: /usr/java/jdk1.6.0_22
Using CLASSPATH: /data/apache-tomcat-6.0.32/bin/bootstrap.jar
tcp 0 0 :::80 :::* LISTEN
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论