linux设置tomcat开机自启
时间: 2023-04-12 15:04:34 浏览: 169
要在Linux上设置Tomcat开机自启,可以按照以下步骤进行操作:
1. 打开Tomcat的启动脚本,通常位于Tomcat安装目录下的bin目录中,例如:/opt/tomcat/bin/catalina.sh。
2. 在脚本中找到以下代码:
# ----- Execute The Requested Command -----------------------------------------
case "$1" in
start)
shift
if [ "$1" = "-security" ] ; then
if [ $have_tty -eq 1 ]; then
echo "Using Security Manager"
shift
exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
else
exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
fi
3. 在该代码块的末尾添加以下内容:
# ----- Set Tomcat to auto-start on boot --------------------------------------
if [ -f /etc/rc.d/init.d/functions ]; then
# RedHat based systems
echo "Adding Tomcat to chkconfig"
/sbin/chkconfig --add tomcat
/sbin/chkconfig --level 345 tomcat on
elif [ -f /etc/init.d/functions ]; then
# Debian based systems
echo "Adding Tomcat to update-rc.d"
/usr/sbin/update-rc.d -f tomcat defaults
fi
4. 保存并关闭文件。
5. 授予启动脚本执行权限,例如:chmod +x /opt/tomcat/bin/catalina.sh。
6. 将Tomcat添加到系统服务中,例如:/etc/init.d/tomcat。
7. 启动Tomcat服务,例如:/etc/init.d/tomcat start。
8. 确认Tomcat已成功启动,例如:ps -ef | grep tomcat。
9. 重启系统,确认Tomcat是否已自动启动。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)