linux环境下配置tomcat

时间:2022-03-14 15:13:09

1、到官方网站下载linux环境下的软件包:http://tomcat.apache.org/download-70.cgi,我下载的是apache-tomcat-7.0.55.tar.gz

2、copy到你的安装目录:sudo cp apache-tomcat-7.0.55.tar.gz /usr/local/soft 并解压sudo tar -zxvf apache-tomcat-7.0.55.tar.gz,然后重命名为tomcat7:sudo mv apache-tomcat-7.0.55 tomcat7

3、配置tomcat7

(1),打开/etc/profile: sudo gedit /etc/profile

(2)在文件最后加上以下配置

TOMCAT_HOME=/usr/local/soft/tomcat7
CATALINA_HOME=/usr/local/soft/tomcat7

export TOMCAT_HOME
export CATALINA_HOME

4、启动tomcat7

sudo /usr/local/soft/tomcat7/bin/startup.sh


进一步配置

进入到/usr/bin下

cd usr

cd bin

ln -s /usr/local/soft/tomcat7/bin/startup.sh

ln -s /usr/local/soft/tomcat7/bin/shutdown.sh


这样我们就可以进入到/usr/bin/下运行 ./startup.sh启动tomcat,./shutdown.sh停止tomcat了

我们也可以进行以下配置设置开机启动tomcat

sudo gedit /etc/rc.local

在文件中加入一下配置

JAVA_HOME=/usr/local/soft/jdk1.7.0_67
export JAVA_HOME
/usr/local/soft/tomcat7/bin/startup.sh

这样就可以开机启动tomcat了

编写启动脚本

#!/bin/bash
#filename tomcat7.sh
TOMCAT_HOME=/usr/local/soft/tomcat7
start_tomcat=$TOMCAT_HOME/bin/startup.sh
stop_tomcat=$TOMCAT_HOME/bin/shutdown.sh


start(){
  echo -n "Starting tomcat7 : "
  ${start_tomcat}
  echo "tomcat7 started ok!!"
}


stop(){
  echo -n "Shutdown tomcat7 : "
  ${stop_tomcat}
  echo "tomcat7 stop ok!!"
}


case $1 in
        start)
                start
                ;;
        stop)
                stop

  ;;
        restart)
                stop
                sleep 10
                start
                ;;
        *)
        echo "Usage:$0{start|stop|restart}"
esac
exit 0