安装Tomcat7
1.下载tomcat7,https://tomcat.apache.org/download-70.cgi,apache-tomcat-7.0.103.tar.gz
2.通过winscp或其他工具上传到CentOS8,解压缩,并移动到/usr/local
#tar -zxvf apache-tomcat-7.0.103.tar.gz
#mv apache-tomcat-7.0.103 /usr/local
3.启动tomcat,进入bin目录。运行启动脚本
#cd apache-tomcat-7.0.103/bin
#./startup.sh #启动
显示Tomcat started表示启动成功
#./shutdown.sh #关闭
4.打开浏览器,输入http://IP:8080,是否可以打开网页
Tips:
tomcat启动成功,但无法访问网页的解决方法
关闭防火墙
#systemctl stop firewalld.service
禁止防火墙自启动
#systemctl disable firewalld.service
打开防火墙
#systemctl start firewalld.service
开启防火墙自启动
#systemctl enable firewalld.service
开放指定端口号
#firewall-cmd --zone=public --add-port=8080/tcp --permanent
重启防火墙
#firewall-cmd --reload
注册系统服务并开机启动
1.修改 tomcat bin 目录的catalina.sh文件,添加如下内容
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
2.在/usr/lib/systemd/system下面建立tomcat.service文件,内容是
-----------------------------------------------------------------------------
[Unit]
Description=Tomcat7
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment='JAVA_HOME=/usr/local/jdk1.8.0_241' #jdk路径
PIDFile=/usr/local/apache-tomcat-7.0.103/tomcat.pid #tomcat路径
ExecStart=/usr/local/apache-tomcat-7.0.103/bin/startup.sh #tomcat路径
ExecReload=/bin/kill-s HUP $MAINPID
ExecStop=/bin/kill-s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------------------
重新载入配置
#systemctl daemon-reload
添加自启动
#systemctl enable tomcat.service
在开机时禁用一个服务
#systemctl disable tomcat.service
查看已启动的服务列表
#systemctl list-unit-files | grep enabled
查看服务是否开机启动
#systemctl is-enabled tomcat.service
显示一个服务的状态
#systemctl status tomcat.service
重启一个服务
#systemctl restart tomcat.service
启动一个服务
#systemctl start postfix.service
关闭一个服务
#systemctl stop postfix.service