在tomcat bin目录下建立 setenv.sh 文件,内容如下
#add tomcat ptah
export CATALINA_HOME=/javadata/tomcat7
export CATALINA_BASE=/javadata/tomcat7
#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add Java_home
JAVA_HOME=/usr/java/jdk1.8.0_131
#add Java opts
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"
在/usr/lib/systemd/system目录下增加tomcat.service 内容
[Unit]
Description=Tomcat
After=syslog.target mariadb.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/javadata/tomcat7/tomcat.pid
ExecStart=/javadata/tomcat7/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]配置了使用用户
使用tomcat.service
systemctl status tomcat.service(查看启动日志)
systemctl start tomcat.service(启动)
systemctl stop name.service
重启服务
systemctl restart name.service
增加开机启动
systemctl enable name.service
删除开机启动
systemctl disable name.service