AWS EC2 Amazon Linux2 へ自動でJavaのデプロイするために、CodeDeploy Agentを導入したかった
検証のため、取り急ぎ、PublicサブネットにAmazon Linux 2立ててCodeDeploy Agentを導入してみた。
前提パッケージのインストール
$ sudo amazon-linux-extras install -y ruby2.6
・Rubyさえ入っていれば、CodeDeploy Agentの導入ができる模様。
・wgetは、Amazon Linux 2に最初から入っているのでインストール不要。
・S3へのアクセス許可するIAMロールが必要とマニュアルには書いてあったものの、なくても導入できたので不要と判断いたしました。
CodeDeploy Agentのインストール
$ sed -i "s/'2.5/'2.6/" install
$ chmod +x install
$ sudo ./install auto
I, [2020-01-23T07:20:02.299167 #3254] INFO -- : Starting Ruby version check.
W, [2020-01-23T07:20:02.299306 #3254] WARN -- : The Ruby version in /usr/bin/ruby is 2.6.3, . Attempting to install anyway.
I, [2020-01-23T07:20:02.299358 #3254] INFO -- : Starting update check.
I, [2020-01-23T07:20:02.299389 #3254] INFO -- : Attempting to automatically detect supported package manager type for system...
I, [2020-01-23T07:20:02.309700 #3254] INFO -- : Checking AWS_REGION environment variable for region information...
I, [2020-01-23T07:20:02.309808 #3254] INFO -- : Checking EC2 metadata service for region information...
I, [2020-01-23T07:20:02.379616 #3254] INFO -- : Downloading version file from bucket aws-codedeploy-ap-northeast-1 and key latest/VERSION...
I, [2020-01-23T07:20:02.422628 #3254] INFO -- : Downloading version file from bucket aws-codedeploy-ap-northeast-1 and key latest/VERSION...
I, [2020-01-23T07:20:02.480273 #3254] INFO -- : Downloading package from bucket aws-codedeploy-ap-northeast-1 and key releases/codedeploy-agent-1.0-1.1597.noarch.rpm...
I, [2020-01-23T07:20:02.580139 #3254] INFO -- : Executing `/usr/bin/yum -y localinstall /tmp/codedeploy-agent-1.0-1.1597.noarch.tmp-20200123-3254-1kqgc9t.rpm`...
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Examining /tmp/codedeploy-agent-1.0-1.1597.noarch.tmp-20200123-3254-1kqgc9t.rpm: codedeploy-agent-1.0-1.1597.noarch
Marking /tmp/codedeploy-agent-1.0-1.1597.noarch.tmp-20200123-3254-1kqgc9t.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package codedeploy-agent.noarch 0:1.0-1.1597 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
codedeploy-agent noarch 1.0-1.1597 /codedeploy-agent-1.0-1.1597.noarch.tmp-20200123-3254-1kqgc9t 17 M
Transaction Summary
===============================================================================================================================
Install 1 Package
Total size: 17 M
Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
pre hook : 1
Checking the ruby version.
Checking if there is already a process named codedeploy-agent running.
Installing : codedeploy-agent-1.0-1.1597.noarch 1/1
post hook : 1
Check if there is a codedeployagent config file.
Start codedeploy-agent in post hook if this is a first install.
Installing codedeploy-agent auto-update cron in '/etc/cron.d/codedeploy-agent-update'...
Installing codedeploy-agent auto-update cron in '/etc/cron.d/codedeploy-agent-update'...Complete
Verifying : codedeploy-agent-1.0-1.1597.noarch 1/1
Installed:
codedeploy-agent.noarch 0:1.0-1.1597
Complete!
I, [2020-01-23T07:20:05.579195 #3254] INFO -- : Update check complete.
I, [2020-01-23T07:20:05.579283 #3254] INFO -- : Stopping updater.
Agentの作りが古く、Rubyのバージョン2.6が出ることを想定されてないようなので、sed使ってインストーラーにちょい手を加える
(参考)
https://github.com/aws/aws-codedeploy-agent/issues/214
CodeDeploy Agentのご様子を確認
$ sudo systemctl status codedeploy-agent
● codedeploy-agent.service - AWS CodeDeploy Host Agent
Loaded: loaded (/usr/lib/systemd/system/codedeploy-agent.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-01-23 07:20:05 UTC; 5min ago
Process: 3317 ExecStart=/bin/bash -a -c [ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/codedeploy-agent start (code=exited, status=0/SUCCESS)
Main PID: 3329 (ruby)
CGroup: /system.slice/codedeploy-agent.service
├─3329 codedeploy-agent: master 3329
└─3332 codedeploy-agent: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller of master 3329
...
無事、起動。
おまけ。Javaアプリケショーンサーバ(いつものTomcat)のインストール
$ sudo amazon-linux-extras install -y java-openjdk11
$ sudo amazon-linux-extras install -y tomcat8.5
$ sudo java -version
openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Corretto-11.0.6.10.1 (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.6.10.1 (build 11.0.6+10-LTS, mixed mode)
$ sudo systemctl start tomcat
$ ps -ef | grep java
tomcat 3576 1 5 07:26 ? 00:00:02 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat/temp -Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start
ec2-user 3640 2722 0 07:27 pts/0 00:00:00 grep --color=auto java
OpenJDKインストールすると、普通に Corretto なのな。