apache

バージョンはyumで取得できる最新(2.4.57)を使用。

$ sudo yum install -y httpd

$ httpd -v
Server version: Apache/2.4.57 ()
Server built:   May  3 2023 16:00:14

$ sudo systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd.service(8)

$ sudo systemctl start httpd.service
$ sudo systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-08-14 16:50:53 JST; 1s ago
     Docs: man:httpd.service(8)
 Main PID: 5174 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           tq5174 /usr/sbin/httpd -DFOREGROUND
           tq5175 /usr/sbin/httpd -DFOREGROUND
           tq5176 /usr/sbin/httpd -DFOREGROUND
           tq5177 /usr/sbin/httpd -DFOREGROUND
           tq5178 /usr/sbin/httpd -DFOREGROUND
           mq5179 /usr/sbin/httpd -DFOREGROUND

Aug 14 16:50:52 ip-172-31-5-50.ap-northeast-1.compute.internal systemd[1]: Starting The Ap...
Aug 14 16:50:53 ip-172-31-5-50.ap-northeast-1.compute.internal systemd[1]: Started The Apa...
Hint: Some lines were ellipsized, use -l to show in full.

ここまででインストール完了。
ブラウザからhttp://[IPアドレス]/へアクセスし、apacheの画面が表示されることを確認。
apache画面

EC2起動時に自動でapacheも起動するよう設定。

$ sudo systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

tomcatへリクエストを渡す設定を追記。
■httpd.conf

ProxyPass / ajp://localhost:8080/[コンテキストパス]/
ProxyPassReverse / ajp://localhost:8080/[コンテキストパス]/

tomcat

バージョンは10.1.11を使用。

$ cd
$ sudo useradd -s /sbin/nologin tomcat
$ wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.11/bin/apache-tomcat-10.1.11.tar.gz 
$ tar -xzvf apache-tomcat-10.1.11.tar.gz

$ cd opt
$ sudo mv ~/apache-tomcat-10.1.11 ./
$ sudo mv apache-tomcat-10.1.11 tomcat-10.1.11

$ sudo chown -R tomcat:tomcat tomcat-10.1.11
$ ll
total 0
drwxr-xr-x 4 root   root    33 Mar  8 09:47 aws
drwxr-xr-x 2 root   root     6 Aug 16  2018 rh
drwxrwxr-x 9 tomcat tomcat 220 Aug 14 16:58 tomcat-10.1.11

$ sudo ln -s /opt/tomcat-10.1.11 /opt/tomcat
$ sudo chown -h tomcat:tomcat tomcat

$ ll
total 0
drwxr-xr-x 4 root   root    33 Mar  8 09:47 aws
drwxr-xr-x 2 root   root     6 Aug 16  2018 rh
lrwxrwxrwx 1 tomcat tomcat  19 Aug 14 17:03 tomcat -> /opt/tomcat-10.1.11
drwxrwxr-x 9 tomcat tomcat 220 Aug 14 16:58 tomcat-10.1.11

TomcatをOSにサービスとして登録。

$ cd /usr/lib/systemd/system/
$ sudo vi tomcat.service

# Systemd unit file for default tomcat
#
# To create clones of this service:
# DO NOTHING, use tomcat@.service instead.

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=oneshot
PIDFile=/opt/tomcat/tomcat.pid
RemainAfterExit=yes
#EnvironmentFile=/etc/tomcat/tomcat.conf
#Environment="NAME="
#EnvironmentFile=-/etc/sysconfig/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
ExecReStart=/opt/tomcat/bin/shutdown.sh;/opt/tomcat/bin/startup.sh
SuccessExitStatus=143
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

EC2起動時に自動でtomcatも起動するよう設定。

$ sudo systemctl enable tomcat.service
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.

$ sudo systemctl status tomcat.service
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

自動デプロイをoff。

sudo vi /opt/tomcat/conf/server.xml
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="false"> ★true→falseへ

エラーが発生したのでserver.xmlを編集。

        Caused by: java.lang.IllegalArgumentException: The AJP Connector is configured with secretRequired="true" but the secret attribute i
s either null or "". This combination is not valid.

■server.xml

    <Connector port="8080" protocol="AJP/1.3"
               connectionTimeout="20000"
               redirectPort="8443"
               secretRequired="false" ★これを追加
               maxParameterCount="1000"
               />

java

バージョンは17を使用。


$ sudo yum install java-17-amazon-corretto

$ java -version
openjdk version "17.0.8" 2023-07-18 LTS
OpenJDK Runtime Environment Corretto-17.0.8.7.1 (build 17.0.8+7-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.8.7.1 (build 17.0.8+7-LTS, mixed mode, sharing)

$ which java
/usr/bin/java