以下是tomcat 自动启动配置
vi /etc/profile
最后加上如下内容
#jdk config
export JAVA_HOME=/usr/java/jdk18
export CLASSPATH=$JAVA_HOME/lib/*.*
#tomcat config
export TOMCAT_HOME=/usr/local/tomcat/tomcat85
export CATALINA_HOME=/usr/local/tomcat/tomcat85
#path config
export PATH=$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin
在/usr/local/tomcat/tomcat85/bin 目录下面,新建 setenv.sh配置,catalina.sh启动的时候会调用,同时配置java内存参数
setenv.sh的内容如下:
export CATALINA_HOME=/usr/local/tomcat/tomcat85
export CATALINA_BASE=/usr/local/tomcat/tomcat85
#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
在/usr/lib/systemd/system目录下增加tomcat.service,目录必须是绝对目录
[Unit]
Description=Tomcat
After=syslog.targetnetwork.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment='JAVA_HOME=/usr/java/jdk18'
Environment='CATALINA_PID=/usr/local/tomcat/tomcat85/tomcat.pid'
Environment='CATALINA_HOME=/usr/local/tomcat/tomcat85/'
Environment='CATALINA_BASE=/usr/local/tomcat/tomcat85/'
WorkingDirectory=/usr/local/tomcat/tomcat85/
ExecStart=/usr/local/tomcat/tomcat85/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
##[unit]配置了服务的描述,规定了在network启动之后执行,
##[service]配置服务的pid,服务的启动,停止,重启
##[install]配置了使用用户
执行
systemctl daemon-reload 回重加载一下
修改/usr/local/tomcat/tomcat85/bin/setclasspath.sh配置
在文件开头加入
export JAVA_HOME=/usr/java/jdk18
export JRE_HOME=/usr/java/jdk18/jre
编辑 tomcat catalina.sh文件 目标 虽然已经有了jdk配置 但这里启动时jdk配置还没加载,
vim /usr/local/tomcat/tomcat85/bin/catalina.sh
在文件开头加入
export JAVA_HOME=/usr/java/jdk18
export JRE_HOME=/usr/java/jdk18/jre
执行服务内容
查看tomcat的状态 systemctl status tomcat.service
配置开机启动 systemctl enable tomcat.service
删除开机启动 systemctl disable tomcat.service
启动tomcat systemctl start tomcat.service
停止tomcat systemctl stop tomcat.service
重启tomcat systemctl restart tomcat.service
转载于:https://www.cnblogs.com/han-java/p/10955511.html