Linux安装Tomcat

Eave 2016.06.29 12:00

1、下载Tomcat

下载地址:https://tomcat.apache.org/download-90.cgi

2、安装Tomcat

$ tar -zxf apache-tomcat-9.0.10.tar.gz
$ mv apache-tomcat-9.0.10 /usr/local/tomcat

3、配置开机启动Tomcat

编辑/etc/init.d/tomcat文件,输入以下内容:

#!/bin/sh
#chkconfig:345 61 61
#description:tomac

start()
{
    /usr/local/tomcat/bin/startup.sh > /dev/null 2>&1
    echo -e $"Starting Tomcat:\t\t\t[\033[32m  OK  \033[0m]"
}

stop()
{
    /usr/local/tomcat/bin/shutdown.sh > /dev/null 2>&1
    echo -e $"Stopping Tomcat:\t\t\t[\033[32m  OK  \033[0m]"
}

restart()
{
    stop
    sleep 0.5
    start
}

version()
{
    echo "Tomcat version:"
    /usr/local/tomcat/bin/version.sh
}

case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        restart
        ;;
    version)
        version
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|version}"
        ;;
esac

修改/etc/init.d/tomcat文件的权限为755

$ chmod 755 /etc/init.d/tomcat

设置开机启动Tomcat

$ chkconfig --add tomcat
$ chkconfig tomcat on

4、启动Tomcat

$ /etc/init.d/tomcat start