Tomcat 开发环境

Summary: Author: 张亚飞 | 阅读时间: 1 minute read | Published: 2018-04-17
Filed under Categories: LinuxTags: Note,

Tomcat 开发

Tomcat 开发环境

Idea 本地开发环境指南

准备 java 运行环境

Ubuntu

sudo apt update
sudo apt install default-jdk

MacOS

使用系统默认…

  • 验证 java 版本
$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
  • 创建 tomcat 用户 - 取消

Ubuntu - 使用普通用户管理服务

#sudo useradd -r -m -U -d /usr/local/tomcat -s /bin/false tomcat
  • 安装 Tomcat
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.17/bin/apache-tomcat-9.0.17.tar.gz
tar -zxvf apache-tomcat-9.0.17.tar.gz
sudo mv apache-tomcat-9.0.17/* /usr/local/tomcat
  • 配置权限
sudo chown -RH coam: /usr/local/tomcat
sudo chmod +x /usr/local/tomcat/bin/*.sh

管理 tomcat 服务

Ubuntu

  • 使用 systemctl 启动设置

建立启动文件 /lib/systemd/system/cs-tomcat.service

* [Unit]
Description=Tomcat 9 servlet container
After=network.target

* [Service]
Type=forking

#User=tomcat
#Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/usr/local/tomcat"
Environment="CATALINA_HOME=/usr/local/tomcat"
Environment="CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh

* [Install]
WantedBy=multi-user.target
  • 服务管理
sudo systemctl daemon-reload
sudo systemctl start cs-tomcat

MacOS

$ /usr/local/tomcat/bin/startup.sh
$ /usr/local/tomcat/bin/shutdown.sh

访问服务

http://:8080

Tomcat 配置

  • 创建关联用户配置文件

Comments

Cor-Ethan, the beverage → www.iirii.com