0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS EC2のRHEL8でTomcatの自動起動を設定する

0
Posted at

Tomcatのインストールはできたけど・・・

自動起動の設定がなかなかうまくいかなかった。最終的にうまくいった方法を書いておきます。

OS:Red Hat Enterprise Linux release 8.2 (Ootpa)
Tomcat:Apache Tomcat 8.5.58

<説明すること>
①Tomcatのインストール手順
②自動起動設定

①Tomcatのインストール手順

/user/local/tomcatにインストールしました

# wgetとJavaのインストール
$sudo yum install -y wget 
$sudo yum install -y java-1.8.0-openjdk

$sudo useradd -s /sbin/nologin tomcat
$sudo wget http://ftp.riken.jp/net/apache/tomcat/tomcat-8/v8.5.58/bin/apache-tomcat-8.5.58.tar.gz
$sudo tar -xzvf ~/apache-tomcat-8.5.58.tar.gz
$sudo mv ~/apache-tomcat-8.5.58 /usr/local/tomcat
$sudo chown -R tomcat:tomcat /usr/local/tomcat

# 環境変数の設定
$sudo echo "JRE_HOME=/usr/lib/jvm/jre" >>/etc/profile
$sudo echo "CATALINA_HOME=/usr/local/tomcat" >>/etc/profile
$sudo echo "export JRE_HOME CATALINA_HOME" >>/etc/profile
$sudo source /etc/profile

②自動起動の設定

tomcat.serviceを設定します。

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

tomcat.serviceの中身は下記のように設定します。

tomcat.service
[Unit]
Description=Apache Tomcat 8.5.58
ConditionPathExists=/usr/local/tomcat

[Service]
User=root
Group=root
Type=oneshot
PIDFile=/usr/local/tomcat/tomcat.pid

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

Restart=no
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Tomcat.serviceを自動起動設定に入れます。

$ sudo systemctl daemon-reload
$ sudo systemctl list-unit-files --type=service | grep tomcat
 tomcat.service                             enabled
$ sudo systemctl enable tomcat

出来た!

$ sudo systemctl start tomcat
$ sudo systemctl status tomcat
● tomcat.service - Apache Tomcat 8.5.58
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: >
   Active: active (exited) since Fri 2020-10-23 14:30:25 UTC; 13h ago
  Process: 5636 ExecStop=/bin/bash /usr/local/tomcat/bin/shutdown.sh (code=exit>
  Process: 5667 ExecStart=/bin/bash /usr/local/tomcat/bin/startup.sh (code=exit>
 Main PID: 5667 (code=exited, status=0/SUCCESS)
    Tasks: 28 (limit: 4855)
   Memory: 134.4M
   CGroup: /system.slice/tomcat.service
           mq5681 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomc>

Oct 23 14:30:25 ip-172-31-37-53.ap-northeast-1.compute.internal systemd[1]: Sto>
Oct 23 14:30:25 ip-172-31-37-53.ap-northeast-1.compute.internal systemd[1]: Sta>
Oct 23 14:30:25 ip-172-31-37-53.ap-northeast-1.compute.internal bash[5667]: Tom>
Oct 23 14:30:25 ip-172-31-37-53.ap-northeast-1.compute.internal systemd[1]: Sta

他の方のご説明通りUser、GroupをTomcatに設定してみるもどうしてもうまくいかず(Permission Deniedを突破できなかった)・・・やむなく、良くないのはわかりつつもrootに設定してみたらできました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?