在linux下搭建好tomcat之后,每次启动和关闭都要去tomcat的bin目录下执行./startup.sh和./shutdown.sh
这是很不方便的,下面介绍如何像执行ls mv cp等命令一样启动,关闭,重启tomcat
第一步创建脚本
脚本创建路径 /etc/init.d/tomcat
首先执行: vim /etc/init.d/tomcat
将下面内容根据你自己的情况(修改/usr/tomcat/apache-tomcat-8.5.23/bin为你的tomcat路径) d删除 y复制 p粘贴
# !/bin/bash # Description: start or stop the tomcat # Usage: tomcat [start|stop|restart] # export PATH=$PATH:$HOME/bin export BASH_ENV=$HOME/.bashrc export USERNAME="root" case "$1" in start) #startup the tomcat cd /usr/tomcat/apache-tomcat-8.5.23/bin ./startup.sh ;; stop) # stop tomcat cd /usr/tomcat/apache-tomcat-8.5.23/bin ./shutdown.sh echo "Tomcat Stoped" ;; restart) $0 stop $0 start ;; *) echo "tomcat: usage: tomcat [start|stop|restart]" exit 1 esac exit 0
添加执行权限
chmod +x /etc/init.d/tomcat
创建软链接
cd /usr/bin
ln -s /etc/init.d/tomcat
测试
tomcat start
tomcat stop
tomcat restart