AWS DataSync エージェントをデプロイした EC2 インスタンスに SSM セッションマネージャーで接続していろいろ探ってみた

通常利用する分には一切知る必要がない内容を頑張って調べました。なぜかって?気になったからです。

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

コンバンハ、千葉(幸)です。

AWS DataSync のコンポーネントのうち、エージェントは Amazon EC2 で構成することができます。

公式で提供されている DataSync エージェント用の AMI からインスタンスを作成し、エンドポイントと通信させてアクティベートすることでエージェントとして機能します。

DataSync エージェントインスタンスでは、通常のキーペアを使用した SSH 接続を試みても OS 領域にアクセスすることができません。DataSync エージェントのローカルコンソールに接続される形となります。

しかし、起動時にユーザーデータで SSM(Systems Manager) エージェントをセットアップすることで、通常のインスタンスと同様にセッションマネージャーの機能でアクセス可能となります。

せっかくなので、DataSync 用の AMI から起動したインスタンスは通常のものと何が違うのかをいろいろと探ってみたいと思います。

探究心、それは人類の原初から DNA に刻み込まれているものです。

目次

今回やることについてもう少し補足

単純に DataSync エージェントを EC2 インスタンスにデプロイする様子については以下のエントリで書きました。基本的な設定内容はこのエントリを踏襲します。

使用する AMI は現時点で最新の以下を選択しました。

  • aws-datasync-1593551918 - ami-02de0268b0efe9fc7
    • m5.2xlarge

DataSync エージェントの要件ではありませんが、個人の趣味として SSM 接続をするために、インスタンスローンチ時にユーザーデータとして以下を設定しています。

#!/bin/bash
cd /tmp
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
sudo start amazon-ssm-agent

ローンチ後、ディレクトリを階層化して確認したかったのでtreeをインストールしました。

[root@ip-192-168-0-176 env]# yum install tree
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                                                                                                 | 2.1 kB  00:00:00
amzn-updates                                                                                                                              | 3.8 kB  00:00:00
1072 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-5.8.amzn1 will be installed
--> Finished Dependency Resolution

--- 略 ---

Installed:
  tree.x86_64 0:1.6.0-5.8.amzn1

Complete!

また、EC2 コンソールから確認できるシステムログの内容より、 DataSync エージェント用 AMI は以下の AMI がベースになっていることがわかります。

--- 略 ---
image_name="amzn-ami-hvm"
image_version="2018.03"
image_arch="x86_64"
image_file="amzn-ami-hvm-2018.03.0.20181116-x86_64.ext4.gpt"
image_stamp="1eb2-dca9"
image_date="20181116230743"
recipe_name="amzn ami"
recipe_id="f77a9127-a78d-21b7-174f-f788-81b9-dc54-58052337"
		Welcome to Amazon Linux AMI
--- 略 ---

DataSync エージェント用 AMI との比較のために通常の Amazon Linux の AMI からインスタンスを作成し、必要に応じて併記することにします。

  • amzn-ami-hvm-2018.03.0.20181116-x86_64-ebs - ami-016ad6443b4a3d960
    • m5.large

それでは早速確認していきます。

ユーザー関連

/etc/passwd

以下ハイライト部が、通常の Amazon Linux と比べて追加されているユーザーです。

この後にも出てきますが、 Storage Gateway がインストールされるというのが面白いですね。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
saslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
ec2-user:x:500:500:EC2 Default User:/home/ec2-user:/bin/bash
tcpdump:x:72:72::/:/sbin/nologin
sgserver:x:498:495::/usr/local/aws-storage-gateway:/sbin/nologin
admin:x:497:494::/home/sguser:/usr/local/aws-storage-gateway/appliance_console
ssm-user:x:501:501::/home/ssm-user:/bin/bash

/etc/shadow

先ほど確認した 3 ユーザー分の差異は当然発生します。adminにはパスワードが設定されています。

ec2-userの第二フィールドが*になっている点も通常のインスタンスと異なっています。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# cat /etc/shadow
root:*LOCK*:14600::::::
bin:*:16323:0:99999:7:::
daemon:*:16323:0:99999:7:::
adm:*:16323:0:99999:7:::
lp:*:16323:0:99999:7:::
sync:*:16323:0:99999:7:::
shutdown:*:16323:0:99999:7:::
halt:*:16323:0:99999:7:::
mail:*:16323:0:99999:7:::
uucp:*:16323:0:99999:7:::
operator:*:16323:0:99999:7:::
games:*:16323:0:99999:7:::
gopher:*:16323:0:99999:7:::
ftp:*:16323:0:99999:7:::
nobody:*:16323:0:99999:7:::
rpc:!!:17851:0:99999:7:::
ntp:!!:17851::::::
saslauth:!!:17851::::::
mailnull:!!:17851::::::
smmsp:!!:17851::::::
rpcuser:!!:17851::::::
nfsnobody:!!:17851::::::
sshd:!!:17851::::::
dbus:!!:17851::::::
ec2-user:*:18443:0:99999:7:::
tcpdump:!!:18443::::::
sgserver:!!:18443::::::
admin:!$1$lh/y5SVj$LYIcvRwMHz7pRtLc7/KGl0:18443::::::
ssm-user:!!:18493:0:99999:7:::

通常のインスタンスでは!!になっています。

通常の Amazon Linux 2インスタンス

[root@ip-192-168-0-56 ~]# cat /etc/shadow
root:*LOCK*:14600::::::
bin:*:16323:0:99999:7:::
daemon:*:16323:0:99999:7:::
adm:*:16323:0:99999:7:::
lp:*:16323:0:99999:7:::
sync:*:16323:0:99999:7:::
shutdown:*:16323:0:99999:7:::
halt:*:16323:0:99999:7:::
mail:*:16323:0:99999:7:::
uucp:*:16323:0:99999:7:::
operator:*:16323:0:99999:7:::
games:*:16323:0:99999:7:::
gopher:*:16323:0:99999:7:::
ftp:*:16323:0:99999:7:::
nobody:*:16323:0:99999:7:::
rpc:!!:17851:0:99999:7:::
ntp:!!:17851::::::
saslauth:!!:17851::::::
mailnull:!!:17851::::::
smmsp:!!:17851::::::
rpcuser:!!:17851::::::
nfsnobody:!!:17851::::::
sshd:!!:17851::::::
dbus:!!:17851::::::
ssm-user:!!:18493:0:99999:7:::
ec2-user:!!:18493:0:99999:7:::

/etc/shadow の読み方を散々調べたのですが、!!*の違いについて、これだ!というソースをうまく見つけられませんでした。(知っている方がいたら教えてください。)

ちなみにec2-userのホームディレクトリはありませんし、キーペアを用いての SSH 接続はできません。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# ls -la /home
total 16
drwxr-xr-x  4 root     root     4096 Aug 19 11:09 .
dr-xr-xr-x 25 root     root     4096 Aug 19 11:09 ..
drwxr-xr-x  4 admin    admin    4096 Aug 19 11:09 sguser
drwx------  2 ssm-user ssm-user 4096 Aug 19 11:09 ssm-user

/etc/group

ユーザーの差分は 3 つでしたが、グループの差分は 5 つありました。wiresharkとかどこから出てきたんだろう……というのは気になります。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# cat /etc/group
root:x:0:
bin:x:1:bin,daemon
daemon:x:2:bin,daemon
sys:x:3:bin,adm
adm:x:4:adm,daemon
tty:x:5:
disk:x:6:,sgserver
lp:x:7:daemon
mem:x:8:
kmem:x:9:
wheel:x:10:ec2-user
mail:x:12:mail
uucp:x:14:
man:x:15:
games:x:20:
gopher:x:30:
video:x:39:
dip:x:40:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
rpc:x:32:
cdrom:x:11:
tape:x:33:
dialout:x:18:
floppy:x:19:
ssh_keys:x:499:
ntp:x:38:
cgred:x:498:
saslauth:x:76:
mailnull:x:47:
smmsp:x:51:
rpcuser:x:29:
nfsnobody:x:65534:
sshd:x:74:
dbus:x:81:
screen:x:84:
ec2-user:x:500:
printadmin:x:497:
wireshark:x:496:
tcpdump:x:72:
sgserver:x:495:
admin:x:494:
ssm-user:x:501:

admin ユーザーのホームディレクトリ

adminユーザーのホームディレクトリは/home/sguserとして用意されています。

envというディレクトリのみが存在したので中身を調べると、以下のようになっていました。

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 env]# ls -la /home/sguser/env/
total 16
drwxr-xr-x 2 root  root  4096 Aug 19 11:09 .
drwxr-xr-x 4 admin admin 4096 Aug 19 11:09 ..
lrwxrwxrwx 1 root  root    47 Aug 19 11:09 exit -> /usr/local/aws-storage-gateway/console/bin/exit
lrwxrwxrwx 1 root  root    44 Aug 19 11:09 h -> /usr/local/aws-storage-gateway/console/bin/h
lrwxrwxrwx 1 root  root    51 Aug 19 11:09 ifconfig -> /usr/local/aws-storage-gateway/console/bin/ifconfig
lrwxrwxrwx 1 root  root    45 Aug 19 11:09 ip -> /usr/local/aws-storage-gateway/console/bin/ip
lrwxrwxrwx 1 root  root    51 Aug 19 11:09 iptables -> /usr/local/aws-storage-gateway/console/bin/iptables
lrwxrwxrwx 1 root  root    63 Aug 19 11:09 open-support-channel -> /usr/local/aws-storage-gateway/console/bin/open-support-channel
lrwxrwxrwx 1 root  root    56 Aug 19 11:09 save-iptables -> /usr/local/aws-storage-gateway/console/bin/save-iptables
lrwxrwxrwx 1 root  root    61 Aug 19 11:09 save-routing-table -> /usr/local/aws-storage-gateway/console/bin/save-routing-table

/usr/local/aws-storage-gateway

シンボリックリンク先の/usr/local/aws-storage-gateway/の内訳は以下のようになっています。

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 env]# tree /usr/local/aws-storage-gateway/
/usr/local/aws-storage-gateway/
├── appliance_console -> /usr/local/aws-storage-gateway-5.0.345.0/appliance_console
├── boot-resource-check -> /usr/local/aws-storage-gateway-5.0.345.0/boot-resource-check
├── config
│   └── coral-config-thinstaller
│       ├── FmrsAgentActivationServiceClientConfig-1.0
│       │   └── coral-config
│       │       └── FmrsAgentActivationServiceCommon-global.config -> /usr/local/aws-storage-gateway-5.0.345.0/config/coral-config/FmrsAgentActivationServiceClientConfig-1.0/coral-config/FmrsAgentActivationServiceCommon-global.config
│       └── FmrsControlPlaneServiceClientConfig-1.0
│           └── coral-config
│               ├── FmrsControlPlaneServiceCommon-global.config -> /usr/local/aws-storage-gateway-5.0.345.0/config/coral-config/FmrsControlPlaneServiceClientConfig-1.0/coral-config/FmrsControlPlaneServiceCommon-global.config
│               └── FmrsControlPlaneService-prod.config -> /usr/local/aws-storage-gateway-5.0.345.0/config/coral-config/FmrsControlPlaneServiceClientConfig-1.0/coral-config/FmrsControlPlaneService-prod.config
├── console
│   ├── bashrc -> /usr/local/aws-storage-gateway-5.0.345.0/console/bashrc
│   ├── bin
│   │   ├── grant-aws-support-access -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/grant-aws-support-access
│   │   ├── h -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/h
│   │   ├── ifconfig -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/ifconfig
│   │   ├── ip -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/ip
│   │   ├── iptables -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/iptables
│   │   ├── open-support-channel -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/open-support-channel
│   │   ├── passwd -> /usr/bin/passwd
│   │   ├── revoke-aws-support-access -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/revoke-aws-support-access
│   │   ├── save-iptables -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/save-iptables
│   │   ├── save-routing-table -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/save-routing-table
│   │   └── testconn -> /usr/local/aws-storage-gateway-5.0.345.0/console/bin/testconn
│   ├── commands
│   │   ├── 200_network_configuration.sh -> /usr/local/aws-storage-gateway-5.0.345.0/console/commands/200_network_configuration.sh
│   │   ├── 210_connectivity_tests.sh -> /usr/local/aws-storage-gateway-5.0.345.0/console/commands/210_connectivity_tests.sh
│   │   ├── 300_system_resource_check.sh -> /usr/local/aws-storage-gateway-5.0.345.0/console/commands/300_system_resource_check.sh
│   │   ├── 400_system_time_management.sh -> /usr/local/aws-storage-gateway-5.0.345.0/console/commands/400_system_time_management.sh
│   │   └── 500_command_prompt.sh -> /usr/local/aws-storage-gateway-5.0.345.0/console/commands/500_command_prompt.sh
│   ├── console_env_var -> /usr/local/aws-storage-gateway-5.0.345.0/console/console_env_var
│   ├── ec2_command -> /usr/local/aws-storage-gateway-5.0.345.0/console/ec2_command
│   ├── gateway.pem -> /usr/local/aws-storage-gateway-5.0.345.0/console/gateway.pem
│   ├── init_console -> /usr/local/aws-storage-gateway-5.0.345.0/console/init_console
│   ├── onpremise_command -> /usr/local/aws-storage-gateway-5.0.345.0/console/onpremise_command
│   └── support-host -> /usr/local/aws-storage-gateway-5.0.345.0/console/support-host
├── creds
│   ├── authorized_keys -> /usr/local/aws-storage-gateway-5.0.345.0/creds/authorized_keys
│   └── known_hosts -> /usr/local/aws-storage-gateway-5.0.345.0/creds/known_hosts
├── diagnostics
│   └── supportrc -> /usr/local/aws-storage-gateway-5.0.345.0/diagnostics/supportrc
├── ec2Indicator.txt
├── FmrsThinstaller.jar -> /usr/local/aws-storage-gateway-5.0.345.0/FmrsThinstaller.jar
├── gateway-ip -> /usr/local/aws-storage-gateway-5.0.345.0/gateway-ip
├── truststore
│   └── InternalAndExternalTrustStore.jks -> /usr/local/aws-storage-gateway-5.0.345.0/truststore/InternalAndExternalTrustStore.jks
└── var
    ├── bootcheck-results.txt
    ├── output
    │   └── logs
    │       ├── access_log
    │       ├── service_log
    │       ├── Thinstaller.log.2020-06-30-21
    │       └── Thinstaller.log.2020-08-19-11
    └── syncCachedApplianceEndpointsFromS3

/usr/local/aws-storage-gateway-5.0.345.0

上記のディレクトリ内でもさらに/usr/local/aws-storage-gateway-5.0.345.0配下にシンボリックリンクが多く設けられているので、中身を確認します。

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# tree /usr/local/aws-storage-gateway-5.0.345.0/
/usr/local/aws-storage-gateway-5.0.345.0/
├── appliance_console
├── boot-resource-check
├── config
│   └── coral-config
│       ├── FmrsAgentActivationServiceClientConfig-1.0
│       │   └── coral-config
│       │       └── FmrsAgentActivationServiceCommon-global.config
│       └── FmrsControlPlaneServiceClientConfig-1.0
│           └── coral-config
│               ├── FmrsControlPlaneServiceCommon-global.config
│               └── FmrsControlPlaneService-prod.config
├── console
│   ├── bashrc
│   ├── bin
│   │   ├── grant-aws-support-access
│   │   ├── h
│   │   ├── ifconfig
│   │   ├── ip
│   │   ├── iptables
│   │   ├── open-support-channel
│   │   ├── revoke-aws-support-access
│   │   ├── save-iptables
│   │   ├── save-routing-table
│   │   └── testconn
│   ├── commands
│   │   ├── 200_network_configuration.sh
│   │   ├── 210_connectivity_tests.sh
│   │   ├── 300_system_resource_check.sh
│   │   ├── 400_system_time_management.sh
│   │   └── 500_command_prompt.sh
│   ├── console_env_var
│   ├── ec2_command
│   ├── gateway.pem
│   ├── init_console
│   ├── onpremise_command
│   └── support-host
├── creds
│   ├── authorized_keys
│   └── known_hosts
├── diagnostics
│   └── supportrc
├── FmrsThinstaller.jar
├── gateway-ip
├── ip-updater.sh
└── truststore
    └── InternalAndExternalTrustStore.jks

通常、ユーザーが DataSync エージェントにアクセスする際はローカルコンソールに接続することになりますが、そこで実行する内容はこのディレクトリの辺りで定義されているようです。

ローカルコンソールで操作可能な内容については以下を参照してください。

Configuring Your Agent on the VM Local Console - AWS DataSync

サービス関連

service コマンド

systemctl コマンドを打とうとするとそんなものはないと怒られたので、 service コマンドで確認します。

通常はiptables: Firewall is not running.となっている箇所が、iptables で定義されているテーブルの内容が表示されています。(アクティベート後にはエントリが消えます。)

読み方に自信がないですが、8080 ポートで受け付けた全ての通信を 80 ポートにリダイレクトしているように見えます。

加えて、末尾の 2 つも追加されていました。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# service --status-all
acpid (pid  2629) is running...
atd (pid  2741) is running...
auditd (pid  2272) is running...
cfn-hup is stopped
Stopped
cgred is stopped
Checking for service cloud-init:Checking for service cloud-init:Checking for service cloud-init:Checking for service cloud-init:crond (pid  2725) is running...
Checking hibagent...                              Service not running
Checking for service hibinit-agent:ip6tables: Firewall is not running.
Table: nat
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 8080

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination

irqbalance (pid  2311) is running...
lvmetad (pid  1709) is running...
lvmpolld (pid  1718) is running...
dmeventd is stopped
mdmonitor is stopped
messagebus (pid  2393) is running...
netconsole module not loaded
Configured devices:
lo eth0
Currently active devices:
lo eth0
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
rpc.statd (pid  2362) is running...
ntpd (pid  2664) is running...
Process accounting is disabled.
quota_nld is stopped
rdisc is stopped
rngd (pid  2321) is running...
rpcbind (pid  2341) is running...
rpc.gssd is stopped
rpc.idmapd is stopped
rpc.svcgssd is stopped
rsyslogd (pid  2293) is running...
saslauthd is stopped
sendmail is stopped
sm-client dead but pid file exists
openssh-daemon (pid  2653) is running...
VGAuthService is stopped
vmtoolsd dead but pid file exists

/etc/init.d

サービスで確認できたもの以外でもいくつか追加されているものがあります。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# ls -la /etc/init.d/
total 284
drwxr-xr-x  2 root root  4096 Aug 20 10:56 .
drwxr-xr-x 10 root root  4096 Nov 16  2018 ..
-rwxr-xr-x  1 root root  1729 Mar 27  2017 acpid
-rwxr-xr-x  1 root root  2297 Jun 30 21:22 add-sguser
-rwxr-xr-x  1 root root  2062 Aug 16  2016 atd
-rwxr-xr-x  1 root root  3448 Mar  8  2017 auditd
-rwxr-xr-x  1 root root  5834 Jul 31 15:08 aws-gateway-sync-agent
-r-xr-xr-x  1 root root  1362 Mar 30  2017 blk-availability
lrwxrwxrwx  1 root root    46 Nov 16  2018 cfn-hup -> /opt/aws/apitools/cfn-init/init/redhat/cfn-hup
-rwxr-xr-x  1 root root  5160 Feb 28  2014 cgconfig
-rwxr-xr-x  1 root root  3580 Feb 28  2014 cgred
-rwxr-xr-x  1 root root  3782 Oct  4  2018 cloud-config
-rwxr-xr-x  1 root root  3763 Oct  4  2018 cloud-final
-rwxr-xr-x  1 root root  3855 Oct  4  2018 cloud-init
-rwxr-xr-x  1 root root  3840 Oct  4  2018 cloud-init-local
-rwxr-xr-x  1 root root  2826 Sep 28  2016 crond
-rw-r--r--  1 root root 25651 Aug 17  2017 functions
-rwxr-xr-x  1 root root  6037 Aug 17  2017 halt
-rwxr-xr-x  1 root root  1395 Dec 13  2017 hibagent
-rwxr-xr-x  1 root root  2267 Nov 12  2018 hibinit-agent
-rwxr-xr-x  1 root root  8563 Sep 27  2013 ip6tables
-rwxr-xr-x  1 root root  8468 Sep 27  2013 iptables
-rwxr-xr-x  1 root root  1955 Oct 29  2018 irqbalance
-rwxr-xr-x  1 root root   652 Jan 18  2017 killall
-r-xr-xr-x  1 root root  2137 Mar 30  2017 lvm2-lvmetad
-r-xr-xr-x  1 root root  2274 Mar 30  2017 lvm2-lvmpolld
-r-xr-xr-x  1 root root  3045 Mar 30  2017 lvm2-monitor
-rwxr-xr-x  1 root root  2904 Sep 18  2014 mdmonitor
-rwxr-xr-x  1 root root  2200 Jul  2  2019 messagebus
-rwxr-xr-x  1 root root  4334 Jan 18  2017 netconsole
-rwxr-xr-x  1 root root  5309 Jan 18  2017 netfs
-rwxr-xr-x  1 root root  6742 Aug 17  2017 network
-rwxr-xr-x  1 root root  6703 Oct  8  2015 nfs
-rwxr-xr-x  1 root root  3526 Oct  8  2015 nfslock
-rwxr-xr-x  1 root root  1926 May  3  2019 ntpd
-rwxr-xr-x  1 root root  2049 May  3  2019 ntpdate
-rwxr-xr-x  1 root root  1556 Sep 10  2014 psacct
-rwxr-xr-x  1 root root  2034 Sep 27  2013 quota_nld
-rwxr-xr-x  1 root root  1515 May 17  2016 rdisc
-rwxr-xr-x  1 root root   691 Jun 30 19:59 restore-routing-table
-rwxr-xr-x  1 root root  1816 Aug 17  2017 rngd
-rwxr-xr-x  1 root root  2073 May  9  2018 rpcbind
-rwxr-xr-x  1 root root  2518 Oct  8  2015 rpcgssd
-rwxr-xr-x  1 root root  2305 Oct  8  2015 rpcidmapd
-rwxr-xr-x  1 root root  2464 Oct  8  2015 rpcsvcgssd
-rwxr-xr-x  1 root root  2011 Nov 11  2014 rsyslog
-rwxr-xr-x  1 root root  2056 Sep 10  2014 saslauthd
-rwxr-xr-x  1 root root  3702 Aug 17  2016 sendmail
-rwxr-xr-x  1 root root   647 Jan 18  2017 single
-rwxr-xr-x  1 root root  4180 Oct 23  2019 sshd
-rwxr-xr-x  1 root root  1144 Mar 25  2016 sysstat
-rwxr-xr-x  1 root root  1642 Mar 19  2014 udev-post
-rwxr-xr-x  1 root root  1873 Apr  4  2017 vgauthd
-rwxr-xr-x  1 root root  2048 Apr  4  2017 vmtoolsd

chkconfig コマンド

基本的には今まで確認した通りです。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# chkconfig
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
add-sguser      0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
blk-availability        0:off   1:on    2:on    3:on    4:on    5:on    6:off
cgconfig        0:off   1:off   2:off   3:off   4:off   5:off   6:off
cgred           0:off   1:off   2:off   3:off   4:off   5:off   6:off
cloud-config    0:off   1:off   2:on    3:on    4:on    5:on    6:off
cloud-final     0:off   1:off   2:on    3:on    4:on    5:on    6:off
cloud-init      0:off   1:off   2:on    3:on    4:on    5:on    6:off
cloud-init-local        0:off   1:off   2:on    3:on    4:on    5:on    6:off
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
hibagent        0:off   1:off   2:off   3:off   4:off   5:off   6:off
hibinit-agent   0:off   1:off   2:on    3:on    4:on    5:on    6:off
ip6tables       0:off   1:off   2:on    3:on    4:on    5:on    6:off
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
irqbalance      0:off   1:off   2:on    3:on    4:on    5:on    6:off
lvm2-lvmetad    0:off   1:on    2:on    3:on    4:on    5:on    6:off
lvm2-lvmpolld   0:off   1:on    2:on    3:on    4:on    5:on    6:off
lvm2-monitor    0:off   1:on    2:on    3:on    4:on    5:on    6:off
mdmonitor       0:off   1:off   2:on    3:on    4:on    5:on    6:off
messagebus      0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
netfs           0:off   1:off   2:off   3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
nfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off
nfslock         0:off   1:off   2:off   3:on    4:on    5:on    6:off
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
ntpdate         0:off   1:off   2:off   3:off   4:off   5:off   6:off
psacct          0:off   1:off   2:off   3:off   4:off   5:off   6:off
quota_nld       0:off   1:off   2:off   3:off   4:off   5:off   6:off
rdisc           0:off   1:off   2:off   3:off   4:off   5:off   6:off
restore-routing-table   0:off   1:off   2:on    3:on    4:on    5:on    6:off
rngd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rpcgssd         0:off   1:off   2:off   3:on    4:on    5:on    6:off
rpcsvcgssd      0:off   1:off   2:off   3:off   4:off   5:off   6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off
udev-post       0:off   1:on    2:on    3:on    4:on    5:on    6:off
vgauthd         0:off   1:off   2:on    3:on    4:on    5:on    6:off
vmtoolsd        0:off   1:off   2:on    3:on    4:on    5:on    6:off

プロセス・ポート関連

netstat コマンド

アクティベート時には TCP 80 で通信が必要なため、起動した時点でリッスンしているのかと想像していましたが、そういったわけではないようでした。

後続でここに関連する内容が出てきますが、サーバ としては TCP 8080 でリッスンするようです。通常のインスタンスとの違いはこの箇所のみです。そう言えば iptables でリダイレクトしていたのもきっとここに関係していますね。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2323/rpcbind
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      2756/java
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2637/sshd
tcp        0      0 0.0.0.0:39261               0.0.0.0:*                   LISTEN      2344/rpc.statd
tcp        0      0 192.168.0.176:57576         52.119.220.97:443           ESTABLISHED 2800/amazon-ssm-age
tcp        0    341 192.168.0.176:57646         52.119.220.97:443           ESTABLISHED 2971/ssm-session-wo
tcp        0      0 192.168.0.176:39056         54.240.225.173:443          ESTABLISHED 2800/amazon-ssm-age
tcp        0      0 192.168.0.176:39610         52.119.221.73:443           TIME_WAIT   -
tcp        0      0 :::111                      :::*                        LISTEN      2323/rpcbind
tcp        0      0 :::22                       :::*                        LISTEN      2637/sshd
tcp        0      0 :::57697                    :::*                        LISTEN      2344/rpc.statd
udp        0      0 0.0.0.0:42642               0.0.0.0:*                               2344/rpc.statd
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1919/dhclient
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2323/rpcbind
udp        0      0 192.168.0.176:123           0.0.0.0:*                               2648/ntpd
udp        0      0 127.0.0.1:123               0.0.0.0:*                               2648/ntpd
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2648/ntpd
udp        0      0 0.0.0.0:800                 0.0.0.0:*                               2323/rpcbind
udp        0      0 127.0.0.1:824               0.0.0.0:*                               2344/rpc.statd
udp        0      0 :::52251                    :::*                                    2344/rpc.statd
udp        0      0 :::111                      :::*                                    2323/rpcbind
udp        0      0 :::800                      :::*                                    2323/rpcbind
--- 略 ---

ちなみにアクティベートが済むと 8080 のリッスンは無くなり、いくつかリッスンポートが増えます。

パブリックサービスエンドポイント向けと思われる 443 向けのアウトバウンド通信も増えています。

アクティベート後

[root@ip-192-168-0-176 ~]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 127.0.0.1:9090              0.0.0.0:*                   LISTEN      4442/java
tcp        0      0 127.0.0.1:9091              0.0.0.0:*                   LISTEN      4091/fmrsd
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2341/rpcbind
tcp        0      0 0.0.0.0:38613               0.0.0.0:*                   LISTEN      2362/rpc.statd
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2653/sshd
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      4091/fmrsd
tcp        0      0 192.168.0.146:50532         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 192.168.0.146:50538         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0    341 192.168.0.146:35634         52.119.220.97:443           ESTABLISHED 2953/ssm-session-wo
tcp        0      0 192.168.0.146:50544         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 192.168.0.146:50542         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 192.168.0.146:35594         52.119.220.97:443           ESTABLISHED 2817/amazon-ssm-age
tcp        0      0 192.168.0.146:51372         54.240.225.178:443          ESTABLISHED 2817/amazon-ssm-age
tcp        0      0 192.168.0.146:50534         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 192.168.0.146:50536         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 192.168.0.146:50540         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 192.168.0.146:50546         54.65.3.60:443              ESTABLISHED 4442/java
tcp        0      0 :::111                      :::*                        LISTEN      2341/rpcbind
tcp        0      0 :::22                       :::*                        LISTEN      2653/sshd
tcp        0      0 :::47835                    :::*                        LISTEN      2362/rpc.statd
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1935/dhclient
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               2341/rpcbind
udp        0      0 192.168.0.146:123           0.0.0.0:*                               2664/ntpd
udp        0      0 127.0.0.1:123               0.0.0.0:*                               2664/ntpd
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2664/ntpd
udp        0      0 0.0.0.0:818                 0.0.0.0:*                               2341/rpcbind
udp        0      0 127.0.0.1:842               0.0.0.0:*                               2362/rpc.statd
udp        0      0 0.0.0.0:40678               0.0.0.0:*                               2362/rpc.statd
udp        0      0 :::111                      :::*                                    2341/rpcbind
udp        0      0 :::818                      :::*                                    2341/rpcbind
udp        0      0 :::35955                    :::*                                    2362/rpc.statd
--- 略 ---

lsof コマンド

lsofコマンドで確認しても同様です。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# lsof -i -P
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhclient  1919     root    5u  IPv4   1918      0t0  UDP *:68
rpcbind   2323      rpc    6u  IPv4  13266      0t0  UDP *:111
rpcbind   2323      rpc    7u  IPv4  13267      0t0  UDP *:800
rpcbind   2323      rpc    8u  IPv4  13268      0t0  TCP *:111 (LISTEN)
rpcbind   2323      rpc    9u  IPv6  13269      0t0  UDP *:111
rpcbind   2323      rpc   10u  IPv6  13270      0t0  UDP *:800
rpcbind   2323      rpc   11u  IPv6  13271      0t0  TCP *:111 (LISTEN)
rpc.statd 2344  rpcuser    5u  IPv4  11504      0t0  UDP localhost:824
rpc.statd 2344  rpcuser    8u  IPv4  15413      0t0  UDP *:42642
rpc.statd 2344  rpcuser    9u  IPv4  15415      0t0  TCP *:39261 (LISTEN)
rpc.statd 2344  rpcuser   10u  IPv6  15417      0t0  UDP *:52251
rpc.statd 2344  rpcuser   11u  IPv6  15419      0t0  TCP *:57697 (LISTEN)
sshd      2637     root    3u  IPv4  11555      0t0  TCP *:22 (LISTEN)
sshd      2637     root    4u  IPv6  11557      0t0  TCP *:22 (LISTEN)
ntpd      2648      ntp   16u  IPv4  15718      0t0  UDP *:123
ntpd      2648      ntp   17u  IPv4  15723      0t0  UDP localhost:123
ntpd      2648      ntp   18u  IPv4  15725      0t0  UDP ip-192-168-0-176.ap-northeast-1.compute.internal:123
java      2756 sgserver   25u  IPv4  15842      0t0  TCP *:8080 (LISTEN)
amazon-ss 2800     root    7u  IPv4  14201      0t0  TCP ip-192-168-0-176.ap-northeast-1.compute.internal:39422->54.240.225.178:443 (ESTABLISHED)
amazon-ss 2800     root   12u  IPv4  13668      0t0  TCP ip-192-168-0-176.ap-northeast-1.compute.internal:57576->52.119.220.97:443 (ESTABLISHED)
ssm-sessi 2971     root   19u  IPv4  11743      0t0  TCP ip-192-168-0-176.ap-northeast-1.compute.internal:57646->52.119.220.97:443 (ESTABLISHED)

アクティベート後に再度実行したのですが、-pをつけ忘れました。(うっかり)

アクティベート後

[root@ip-192-168-0-146 ~]# lsof -i
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhclient  1935     root    5u  IPv4   1304      0t0  UDP *:bootpc
rpcbind   2341      rpc    6u  IPv4  11994      0t0  UDP *:sunrpc
rpcbind   2341      rpc    7u  IPv4  11995      0t0  UDP *:818
rpcbind   2341      rpc    8u  IPv4  11996      0t0  TCP *:sunrpc (LISTEN)
rpcbind   2341      rpc    9u  IPv6  11997      0t0  UDP *:sunrpc
rpcbind   2341      rpc   10u  IPv6  11998      0t0  UDP *:818
rpcbind   2341      rpc   11u  IPv6  11999      0t0  TCP *:sunrpc (LISTEN)
rpc.statd 2362  rpcuser    5u  IPv4  13648      0t0  UDP localhost:842
rpc.statd 2362  rpcuser    8u  IPv4    923      0t0  UDP *:40678
rpc.statd 2362  rpcuser    9u  IPv4    925      0t0  TCP *:38613 (LISTEN)
rpc.statd 2362  rpcuser   10u  IPv6    927      0t0  UDP *:35955
rpc.statd 2362  rpcuser   11u  IPv6    929      0t0  TCP *:47835 (LISTEN)
sshd      2653     root    3u  IPv4   2297      0t0  TCP *:ssh (LISTEN)
sshd      2653     root    4u  IPv6   2299      0t0  TCP *:ssh (LISTEN)
ntpd      2664      ntp   16u  IPv4  15565      0t0  UDP *:ntp
ntpd      2664      ntp   17u  IPv4  15570      0t0  UDP localhost:ntp
ntpd      2664      ntp   18u  IPv4  15572      0t0  UDP ip-192-168-0-146.ap-northeast-1.compute.internal:ntp
amazon-ss 2817     root    7u  IPv4  50918      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:43344->54.240.225.173:https (ESTABLISHED)
amazon-ss 2817     root   12u  IPv4  12654      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:35594->52.119.220.97:https (ESTABLISHED)
ssm-sessi 2953     root   20u  IPv4  15133      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:35634->52.119.220.97:https (ESTABLISHED)
fmrsd     4091     root    7u  IPv4   2675      0t0  TCP localhost:xmltec-xmlmail (LISTEN)
fmrsd     4091     root   10u  IPv4  19824      0t0  TCP *:https (LISTEN)
java      4442 sgserver   69u  IPv4  23676      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50532->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   70u  IPv4  14311      0t0  TCP localhost:websm (LISTEN)
java      4442 sgserver   71u  IPv4  20859      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50546->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   72u  IPv4  16166      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50536->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   73u  IPv4   1860      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50542->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   74u  IPv4  19032      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50538->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   75u  IPv4  14312      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50540->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   76u  IPv4   1861      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50534->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)
java      4442 sgserver   77u  IPv4  19851      0t0  TCP ip-192-168-0-146.ap-northeast-1.compute.internal:50544->ec2-54-65-3-60.ap-northeast-1.compute.amazonaws.com:https (ESTABLISHED)

pstree コマンド

プロセスを確認してみると、ハイライト部が通常のインスタンスと異なります。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# pstree -a
init
  ├─acpid
  ├─agetty ttyS0 9600 vt100-nav
  ├─amazon-ssm-agen
  │   ├─ssm-session-wor cm-chiba.yukihiro-05e65802da1da7f1f i-096172280137100de
  │   │   ├─sh
  │   │   │   └─sudo su -
  │   │   │       └─su -
  │   │   │           └─bash
  │   │   │               └─pstree -a
  │   │   └─17*[{ssm-session-wor}]
  │   └─24*[{amazon-ssm-agen}]
  ├─anacron -s
  ├─atd
  ├─auditd
  │   └─{auditd}
  ├─crond
  │   └─crond
  │       └─sh -c /usr/local/bin/launch-thinstaller >/dev/null 2>&1
  │           └─launch-thinstal /usr/local/bin/launch-thinstaller
  │               └─su -c /opt/jre/bin/java -DCORAL_CONFIG_PATH=config/coral-config-thinstaller -Dsgw.proxy.file=/var/aws-storage-gateway/config/proxy.properties -jar FmrsThinstaller.jar ...
  │                   └─java -DCORAL_CONFIG_PATH=config/coral-config-thinstaller -Dsgw.proxy.file=/var/aws-storage-gateway/config/proxy.properties -jar FmrsThinstaller.jar
  │                       └─22*[{java}]
  ├─dbus-daemon --system
  ├─dhclient -q -lf /var/lib/dhclient/dhclient-eth0.leases -pf /var/run/dhclient-eth0.pid eth0
  ├─irqbalance --pid=/var/run/irqbalance.pid --hintpolicy=subset
  │   └─{irqbalance}
  ├─lvmetad
  ├─lvmpolld
  ├─mingetty /dev/tty1
  ├─mingetty /dev/tty2
  ├─mingetty /dev/tty3
  ├─mingetty /dev/tty4
  ├─mingetty /dev/tty5
  ├─mingetty /dev/tty6
  ├─ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
  │   └─{ntpd}
  ├─rngd --no-tpm=1 --quiet
  ├─rpc.statd
  ├─rpcbind
  ├─rsyslogd -i /var/run/syslogd.pid -c 5
  │   └─3*[{rsyslogd}]
  ├─sshd
  └─udevd -d
      ├─udevd -d
      └─udevd -d

アクティベート後には crond 配下が無くなり、以下が追加されます。

アクティベート後

  ├─su -c /opt/jre/bin/java  -Xms128m -Xmx384m -DCORAL_CONFIG_PATH=config/coral-config -jar FmrsAgent.jar -m -s /bin/bash sgserver
  │   └─java -Xms128m -Xmx384m -DCORAL_CONFIG_PATH=config/coral-config -jar FmrsAgent.jar
  │       └─80*[{java}]

ローンチ時に呼び出されているファイルがあるので、それを確認してみます。

/usr/local/bin

インストール時に実行する内容が定義されています。

アクティベート用に必要なのは 80 番ポートなのにリッスンしていたのは 8080 だった、という点については、ここでマッピングが行われていることが答えになりそうです。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# cat /usr/local/bin/launch-thinstaller
#!/bin/bash
#
# Launch a single instance of Thinstaller.jar

source /etc/aws-storage-gateway.config

THINSTALLER_JAR=FmrsThinstaller.jar
ACTIVATION_PORT=8080
REDIRECT_RULE=(PREROUTING -p tcp -j REDIRECT --to-port $ACTIVATION_PORT --dport 80)
LOG_DIRECTORY="$SGW_WORKING_DIR/var/output/logs"
LOG_FILE_NAME="$LOG_DIRECTORY/Thinstaller.log.$(date +%F-%H)"
JAVA=/usr/bin/java
[[ -e /opt/jre ]] && JAVA=/opt/jre/bin/java
JAVA_FLAGS="-DCORAL_CONFIG_PATH=config/coral-config-thinstaller -Dsgw.proxy.file=$SGW_CONFIG_DIR/proxy.properties"

log() {
    echo -e "$(date) [$$] $0: $@"
}

is_ec2() {
    [[ -e "$SGW_WORKING_DIR/ec2Indicator.txt" ]]
}

is_install_stage() {
    [[ -e "$SGW_WORKING_DIR/var/activation-indicator" ]]
}

is_activated() {
    [[ -f "$SGW_WORKING_DIR/var/cert.pem" ]]
}

map_http_port() {
    if /sbin/iptables -nL -t nat | grep -q " ${ACTIVATION_PORT}$"; then
        return 0
    fi

    log "re-establishing port 80 -> 8080 mapping"
    # Set up the iptables mapping of port 80 to 8080 to avoid requiring root to activate.
    /sbin/iptables -t nat -I ${REDIRECT_RULE[@]}
    if ! is_ec2; then
        # CentOs default firewall rules block port 8080, so we need to open it.
        /sbin/iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport $ACTIVATION_PORT -j ACCEPT
    fi
}

unmap_http_port() {
    if ! /sbin/iptables -nL -t nat | grep -q " ${ACTIVATION_PORT}$"; then
        return 0
    fi

    log "removing port 80 -> 8080 mapping"
    /sbin/iptables -t nat -D ${REDIRECT_RULE[@]}
    if ! is_ec2; then
        /sbin/iptables -D RH-Firewall-1-INPUT -p tcp --dport $ACTIVATION_PORT -j ACCEPT
    fi
}

run_thinstaller_jar() {
    if is_activated; then
        log "running thinstaller with 3600 seconds timeout"
        # After activation thinstaller should not run for more than an hour
        /usr/bin/timeout 3600 su -c "$JAVA $JAVA_FLAGS -jar $THINSTALLER_JAR" -m sgserver
    else
        # Before activation thinstaller could be running for long
        su -c "$JAVA $JAVA_FLAGS -jar $THINSTALLER_JAR" -m sgserver
    fi
}

fix_log_dir_permissions() {
    [[ -d "$LOG_DIRECTORY" ]] || mkdir -p "$LOG_DIRECTORY"
    chown sgserver:sgserver "$SGW_WORKING_DIR"/var/*
    chown -RL sgserver:sgserver "$LOG_DIRECTORY"
}

fix_port_mapping() {
    if is_activated; then
        unmap_http_port
    else
        map_http_port
    fi
}

idempotency_check() {
    if /usr/bin/pgrep -f $THINSTALLER_JAR >/dev/null; then
        # check for restart indicator
        RESTART_INDICATOR="$SGW_CONFIG_DIR/restart-indicator"
        if [[ -f "$RESTART_INDICATOR" && ! -f "$ACTIVATED_INDICATOR" ]]; then
            /usr/bin/pkill -f $THINSTALLER_JAR >/dev/null || exit 1
            rm -f "$RESTART_INDICATOR"
        else
            log "another instance already running - end"
            exit 0
        fi
    fi
}

run_thinstaller() {
    cd "$SGW_WORKING_DIR"
    export SGW_GLOBAL_COMPONENT_VERSION
    log "running Thinstaller"
    run_thinstaller_jar
}

# MAIN
exec &>> "$LOG_FILE_NAME"
log "starting Thinstaller"
fix_log_dir_permissions
fix_port_mapping
idempotency_check
run_thinstaller
if is_install_stage; then
    log "relaunching Thinstaller for installation stage"
    run_thinstaller_jar
fi
log "end"

上記のファイルで source として指定されている config は以下のようになっていました。

[root@ip-192-168-0-176 ~]# cat /etc/aws-storage-gateway.config
SGW_CONFIG_DIR=/var/aws-storage-gateway/config
SGW_GLOBAL_COMPONENT_VERSION=5.0.345.0
SGW_LOCAL_USER=admin
SGW_WORKING_DIR=/usr/local/aws-storage-gateway

/etc 配下に config が配置されていたので、ついでにawsの名称がつくものを確認してみました。

[root@ip-192-168-0-176 ~]# ls -la /etc | grep aws
-rw-rw-rw-   1 root root       0 Jun 30 21:22 aws-sg-routingtable
-rw-rw-rw-   1 root root       0 Jun 30 21:22 aws-sg-temp-routingtable
-rw-r--r--   1 root root     154 Jun 30 21:22 aws-storage-gateway.config
-rw-r--r--   1 root root    1908 Jun 30 19:59 ntp.conf.aws-storage-gateway

/usr/local/bin 以下にもう一つファイルがあったのでついでに確認します。

[root@ip-192-168-0-176 ~]# cat /usr/local/bin/bootcheck-thinstaller
#!/bin/bash
#
# Run the bootcheck process. Multiple running instances are allowed,
# but unrealistic since expectation is to execute this only
# periodically.

source /etc/aws-storage-gateway.config
source "$SGW_WORKING_DIR/boot-resource-check"
bootcheck_start

ファイルシステム関連

Storage Gateway がインストールされたことで何か変化があるのかな?と思っていたのですが、特に通常のインスタンスと変わりありませんでした。

df コマンド

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
devtmpfs       devtmpfs  16050644      68  16050576   1% /dev
tmpfs          tmpfs     16061324       0  16061324   0% /dev/shm
/dev/nvme0n1p1 ext4      82436764 2075188  80261328   3% /

fdisk コマンド

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/nvme0n1: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt


#         Start          End    Size  Type            Name
 1         4096    167772126     80G  Linux filesyste Linux
128         2048         4095      1M  BIOS boot parti BIOS Boot Partition

lsblk コマンド

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0  80G  0 disk
├─nvme0n1p1   259:1    0  80G  0 part /
└─nvme0n1p128 259:2    0   1M  0 part

リソース関連

ストレージを確認したついでにメモリや CPU の使用状況も確認してみます。とはいえ、単にデプロイしてアクティベートしただけで DataSync タスクの実行も一切行っていないのでほぼ下限に張り付きです。

ちなみに今回は m5.2xlarge を使用しているので、 8 vCPU 、メモリ 32 GiB です。

top コマンド

アクティベート後

top - 12:44:54 up 7 min,  0 users,  load average: 0.00, 0.02, 0.00
Tasks: 128 total,   1 running,  74 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  32122644k total,   950412k used, 31172232k free,    11064k buffers
Swap:        0k total,        0k used,        0k free,   295248k cached

free コマンド

-mオプションを使用しているのでメガバイト単位での表示です。

アクティベート後

sh-4.2$ free -m
             total       used       free     shared    buffers     cached
Mem:         31369        935      30434          0         11        289
-/+ buffers/cache:        634      30734
Swap:            0          0          0

vmstat コマンド

いつまで経っても見方が覚えられません。

アクティベート後

sh-4.2$ vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 31164856  11532 296372    0    0    57     5   98  269  1  0 99  0  0

cloud-init 関連

/etc/cloud/cloud.cfg

cloud-init の実行内容を定義する/etc/cloud/cloud.cfgは通常のものと変わりありません。cloud.cfg.d配下に格納されているファイルに違いがあります。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# ls -la /etc/cloud/
total 20
drwxr-xr-x   4 root root 4096 Nov 16  2018 .
drwxrwxr-x+ 83 root root 4096 Aug 19 11:09 ..
-rw-r--r--   1 root root  559 Oct  4  2018 cloud.cfg
drwxr-xr-x   2 root root 4096 Jun 30 21:22 cloud.cfg.d
drwxr-xr-x   2 root root 4096 Nov 16  2018 templates

/etc/cloud/cloud.cfg.d

通常のインスタンスにはない100_sguser_only.cfgというファイルが存在します。

Datasyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# ls -la /etc/cloud/cloud.cfg.d/
total 28
drwxr-xr-x 2 root root 4096 Jun 30 21:22 .
drwxr-xr-x 4 root root 4096 Nov 16  2018 ..
-rw-r--r-- 1 root root 2610 Oct  4  2018 00_defaults.cfg
-rw-r--r-- 1 root root 1963 Oct  4  2018 05_logging.cfg
-rw-r--r-- 1 root root  312 Jun 30 21:22 100_sguser_only.cfg
-rw-r--r-- 1 root root  586 Apr 11  2018 10_aws_yumvars.cfg
-rw-r--r-- 1 root root  141 Oct 10  2014 README

内訳としては以下のようになっています。adminユーザーをセットアップする処理が書かれていますね。

DataSyncエージェントインスタンス

[root@ip-192-168-0-176 ~]# cat /etc/cloud/cloud.cfg.d/100_sguser_only.cfg
#cloud-config

##
# Override system user so that sguser (admin) ssh auth keys gets filled with EC2 instance keypair
#
system_info:
  default_user:
    name: admin
    homedir: /home/sguser
    lock_passwd: true
    gecos: SGW Local User
    groups: [ wheel ]

runcmd:
 - [ "rm -rf /root/.ssh/authorized_keys" ]

通常の Amazon Linux と異なりec2-userを無効化するような処理をどこかで行っているのだろうと思いつつ、該当する箇所を確認することができませんでした。

/var/lib/cloud

DataSync エージェントインスタンス特有の設定内容は無いのですが、こういう構造になっているんだ、と改めて見て興味深かかった/var/lib/cloud配下を載せておきます。

動作確認を行なったインスタンスはi-096172280137100deなのですが、それとは異なるインスタンスの ID もディレクトリ名として存在します。 AMI のベースとなったインスタンスの ID かと思っています。(通常の Amzon Linux インスタンスには存在しませんでした。)

Datasyncエージェントインスタンス

root@ip-192-168-0-176 ~]# tree /var/lib/cloud/
/var/lib/cloud/
├── data
│   ├── instance-id
│   ├── previous-datasource
│   ├── previous-instance-id
│   ├── result.json
│   └── status.json
├── handlers
├── instance -> /var/lib/cloud/instances/i-096172280137100de
├── instances
│   ├── i-061becb0c1eaxxx32
│   │   ├── cloud-config.txt
│   │   ├── datasource
│   │   ├── handlers
│   │   ├── obj.pkl
│   │   ├── scripts
│   │   ├── sem
│   │   │   ├── config_keys_to_console
│   │   │   ├── config_locale
│   │   │   ├── config_mounts
│   │   │   ├── config_package_update_upgrade_install
│   │   │   ├── config_phone_home
│   │   │   ├── config_power_state_change
│   │   │   ├── config_puppet
│   │   │   ├── config_resolv_conf
│   │   │   ├── config_rsyslog
│   │   │   ├── config_runcmd
│   │   │   ├── config_scripts_per_instance
│   │   │   ├── config_scripts_user
│   │   │   ├── config_set_hostname
│   │   │   ├── config_set_passwords
│   │   │   ├── config_ssh
│   │   │   ├── config_ssh_authkey_fingerprints
│   │   │   ├── config_timezone
│   │   │   ├── config_users_groups
│   │   │   ├── config_write_files
│   │   │   ├── config_write_metadata
│   │   │   ├── config_yum_add_repo
│   │   │   ├── config_yum_configure
│   │   │   └── consume_data
│   │   ├── user-data.txt
│   │   ├── user-data.txt.i
│   │   ├── vendor-data.txt
│   │   └── vendor-data.txt.i
│   └── i-096172280137100de
│       ├── boot-finished
│       ├── cloud-config.txt
│       ├── datasource
│       ├── handlers
│       ├── obj.pkl
│       ├── scripts
│       │   ├── part-001
│       │   └── runcmd
│       ├── sem
│       │   ├── config_keys_to_console
│       │   ├── config_locale
│       │   ├── config_mounts
│       │   ├── config_package_update_upgrade_install
│       │   ├── config_phone_home
│       │   ├── config_power_state_change
│       │   ├── config_puppet
│       │   ├── config_resolv_conf
│       │   ├── config_rsyslog
│       │   ├── config_runcmd
│       │   ├── config_scripts_per_instance
│       │   ├── config_scripts_user
│       │   ├── config_set_hostname
│       │   ├── config_set_passwords
│       │   ├── config_ssh
│       │   ├── config_ssh_authkey_fingerprints
│       │   ├── config_timezone
│       │   ├── config_users_groups
│       │   ├── config_write_files
│       │   ├── config_write_metadata
│       │   ├── config_yum_add_repo
│       │   ├── config_yum_configure
│       │   └── consume_data
│       ├── user-data.txt
│       ├── user-data.txt.i
│       ├── vendor-data.txt
│       └── vendor-data.txt.i
├── scripts
│   ├── per-boot
│   ├── per-instance
│   ├── per-once
│   └── vendor
├── seed
└── sem
    └── config_scripts_per_once.once

あらかた気になった部分のチェックが終わりました。

終わりに

DataSync エージェントをデプロイした EC2 インスタンスに接続してもろもろの情報を確認してみました。

通常はローカルコンソールに接続できればよく、OS 内部にアクセスする必要はありません。とはいえ気になってしまったので仕方がありません。ちょっと裏技チックな方式で接続したので、ここぞとばかりに思いついた限り気になる部分を確認してみました。

探究心が湧いた方の助けになれば幸いです。

以上、千葉(幸)がお送りしました。