Linux7.4安装tomcat及开机自启动

时间:2023-01-08 15:40:26

1.首先确认已安装jdk

2.下载tomcat

curl http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.85/bin/apache-tomcat-7.0.85.tar.gz

3.解压

tar -zxvf apache-tomcat-7.0.85.tar.gz

4.配置环境

#在tomcat/bin/catalina.sh 的头部加入环境变量,适用于非yum安装
export  JAVA_HOME=/usr/local/java/jdk1.8.0_161

export  JRE_HOME=/usr/local/java/jdk1.8.0_161/jre

5.设置开机启动服务

#tomcat开机自启动服务,在lib/systemd/system 中创建tomcat.service

[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
  
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat7/bin/startup.sh
ExecStop=/usr/local/tomcat7/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
 
[Install]

WantedBy=multi-user.target

5. #添加到开机启动

systemctl enable tomcat.service

6. #重启机器查看状态

[zhiwei@VM_162_98_centos ~]$ ps aux|grep tomcat
root       892  0.0  5.3 2511304 100176 ?      Sl   Mar28   6:56 /usr/local/java/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat7 -Dcatalina.home=/usr/local/tomca7 -Djava.io.tmpdir=/usr/local/tomcat7/temp org.apache.catalina.startup.Bootstrap start