AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
Amazon EC2 インスタンスの管理でプロキシを使用するように SSM Agent を設定する場合の問題をトラブルシューティングする方法を教えてください。
SSM Agent でプロキシを使用し、AWS Systems Manager で Amazon Elastic Compute Cloud (Amazon EC2) インスタンスを管理すると、エラーが表示されます。プロキシの問題を解決するには、どうすればよいですか?
簡単な説明
Systems Manager を使用して Amazon EC2 インスタンスを管理できます。ただし、インスタンスがプロキシの背後にある場合は、プロキシを介して Amazon エンドポイントと通信するように SSM Agent を設定する必要があります。SSM Agent が正しく設定されていない場合、次のようなエラーメッセージが表示されます。
Post https://ssm.RegionID.amazonaws.com/: proxyconnect tcp: dial tcp xxx.xxx.xxx.xxx:yyyy: i/o timeout
解決方法
プロキシの問題のトラブルシューティングを行うには、以下の手順を実行します。
EC2 インスタンスがプロキシサーバーにアクセスできることを確認
EC2 Windows インスタンス
次の Windows PowerShell コマンドを使用して、プロキシへの接続を確認できます。次の例では、hostname をプロキシホスト名に置き換え、port をプロキシポートに置き換えます。
> Test-NetConnection hostname -port port
期待される出力:
ComputerName : hostname RemoteAddress : xxx.xxx.xxx.xxx RemotePort : port InterfaceAlias : Ethernet SourceAddress : YYY.YYY.YYY.YYY TcpTestSucceeded : True PS C:\Windows\system32>
EC2 Linux インスタンス
次の telnet コマンドまたは netcat コマンドを使用して、プロキシへの接続を確認できます。次の例では、hostname をプロキシホスト名に置き換え、port をプロキシポートに置き換えます。
Telnet
$ telnet hostname port
期待される出力:
Trying xxx.xxx.xxx.xxx... Connected to hostname. Escape character is '^]'.
Netcat
$ nc -vz hostname port'
期待される出力:
Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connected to xxx.xxx.xxx.xxx:YYYY. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
注意: Netcat は Amazon EC2 インスタンスにはプリインストールされていません。Netcat を手動でインストールするには、Nmap のウェブサイトで Ncat を参照してください。
EC2 インスタンスがプロキシサーバーを介して Systems Manager エンドポイントに到達できることを確認します
次のコマンドを実行して、インスタンスがプロキシサーバーを介して Systems Manager エンドポイントに到達できることを確認します。http エラーコード 4xx を受信すると、プロキシサーバー経由でエンドポイントに到達できることを示します。
注意: 以下のコマンド例では、RegionID を使用している AWS リージョンに置き換え、hostname を使用しているプロキシホスト名に置き換え、port を使用しているプロキシポートに置き換えます。
EC2 Windows インスタンス
> (invoke-webrequest https://ssm.RegionID.amazonaws.com -DisableKeepAlive -UseBasicParsing -Method head -Proxy http://hostname:port )
期待される出力:
invoke-webrequest : The remote server returned an error: (404) Not Found.
EC2 Linux インスタンス
$ curl -k --proxy http://hostname:port -m 5 -s -o /dev/null -w "%{http_code}" https://ssm.RegionID.amazonaws.com
期待される出力:
404
SSM Agent がプロキシ情報を使用するように設定されていることを確認します。
EC2 Windows インスタンス
次の例に示すように、SSM Agent ログを確認して、プロキシ設定が適用されていることを確認する必要があります。次のコマンドを入力します。
> type C:\ProgramData\Amazon\SSM\Logs\amazon-ssm-agent.log | findstr -i "proxy"
期待される出力:
2021-03-18 19:06:16 INFO Getting IE proxy configuration for current user: The operation completed successfully. 2021-03-18 19:06:16 INFO Getting WinHTTP proxy default configuration: The operation completed successfully. 2021-03-18 19:06:16 INFO Proxy environment variables: 2021-03-18 19:06:16 INFO http_proxy: hostname:port 2021-03-18 19:06:16 INFO https_proxy: 2021-03-18 19:06:16 INFO no_proxy: 169.254.169.254
詳細については、Windows Server インスタンスのプロキシを使用するように SSM Agent を設定するを参照してください。
EC2 Linux インスタンス
まず、次のコマンドを実行し、プロセス環境変数をチェックして、SSM Agent が現在必要なプロキシ変数を使用しているかどうかを確認します。
sudo cat /proc/$(pidof amazon-ssm-agent)/environ | xargs -0 -L1 -I{} echo {}
期待される出力:
[root@host123~]# sudo cat /proc/$(pidof amazon-ssm-agent)/environ | xargs -0 -L1 -I{} echo {} LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin http_proxy=http://Hostname:Port https_proxy=http://Hostname:Port no_proxy=169.254.169.254
次に、出力にプロキシ変数が含まれていない場合は、インスタンスタイプの以下のガイダンスに従って、関連するファイルを検証および更新します。
Ubuntu 14.04 などのアップスタートに基づく EC2 Linux インスタンス
Amazon-ssm-agent.override ファイルに必要な設定が含まれていることを確認します。次のコマンドを入力し、出力が期待される出力例と一致することを確認します。詳細については、「 プロキシを使用するように SSM Agent を設定 (アップスタート)」を参照してください。
重要: amazon-ssm-agent.override ファイルを更新する場合は、ファイルの編集後に SSM Agent を再起動してください。
$ cat /etc/init/amazon-ssm-agent.override
HTTP プロキシサーバーの期待される出力:
env http_proxy=http://hostname:port env https_proxy=http://hostname:port env no_proxy=169.254.169.254
HTTPS プロキシサーバーの期待される出力:
env http_proxy=http://hostname:port env https_proxy=https://hostname:port env no_proxy=169.254.169.254
スナップを使用して SSM Agent をインストールした Ubuntu 16.04 以降に基づいた EC2 Linux インスタンス
次のコマンドを入力し、プロキシ情報が期待される出力と一致することを確認します。詳細については、「 プロキシを使用するように SSM Agent を設定 (systemd)」を参照してください。
重要: amazon-ssm-agent.override ファイルを更新する場合は、ファイルの編集後に SSM Agent を再起動してください。
$ cat /etc/systemd/system/snap.amazon-ssm-agent.amazon-ssm-agent.service.d/override.conf
HTTP プロキシサーバーの期待される出力:
[Service] Environment="http_proxy=http://hostname:port" Environment="https_proxy=http://hostname:port" Environment="no_proxy=169.254.169.254"
HTTPS プロキシサーバーの期待される出力:
[Service] Environment="http_proxy=http://hostname:port" Environment="https_proxy=https://hostname:port" Environment="no_proxy=169.254.169.254"
Amazon Linux 2 に基づく EC2 Linux インスタンス
次のコマンドを入力し、プロキシ情報が期待される出力と一致することを確認します。詳細については、「 プロキシを使用するように SSM Agent を設定 (systemd)」を参照してください。
重要: amazon-ssm-agent.override ファイルを更新する場合は、ファイルの編集後に SSM Agent を再起動してください。
$ cat /etc/systemd/system/amazon-ssm-agent.service.d/override.conf
HTTP プロキシサーバーの期待される出力:
[Service] Environment="http_proxy=http://hostname:port" Environment="https_proxy=http://hostname:port" Environment="no_proxy=169.254.169.254"
HTTPS プロキシサーバーの期待される出力:
[Service] Environment="http_proxy=http://hostname:port" Environment="https_proxy=https://hostname:port" Environment="no_proxy=169.254.169.254"
他のオペレーティングシステムに基づいた EC2 Linux インスタンス
次のコマンドを入力し、プロキシ情報が期待される出力と一致することを確認します。詳細については、「 プロキシを使用するように SSM Agent を設定 (systemd)」を参照してください。
重要: amazon-ssm-agent.override ファイルを更新する場合は、ファイルの編集後に SSM Agent を再起動してください。
$ cat /etc/systemd/system/amazon-ssm-agent.service.d/amazon-ssm-agent.override
HTTP プロキシサーバーの期待される出力:
[Service] Environment="http_proxy=http://hostname:port" Environment="https_proxy=http://hostname:port" Environment="no_proxy=169.254.169.254"
HTTPS プロキシサーバーの期待される出力:
[Service] Environment="http_proxy=http://hostname:port" Environment="https_proxy=https://hostname:port" Environment="no_proxy=169.254.169.254"
関連情報
- 言語
- 日本語
