admin 管理员组

文章数量: 887021


2024年1月22日发(作者:新闻类网站宣传h5模板)

Linux下安装配置tomcat

1、 安装

Tomcat版本:6.0.29

Linux版本:Radhat Enterprise 5.5

Jdk版本:1.6.0_20

解压缩tomcat

#tar –

安装jdk

#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/:$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下,把以下几句加入和两个文件

JAVA_HOME=/usr/java/jdk1.6.0_20

CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/:$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

2)、设置IP和Port

Tomcat缺省的Port number是8080.打开文件tomcat/conf/,找到如下的字段:

然后把8080改成80即可.

connectionTimeout="20000"

redirectPort="8443"

address="192.168.89.15" />

3)、设置Tomcat管理用户

[root@linux5 conf]# vi

3、 启动tomcat

重启电脑后启动tomcat:

[root@linux5 bin]# pwd

/opt/apache-tomcat-6.0.32/bin

[root@linux5 bin]# ./

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/

关闭tomcat:

[root@linux5 bin]# ./

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/

[root@linux5 ~]#cd /etc/rc.d/init.d/

[root@linux5 init.d]# vi tomcat

以下为启动脚本内容

4、 开机自动启动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/

sleep 10

ifnetstat -an | grep -w 80 >/dev/null

then

echo "Tomcat is running"

return 0

else

return 1

fi

}

stop() {

ifnetstat -an | grep -w 80 | grep LISTEN >/dev/null

then

# try to shutdown the server first

echo "Now Shutdown "

su - $TOMCAT_USER -c $TOMCAT_BIN/

else

echo "Tomcat is not running"

return 0

fi

ifnetstat -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

ifnetstat -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)

ifnetstat -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/

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/

tcp 0 0 :::80

LISTEN

Now kill it

查看状态:

[root@centos ~]# tomcat status

Tomcat is Running

:::*


本文标签: 设置 启动 文件 用户