sudo yum update
之後在關閉內建firewalled (如以後外部防火牆設備)等設定及yum vim..等相關套件工具
安裝java1.8 相關套件
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
確認JAVA版本是否為1.8
java -version
cd /tmp
Tomcat 的官方網站下載最新的 Tomcat 9 壓縮檔(這邊是安裝tomcat9.0.50)
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.zip
同時下載 SHA512 的檢查碼
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.zip.sha512
驗證sha512sum 檢查一下檔案比對兩邊檢查碼是否一樣
sha512sum apache-tomcat-9.0.50.zip
cat apache-tomcat-9.0.50.zip.sha512
解壓縮tomcat並把解開移至opt/tomcat
unzip apache-tomcat-9.0.50.zip
mv apache-tomcat-9.0.50 /opt/tomcat
建立tomcat帳號
useradd -r tomcat --shell /bin/false
設定tomcat資料夾權限
cd /opt/tomcat
sudo chgrp -R tomcat *
sudo chmod g+rwx conf
sudo chmod -R g+r conf
sudo chown -R tomcat webapps/ work/ temp/ logs/
sudo chmod +x /opt/tomcat/bin/*.sh
設定 Systemd 啟動指令檔
vim /etc/systemd/system/tomcat.service
=======================================================
[Unit]
Description=Apache Tomcat 9
After=syslog.target network.target
[Service]
User=tomcat
Group=tomcat
Type=forking
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
Environment='CATALINA_OPTS=-Xms512M -Xmx8192M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
[Install]
WantedBy=multi-user.target
=======================================================
重新載入 Systemd
systemctl daemon-reload
啟動 Tomcat 服務並設定自動開機啟動tomcat
systemctl enable tomcat
systemctl start tomcat
查看 Tomcat 服務的狀態
systemctl status tomcat
開起網頁 http://serverIP:8080/
新增Tomcat管理者的帳號 (這裡如設定username admin password admin)
vim /opt/tomcat/conf/tomcat-users.xml
在「</tomcat-users>」之前新增下列設定
======================================================
<role rolename="admin-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui" />
======================================================
再來設定允許本機以外的IP可以連線管理網頁
vim /opt/tomcat/webapps/manager/META-INF/context.xml
進去看到後下列設定參數刪除 即可開放任何IP連線管理者網頁
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
跳出重啟服務
systemctl restart tomcat
驗證管理者帳號是否有效
點選「Server Status」
彈出敲帳密視窗把剛剛設號帳密打進去結果如下:
PS:也可做個測試頁在webapps底下建個test資料夾建立test.jsp
cd /opt/tomcat/webapps/
mkdir test 進去test資料夾
vim test.jsp
======================
test tomcat ok!
======================
重啟tomcat服務
systemctl restart tomcat
進去tomcat網頁
http://serverIP:8080/ test/test.jsp 出現剛剛編寫測試成功網頁
沒有留言:
張貼留言