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
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)
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
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.
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.
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