NoesBlog Docs
搜索文档…
CentOS7 install Tomcat9
教程适用于CentOS7,使用编译安装方式,在使用本教程时请注意你的安装路径是否一致!
教程测试于:
CentOS7.4 64位
jdk-8u152

Tomcat install

跳转到软件目录
1
cd /opt
Copied!
下载tomcat 编译包
1
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-9/v9.0.2/bin/apache-tomcat-9.0.2.tar.gz
Copied!
解压编译包
1
tar zxvf apache-tomcat-9.0.2.tar.gz
Copied!
安装完毕
打开防火墙端口
1
firewall-cmd --zone=public --add-port=8080/tcp --permanent
Copied!
1
firewall-cmd --reload
Copied!
访问http://服务器ip:8080 即可查看tomcat欢迎页
设置tomcat开机自启动
1
vi /etc/systemd/system/tomcat.service
Copied!
在文件内追加如下内容并保存
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment=JAVA_HOME=/opt/jdk1.8.0_152
Environment=CATALINA_HOME=/opt/apache-tomcat-9.0.2
Environment=CATALINA_BASE=/opt/apache-tomcat-9.0.2
ExecStart=/opt/apache-tomcat-9.0.2/bin/startup.sh start
ExecStop=/opt/apache-tomcat-9.0.2/bin/shutdown.sh stop
[Install]
WantedBy=multi-user.target
重载文件
1
systemctl daemon-reload
Copied!
设置tomcat开机启动
1
systemctl enable tomcat
Copied!
启动tomcat
1
systemctl start tomcat
Copied!

常用命令汇总

查看运行状态
1
systemctl status tomcat
Copied!
启动tomcat
1
systemctl start tomcat
Copied!
停止tomcat
1
systemctl stop tomcat
Copied!
重启tomcat
1
systemctl restart tomcat
Copied!
去除tomcat开机启动
1
systemctl disable tomcat
Copied!
设置tomcat开机启动
1
systemctl enable tomcat
Copied!
说明:设置tomcat自启动后建议使用命令方式直接启动或关闭等操作。
脚本启动tomcat
1
cd /opt/apache-tomcat-9.0.2/bin
Copied!
1
./startup.sh
Copied!
脚本停止tomcat
1
cd /opt/apache-tomcat-9.0.2/bin
Copied!
1
./shutdown.sh
Copied!
查看当前日志
1
/opt/apache-tomcat-9.0.2/logs
Copied!
1
cat catalina.out
Copied!
跟踪查看当前日志(与windows一致,实时更新控制台输出,方便debug)
1
/opt/apache-tomcat-9.0.2/logs
Copied!
1
tail -f catalina.out
Copied!

异常处理

提示内容:
Job for tomcat.service failed because the control process exited with error code. See "systemctl status tomcat.service" and "journalctl -xe" for details.
表明你的tomcat自启动文件有误,请重新按照步骤添加tomcat自启动
提示内容:
Failed to start tomcat.service: Access denied
表示服务无法正常启动,执行下面命令然后再执行启动tomcat命令一般可以解决
重新启动systemd
1
systemctl daemon-reexec
Copied!
最近更新 3yr ago