目标:
安装Tomcat,设置Tomcat开机自启
安装步骤:(采用解压方式安装)
1.创建一个tomcat目录cd /usr/local
mkdir tomcat
cd tomcat
2.使用上传工具将tomcat压缩版添加到当前目录
解压目录
tar -zxvf apache-tomcat-8.5.63.tar.gz
3.移动到解压后的tomcat的bin目录启动tomcat
./startup.sh
4.开发8080端口永久开发
firewall-cmd --zone=public --add-port=8080/tcp --permanent
5.重新加载 (及时生效)
firewall-cmd --reload
6.测试
http://ip:8080 (ip为本机IP地址)
设置开机自启:
1.创建tomcat自动启动命令脚本
vi /etc/init.d/tomcat
2.写以下代码:注意修改JAVA_HOME和CATALINA_HOME CATALINA_BASE字段, 匹配自己的安装路径 。
RETVAL=0
export JAVA_HOME=/usr/local/softs/jdk1.8.0_281
export CATALINA_HOME=/usr/local/softs/apache-tomcat-8.5.63
export CATALINA_BASE=/usr/local/softs/apache-tomcat-8.5.63
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
3.设置执行权限
chmod a+x /etc/init.d/tomcat
4.注册成服务
chkconfig --add tomcat
5.设置开机启动
chkconfig tomcaton
编辑时间:
2022-7-27 周三