安裝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
