1.安装jdk
sudo apt-get update
sudo apt-get install default-jdk

2.创建tomcat用户
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

3.安装tomcat
cd /tmp
curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.5/bin/apache-tomcat-8.5.5.tar.gz
sudo mkdir /opt/tomcat
sudo tar -zxf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1

4.权限配置
cd /opt/tomcat
sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps work temp logs

5.创建systemd文件
sudo update-java-alternatives -l
sudo vi /etc/systemd/system/tomcat.service

点击(此处)折叠或打开

  1. [Unit]
  2. Description=Apache Tomcat Web Application Container
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
  7. Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
  8. Environment=CATALINA_HOME=/opt/tomcat
  9. Environment=CATALINA_BASE=/opt/tomcat
  10. Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
  11. Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
  12. ExecStart=/opt/tomcat/bin/startup.sh
  13. ExecStop=/opt/tomcat/bin/shutdown.sh
  14. User=tomcat
  15. Group=tomcat
  16. UMask=0007
  17. RestartSec=10
  18. Restart=always
  19. [Install]
  20. WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat
sudo systemctl enable tomcat

6.配置防火墙
sudo ufw allow 8080

7.配置tomcat管理界面
sudo vi /opt/tomcat/conf/tomcat-users.xml

点击(此处)折叠或打开

  1. <tomcat-users . . .>
  2.     <user username="admin" password="password" roles="manager-gui,admin-gui"/>
  3. </tomcat-users>


10-26 08:09