⼀、安装tomcat8
1、下载tomcat8 https://tomcat.apache.org/download-80.cgi
2、移到java⽂件夹下 :mv apache-tomcat-8.5.34 .tar.gz /usr/local/java
3、解压⽂件夹:tar -zxvf apache-tomcat-8.5.34.tar.gz
4、更改⽂件夹名称 mv apache-tomcat-8.5.34 tomcat8(不做更改也可以)
5、运⾏bin⽬录下的 ./startup.sh(运⾏tomcat)
6、对外开放端⼝号8080
⼆、设置tomcat8服务 以及开机⾃启
1、编辑该⽂件:vim /usr/lib/systemd/system/tomcat.service
如果vim /usr/lib/systemd/system/下没有该⽂件则⾃⼰创建
内容如下:
[Unit] Description=Tomcat8 After=syslog.target network.target remote-fs.target nss-lookup.target
[Service] Type=forking Environment=‘JAVA_HOME=/usr/local/java/jdk1.8.0_181’ Environment=‘CATALINA_PID=/usr/local/java/tomcat8/bin/tomcat.pid’ Environment=‘CATALINA_HOME=/usr/local/java/tomcat8/’ Environment=‘CATALINA_BASE=/usr/local/java/tomcat8/’ Environment=‘CATALINA_OPTS=-Xms512M -Xmx1024M -server XX:+UseParallelGC’
WorkingDirectory=/usr/local/java/tomcat8/
ExecStart=/usr/local/java/tomcat8/bin/startup.sh
./startup.sh 看不见启动日志、1 ./catalina.sh run 启动能看到日志,但是界面不能关闭2
298 firewall-cmd --permanent --add-port=8080/tcp1 299 firewall-cmd --reload2 300 firewall-cmd --list-all3
ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true
[Install] WantedBy=multi-user.target
2、设置为开机启动 systemctl enable tomcat
3、其他服务: A、启动服务:systemctl start tomcat B、停⽌服 务:systemctl stop tomcat C、重启服务:systemctl restart tomcat D、检查状态:systemctl status tomcat
4、测试访问tomcat服务