Come posso risolvere i problemi che si verificano quando configuro SSM Agent per utilizzare un proxy per gestire l’istanza Amazon EC2?

6 minuti di lettura
0

Ricevo errori quando utilizzo un proxy con SSM Agent per gestire l’istanza Amazon Elastic Compute Cloud (Amazon EC2) con AWS Systems Manager. Come posso risolvere i problemi relativi ai proxy?

Descrizione breve

Puoi usare Systems Manager per gestire le istanze Amazon EC2. Tuttavia, se le istanze sono protette da un proxy, devi configurare SSM Agent per comunicare con gli endpoint Amazon tramite il proxy. Se SSM Agent non è configurato correttamente, viene visualizzato un messaggio di errore simile al seguente:

Post https://ssm.RegionID.amazonaws.com/: proxyconnect tcp: dial tcp xxx.xxx.xxx.xxx:yyyy: i/o timeout

Risoluzione

Per risolvere i problemi relativi al proxy, segui questi passaggi:

Verifica che l'istanza EC2 possa accedere al server proxy

Istanze EC2 per Windows

È possibile utilizzare il seguente comando di Windows PowerShell per verificare la connettività al proxy. Nell'esempio seguente, sostituisci hostname con il nome host del proxy e sostituisci port con la porta del proxy.

> Test-NetConnection hostname -port port

Output previsto:

ComputerName     : hostname
RemoteAddress    : xxx.xxx.xxx.xxx
RemotePort       : port
InterfaceAlias   : Ethernet
SourceAddress    : YYY.YYY.YYY.YYY
TcpTestSucceeded : True
PS C:\Windows\system32>

Istanze Linux EC2

È possibile utilizzare i seguenti comandi telnet o netcat per verificare la connettività al proxy. Negli esempi seguenti, sostituisci hostname con il nome host del proxy e sostituisci port con la porta del proxy.

Telnet

$ telnet hostname port

Output previsto:

Trying xxx.xxx.xxx.xxx...
Connected to hostname.
Escape character is '^]'.

Netcat

$ nc -vz hostname port'

Output previsto:

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.

Nota: Netcat non è preinstallato sulle istanze Amazon EC2. Per installare manualmente Netcat, consulta Ncat sul sito Web di Nmap.

Verifica che l’istanza EC2 possa raggiungere l'endpoint di Systems Manager tramite il server proxy

Esegui il comando seguente per verificare che l'istanza possa raggiungere l'endpoint di Systems Manager tramite il server proxy. Se ricevi il codice di errore http 4xx, significa che è possibile raggiungere l'endpoint tramite il server proxy.

Nota: nei seguenti esempi di comandi, sostituisci RegionID con la Regione AWS, sostituisci hostname con il nome host del proxy e sostituisci port con la porta del proxy.

Istanze EC2 per Windows

> (invoke-webrequest https://ssm.RegionID.amazonaws.com -DisableKeepAlive -UseBasicParsing -Method head -Proxy http://hostname:port )

Output previsto:

invoke-webrequest : The remote server returned an error: (404) Not Found.

Istanze Linux EC2

$  curl -k --proxy http://hostname:port -m 5 -s -o /dev/null -w "%{http_code}" https://ssm.RegionID.amazonaws.com

Output previsto:

404

Verifica che SSM Agent sia configurato per utilizzare le informazioni del proxy

Istanze EC2 per Windows

È necessario esaminare il log di SSM Agent per verificare che le impostazioni del proxy siano applicate, come mostra l'esempio seguente. Esegui il seguente comando:

> type C:\ProgramData\Amazon\SSM\Logs\amazon-ssm-agent.log | findstr -i "proxy"

Output previsto:

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

Per ulteriori informazioni, consulta Configure SSM Agent to use a proxy for Windows Server instances.

Istanze Linux EC2

Innanzitutto, esegui il seguente comando per verificare che SSM Agent utilizzi attualmente le variabili del proxy richieste controllando la variabile di ambiente del processo:

sudo cat /proc/$(pidof amazon-ssm-agent)/environ | xargs -0 -L1 -I{} echo {}

Output previsto:

[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

Quindi, se l'output non include le variabili del proxy, segui le istruzioni riportate di seguito per il tuo tipo di istanza, in modo da verificare e aggiornare i file pertinenti.

Istanze Linux EC2 basate su upstart come Ubuntu 14.04

Verifica che il file amazon-ssm-agent.override contenga le configurazioni richieste. Inserisci il comando seguente e verifica che l'output corrisponda a quello dell'esempio. Per ulteriori informazioni, consulta Configure SSM Agent to use a proxy (upstart).

Importante: se aggiorni il file amazon-ssm-agent.override, assicurati di riavviare SSM Agent dopo avere modificato il file.

$ cat  /etc/init/amazon-ssm-agent.override

Output previsto per un server proxy HTTP:

env http_proxy=http://hostname:port
env https_proxy=http://hostname:port
env no_proxy=169.254.169.254

Output previsto per un server proxy HTTPS:

env http_proxy=http://hostname:port
env https_proxy=https://hostname:port
env no_proxy=169.254.169.254

Istanze Linux EC2 basate su Ubuntu 16.04 o versioni successive con SSM Agent installato tramite una snapshot

Inserisci il comando seguente e verifica che le informazioni sul proxy corrispondano all'output dell'esempio. Per ulteriori informazioni, consulta Configure SSM Agent to use a proxy (systemd).

Importante: se aggiorni il file amazon-ssm-agent.override, assicurati di riavviare SSM Agent dopo avere modificato il file.

$ cat /etc/systemd/system/snap.amazon-ssm-agent.amazon-ssm-agent.service.d/override.conf

Output previsto per un server proxy HTTP:

[Service]
Environment="http_proxy=http://hostname:port"
Environment="https_proxy=http://hostname:port"
Environment="no_proxy=169.254.169.254"

Output previsto per un server proxy HTTPS:

[Service]
Environment="http_proxy=http://hostname:port"
Environment="https_proxy=https://hostname:port"
Environment="no_proxy=169.254.169.254"

Istanze Linux EC2 basate su Amazon Linux 2

Inserisci il comando seguente e verifica che le informazioni sul proxy corrispondano all'output dell'esempio. Per ulteriori informazioni, consulta Configure SSM Agent to use a proxy (systemd).

Importante: se aggiorni il file amazon-ssm-agent.override, assicurati di riavviare SSM Agent dopo avere modificato il file.

$ cat /etc/systemd/system/amazon-ssm-agent.service.d/override.conf

Output previsto per un server proxy HTTP:

[Service]
Environment="http_proxy=http://hostname:port"
Environment="https_proxy=http://hostname:port"
Environment="no_proxy=169.254.169.254"

Output previsto per un server proxy HTTPS:

[Service]
Environment="http_proxy=http://hostname:port"
Environment="https_proxy=https://hostname:port"
Environment="no_proxy=169.254.169.254"

Istanze Linux EC2 basate su altri sistemi operativi

Inserisci il comando seguente e verifica che le informazioni sul proxy corrispondano all'output dell'esempio. Per ulteriori informazioni, consulta Configure SSM Agent to use a proxy (systemd).

Importante: se aggiorni il file amazon-ssm-agent.override, assicurati di riavviare SSM Agent dopo avere modificato il file.

$ cat /etc/systemd/system/amazon-ssm-agent.service.d/amazon-ssm-agent.override

Output previsto per un server proxy HTTP:

[Service]
Environment="http_proxy=http://hostname:port"
Environment="https_proxy=http://hostname:port"
Environment="no_proxy=169.254.169.254"

Output previsto per un server proxy HTTPS:

[Service]
Environment="http_proxy=http://hostname:port"
Environment="https_proxy=https://hostname:port"
Environment="no_proxy=169.254.169.254"

Informazioni correlate

Working with SSM Agent

Troubleshooting SSM Agent

AWS UFFICIALE
AWS UFFICIALEAggiornata 3 anni fa