Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)

Overview

Don't forget that you have Java, Apache (WEB server), and Tomcat (Servlet container) installed on AmazonLinux2.

https://wa3.i-3-i.info/word12843.html

Java installation

Install java-1.8.0-openjdk-devel. I referred to here for the difference between the presence and absence of devel. If you only have an execution environment, java-1.8.0-openjdk is fine, but if you have -devel, you can use development commands such as javac. Basically install -devel.

Installation


$yum install -y java-1.8.0-openjdk-devel

Version confirmation


$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

Apache installation

I referred to here.

Version confirmation


$ httpd -v
Server version: Apache/2.4.43 ()
Server built:   May  8 2020 17:02:41

Setting to start Apache when EC2 starts


$ systemctl enable httpd.service
$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running)since water 2020-09-02 14:17:37 UTC; 16h ago
     Docs: man:httpd.service(8)
~Abbreviation~

If there is a character of ʻenabled`, the automatic start setting is completed.

When you access the EC2 endpoint like ↓, the Apache test page is displayed. http://ec2********.ap-northeast-1.compute.amazonaws.com

Install tomcat

I referred to the link that helped me with Apache installation, but it didn't work. It worked when I referred to here. I wonder why. .. .. In addition, allow 8080 port in the inbound rule of the security group of EC2. Required to access the Tomcat test page. セキュリティグループ:サーバー用.png

The download source URL is the tar.gz link address of the Official Site.

Download tomcat to ho directory


$ cd ~
$ wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz

Defrost


$ tar -xvzf apache-tomcat-9.0.37.tar.gz

Follow the reference site for the unzipped directory/opt/tomcat-Move to 9&rename。


$ sudo mv ~/apache-tomcat-9.0.37 /opt/tomcat-9

Create a tomcat group and a user and set it to the user group in the tomcat-9 directory. The -s / bin / false option seems to prevent the tomcat user from logging in as a normal user.

User, group settings


$sudo groupadd tomcat
$sudo useradd -r tomcat -s /bin/false -g tomcat tomcat
$sudo chgrp -R tomcat /opt/tomcat-9
$sudo chown -R tomcat /opt/tomcat-9

Create a configuration file (unit file) for starting the tomcat service


$sudo vim /etc/systemd/system/tomcat.service

Paste the following. Comparing the reference site and my environment, the path of JAVA_HOME was a little different. CATALINA_HOME and BASE are like directories where Tomcat is installed. Looking at the ↓ in the unit file seems to have various meanings, but I will study the details one by one. https://tex2e.github.io/blog/linux/create-my-systemd-service

Unit file


[Unit]
Description=Apache Tomcat
After=network.target
[Service]
Type=forking
Environment=CATALINA_PID=/opt/tomcat-9/temp/tomcat9.pid
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
Environment=CATALINA_HOME=/opt/tomcat-9
Environment=CATALINA_BASE=/opt/tomcat-9
Environment="CATALINA_OPTS=-Xms512m -Xmx1G"
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Djava.awt.headless=true"
ExecStart=/opt/tomcat-9/bin/startup.sh
ExecStop=/opt/tomcat-9/bin/shutdown.sh
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target

Automatic start start


$sudo systemctl daemon-reload
$sudo systemctl start tomcat
$sudo systemctl enable tomcat

status check


$ systemctl status tomcat.service
● tomcat.service - Apache Tomcat
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: active (running)since water 2020-09-02 14:17:37 UTC; 18h ago
~abridgement~

If you add: 8080 to the EC2 endpoint, the Tomcat page will be displayed. http://ec2********.ap-northeast-1.compute.amazonaws.com:8080

The service can be started and stopped manually.

$sudo service tomcat start
$sudo service tomcat stop

Comparing the above procedure with Site that was taken care of by installing Apache, there are subtle details such as no unit file contents or symbolic link creation procedure. It was different, but it worked. The procedure for creating a symbolic link can handle cases such as changing the version of tomcat.

reference

Thank you very much. https://qiita.com/hiren/items/2a4f1b55c99ebfb3fd08#apache https://medium.com/@ean.vafaei/how-to-install-tomcat-on-aws-ec2-instance-c10738a653f2

Recommended Posts

Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
Install java 1.8.0 on Amazon linux2
Install rbenv on Amazon Linux
How to install kafkacat on Amazon Linux2
Try to build Java8 environment on Amazon Linux2
Install Java on Mac
[Java] Install Amazon Corretto 8
Install Java 8 (OpenJDK: Amazon Corretto) on macOS with Homebrew
Install OpenJDK7 (JAVA) on ubuntu 14.04
Downgrade Java on openSUSE Linux
Install tomcat on Sakura's VPS
Install Java on WSL Ubuntu 18.04
Install docker on AWS EC2
Install tomcat + eclipse on mac
Run R from a tomcat-powered Java process on Amazon Linux
Install Java and Tomcat with Ansible
Install Java with zip on Windows
Install Java Open JDK 8 on CentOS 7
Run tomcat shell script on java8
Install Java 9 on windows 10 and CentOS 7
Install Java development environment on Mac
Java runtime environment construction method (Tomcat @ Linux)
Install OpenJDK (Java) on the latest Ubuntu
Deploy Java Servlet app locally on Tomcat
Build Apache + Tomcat + Pebble locally on Mac
Install java and android-sdk on Mac using homebrew
Install Java 11 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Build Apache / Tomcat development environment on Cent OS 7
Install Java 8 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Install Apache JMeter
JSP on tomcat
Apache and tomcat
EC2 on Docker-compose
Install docker-compose on a Graviton 2 instance of AWS EC2
How to install Ruby on an EC2 instance on AWS
Java development environment construction on Mac-JDK Install (2020 preservation version)
Install java and maven using brew on new mac
Install Java 8 (OpenJDK: Zulu Community) on macOS with Homebrew
[Docker] Build an Apache container on EC2 using dockerfile
Install Java / Tomcat / PostgreSQL without polluting your Mac environment