Linux上安装tomcat

参考https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7,原文中是单独创建了tomcat账号来运行tomcat,我这边因为自己使用,为方便就直接使用了自己的账号(用户和用户组都是soul);另外原文是CentOS 7系统,但实际安装部分基本上是完全通用的

  1. 下载tomcat
    1. cd ~
    2. wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz(包的地址会变化,从http://tomcat.apache.org/download-80.cgi获取最新地址)
  2. 创建tomcat目录,并解压tomcat
    1. sudo mkdir /opt/tomcat
    2. sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
  3. 赋予soul组权限
    1. cd /opt/tomcat
    2. sudo mkdir cache
    3. sudo chgrp -R soul /opt/tomcat
    4. sudo chmod -R g+r conf
    5. sudo chmod g+x conf
  4. 赋予soul用户权限
    1. sudo chown -R soul webapps/ work/ temp/ logs/ cache/
  5. 将tomcat生成为系统服务
    1. sudo vi /etc/systemd/system/tomcat.service
      # Systemd unit file for tomcat
      [Unit]
      Description=Apache Tomcat Web Application Container
      After=syslog.target network.target
      
      [Service]
      Type=forking
      
      Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/
      Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
      Environment=CATALINA_HOME=/opt/tomcat
      Environment=CATALINA_BASE=/opt/tomcat
      Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -Xss256k -XX:+UseParallelGC'
      Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
      
      ExecStart=/opt/tomcat/bin/startup.sh
      ExecStop=/opt/tomcat/bin/shutdown.sh
      
      User=soul
      Group=soul
      UMask=0007
      RestartSec=10
      Restart=always
      
      [Install]
      WantedBy=multi-user.target

      注:JAVA_HOME、User、Group按照实际的替换

    2. sudo systemctl daemon-reload

    3. sudo systemctl start tomcat

  6. 设置tomcat服务开机启动
    1. sudo systemctl enable tomcat

posted @ 2022-09-04 15:29  SoulTraitor  阅读(23)  评论(0编辑  收藏  举报