centos 7 安裝tomcat 8.5

要使用tomcat當做java web servlet container 需要java環境,所以需要再安裝jdk,這裡使用openJDK

1.安裝openJDK

參考此網站 http://openjdk.java.net/install/

sudo yum install java-1.8.0-openjdk

2.建立user 及group tomcat

sudo useradd -r tomcat --shell /bin/false

3.下載tomcat 8.5

可至

https://tomcat.apache.org/download-80.cgi

取得url,利用wget下載tar gz檔

cd /tmp & wget ftp://ftp.twaren.net/Unix/Web/apache/tomcat/tomcat-8/v8.5.45/bin/apache-tomcat-8.5.45.tar.gz

4.解壓縮tomcat tar gz檔,並修改目錄user及group

sudo tar -zxf /tmp/apache-tomcat-*.tar.gz -C /opt
sudo ln -s /opt/apache-tomcat-8.5.45 /opt/tomcat
sudo chown -hR tomcat: /opt/tomcat /opt/apache-tomcat-*

5.建立start script

sudo nano /etc/systemd/system/tomcat.service

內容如下:

[Unit]
Description=Tomcat8.5
After=network.target

[Service]
Type=forking
User=tomcat
Group=tomcat

Environment=CATALINA_PID=/opt/tomcat-latest/tomcat.pid
Environment=TOMCAT_JAVA_HOME=/usr/java/default
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

6.設定on boot start 及啟用tomcat

sudo systemctl daemon-reload
sudo systemctl restart tomcat
sudo systemctl enable tomcat

7.測試http://ip:8080/

ps.如果被防火牆檔到可以利用下面shell打開

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

發表迴響