[AWS SSM] Systems Manager์—์„œ EC2 ์ธ์‹ ๋ถˆ๊ฐ€๋Šฅ ๋ฐ Session Manager๋ฅผ ์ด์šฉํ•˜์—ฌ EC2 ์ธ์Šคํ„ด์Šค ์—ฐ๊ฒฐ ์‹คํŒจ(Windows AMI)

2022. 5. 16. 23:57ใ†AWS/troubleshooting

โ˜„๏ธ ๋ฌธ์ œ

AWS Systems Manager(์ดํ•˜ SSM)์—์„œ ์‹ ๊ทœ๋กœ ์ƒ์„ฑํ•œ EC2๋ฅผ ์ธ์‹ํ•˜์ง€ ๋ชปํ•จ.

(SSM > Fleet Manager & Run command์—์„œ EC2 ๋ชฉ๋ก์— ํ•ด๋‹น ์ธ์Šคํ„ด์Šค ์กด์žฌํ•˜์ง€ ์•Š์Œ)

⇒ AWS EC2 ์ฝ˜์†”์—์„œ ํ•ด๋‹น EC2 ์ธ์Šคํ„ด์Šค์— session manger๋กœ ์—ฐ๊ฒฐ์ด ๋ถˆ๊ฐ€๋Šฅ.

Session Manager๋ฅผ ์ด์šฉํ•˜์—ฌ EC2 ์—ฐ๊ฒฐ ์‹คํŒจ

๐ŸŒŽ ํ™˜๊ฒฝ

  • OS : Windows 2019(AWS EC2)

 


 

๐Ÿ”ซ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

1. AWS SSM Agent ํ™•์ธ

1-1. ์ธ์Šคํ„ด์Šค ๋‚ด AWS Systems Agent(amazon-ssm-agent)๊ฐ€ ์„ค์น˜ ๋ฐ ์‹คํ–‰ ์ค‘์ธ์ง€ ํ™•์ธ.

  • ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด amazon-agent๊ฐ€ ์ตœ์‹  ๋ฒ„์ „์ธ์ง€ ํ™•์ธ ๋ฐ ์—…๋ฐ์ดํŠธ
  • ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด ssm ์—์ด์ „ํŠธ ์„ค์น˜ ๋ฐ ๊ตฌ์„ฑ
  • Windows Powershell์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ๋„ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.
Get-Service AmazonSSMAgent

(Windows Powershell) SSM Agent Status ์กฐํšŒ

1-2. ssm-user ์‚ฌ์šฉ์ž ๊ณ„์ •์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

  • SSM Agent๋Š” ์ตœ์ดˆ ์‹œ์ž‘ ๋˜๋Š” ์„ค์น˜ ํ›„ ์žฌ์‹œ์ž‘ ์‹œ ssm-user ๋กœ์ปฌ ์‚ฌ์šฉ์ž ๊ณ„์ •์„ ์ƒ์„ฑํ•œ๋‹ค.
    • Linux ๋ฐ macOS : ssm-user๋Š” /etc/sudoers์— ํฌํ•จ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
    • Windows : Administrators ๊ทธ๋ฃน์— ํฌํ•จ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

 

2. EC2 IAM Role ํ™•์ธ

  • AWS Systems Manager๊ฐ€ EC2 ์ธ์Šคํ„ด์Šค์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก IAM์„ ์ด์šฉํ•˜์—ฌ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ด์•ผ ํ•œ๋‹ค.
  • EC2 ์ธ์Šคํ„ด์Šค์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋Š” IAM ์—ญํ• ์—๋Š” AWS Managed Policy์ธ AmazonSSMManagedInstanceCore๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

 

3. ์ธ์Šคํ„ด์Šค ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์„œ๋น„์Šค ์—ฐ๊ฒฐ ํ™•์ธ

3-1. SSM Agent๋Š” ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ์ธ์Šคํ„ด์Šค ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์„œ๋น„์Šค์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

  • telnet 169.254.169.254 80์œผ๋กœ TCP connection ํ™•์ธ.
  • Windows์˜ ๊ฒฝ์šฐ์—๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ http://169.254.169.254/latest/meta-data/ ์ ‘์†ํ•ด์„œ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๋‹ค.
  • ๋งŒ์•ฝ ์—ฐ๊ฒฐ์— ์‹คํŒจํ•œ๋‹ค๋ฉด, OS ๋‚ด ๋ผ์šฐํŒ… ์„ค์ • ํ™•์ธ ํ•„์š” ⇒ route print๋กœ gateway์˜ ์ฃผ์†Œ๊ฐ€ ์„œ๋ธŒ๋„ท CIDR ๋ฒ”์œ„์˜ ์ฒซ๋ฒˆ์งธ IP์ธ์ง€ ํ™•์ธํ•œ๋‹ค.

3-2. SSM ์—”๋“œํฌ์ธํŠธ์— 443 ํฌํŠธ๋กœ ์ž˜ ์—ฐ๊ฒฐ์ด ๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

tnc -p 443 ec2messages.ap-northeast-2.amazonaws.com
tnc -p 443 ssm.ap-northeast-2.amazonaws.com
tnc -p 443 ssmmessages.ap-northeast-2.amazonaws.com

⇒ ๋ณด์•ˆ๊ทธ๋ฃน ์„ค์ • ๋ฐ NAT Gateway๋กœ์˜ ๋ผ์šฐํŒ… ์„ค์ •์— ์ด์Šˆ๋Š” ์—†์—ˆ์œผ๋ฉฐ ๋ชจ๋‘ PingSucceeded์—์„œ False์˜ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•จ.

(Windows Firewall Profiles๋Š” ์ด๋ฏธ ๋ชจ๋‘ ํ•ด์ œ๋˜์–ด ์žˆ๋˜ ์ƒํƒœ. ํ•ด์ œํ•˜๋Š” ๋ช…๋ น์–ด๋Š” ๋‹ค์Œ์„ ์ฐธ๊ณ )

netsh advfirewall set allprofiles state off

3-3. DNS ์„œ๋ฒ„๋ฅผ ํ™•์ธํ•œ๋‹ค.

  • DNS ์„œ๋ฒ„๊ฐ€ VPC CIDR ๋Œ€์—ญ์˜ ๋‘ ๋ฒˆ์งธ IP์ธ์ง€ ํ™•์ธํ•œ๋‹ค.
  • ์ œ์–ดํŒ > ๋„คํŠธ์›Œํฌ ๋ฐ ์ธํ„ฐ๋„ท > ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ > (์šฐํด๋ฆญ) ์†์„ฑ > ์ธํ„ฐ๋„ท ํ”„๋กœํ† ์ฝœ ๋ฒ„์ „ 4(TCP/IPv4)
  • [ ๋‹ค์Œ DNS ์„œ๋ฒ„ ์ฃผ์†Œ ์‚ฌ์šฉ ] ์—์„œ [ ๊ธฐ๋ณธ ์„ค์ • DNS ์„œ๋ฒ„ ] IP ํ™•์ธํ•˜์—ฌ VPC CIDR ๋Œ€์—ญ์˜ 2๋ฒˆ์งธ IP์ธ์ง€ ํ™•์ธ
    ex) 10.0.0.0/24์—์„œ 10.0.0.1์€ VPC ๋ผ์šฐํ„ฐ๋ฅผ ์œ„ํ•ด AWS์—์„œ ์˜ˆ์•ฝ๋œ IP

⇒ DNS ์„œ๋ฒ„๊ฐ€ ๋‹ค๋ฅธ IP๋กœ ์„ค์ •๋˜์–ด ์žˆ์–ด VPC ๋„คํŠธ์›Œํฌ ์ฃผ์†Œ์˜ 2๋ฒˆ์งธ IP๋กœ ๋ณ€๊ฒฝ ํ›„, SSM์—์„œ ์ •์ƒ์ ์œผ๋กœ ์ธ์‹๋จ

 

 

4. SSM Logs ํ™•์ธ

  • 3๋ฒˆ๊นŒ์ง€ ํ™•์ธ ๋ฐ ์ด์ƒ ์—†์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ , SSM์—์„œ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ œ๋Œ€๋กœ ์ธ์‹๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด SSM Agent์˜ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•ด๋ณด์ž.
    • Linux ๋ฐ macOS : /var/log/amazon/ssm/
    • Windows : %PROGRAMDATA%\\Amazon\\SSM\\InstanceData\\

 

โœ…  ์š”์•ฝ : Checklist 

1. ์ธ์Šคํ„ด์Šค์— AWS Systems Agent(amazon-ssm-agent) ์„ค์น˜ & ์‹คํ–‰ ์ค‘์ธ์ง€? (+์ตœ์‹  ๋ฒ„์ „์ธ์ง€)

2. ์„œ๋ฒ„ ๋‚ด๋ถ€์— ssm-user ์‚ฌ์šฉ์ž ๊ณ„์ •์ด ์žˆ๋Š”์ง€?

3. EC2์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋Š” IAM Role์— AmazonSSMManagedInstanceCore ์ •์ฑ… ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€?

4. ๋ณด์•ˆ ๊ทธ๋ฃน, NAT Gateway๋กœ์˜ ๋ผ์šฐํŒ…, (Windows์ธ ๊ฒฝ์šฐ Windows ๋ฐฉํ™”๋ฒฝ) ์„ค์ •์— ๋ฌธ์ œ์—†๋Š”์ง€?

5. DNS ์„œ๋ฒ„ ์ฃผ์†Œ ์ œ๋Œ€๋กœ ์„ค์ •๋˜์–ด ์žˆ๋Š”์ง€?


๐Ÿ’ก ์›์ธ ๋ถ„์„

EC2 Launch Initialize ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๊ณ  Windows 2019 ์ธ์Šคํ„ด์Šค์—์„œ AMI๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ๊ฒฝ์šฐ, ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋กœ์˜ ๋ผ์šฐํŒ… ์ •๋ณด๋ฅผ ํฌํ•จํ•œ ์‹œ์Šคํ…œ ๊ด€๋ จ ์ •๋ณด๊ฐ€ OS ๊ตฌ์„ฑ์˜ ์ผ๋ถ€๋กœ ์ธ์‹๋˜์–ด AMI์— ํฌํ•จ๋˜๊ฒŒ ๋œ๋‹ค. ํ•ด๋‹น AMI์—์„œ ์ƒ์„ฑ๋˜๋Š” ์‹ ๊ทœ ์ธ์Šคํ„ด์Šค๋Š” ์„œ๋ธŒ๋„ท๊ณผ ๊ด€๊ณ„์—†์ด AMI๊ฐ€ ๋งŒ๋“ค์–ด์กŒ๋˜ ์ธ์Šคํ„ด์Šค์˜ ๊ฒฝ๋กœ์™€ ๋™์ผํ•œ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ๋ฐ ํ™œ์„ฑํ™”์™€ ๊ฐ™์€ ์ž‘์—…์ด ๋‹ค๋ฅธ ์„œ๋ธŒ๋„ท์ด๋‚˜ VPC์—์„œ ์‹œ์ž‘๋˜๋ฉด ์‹คํŒจํ•˜๊ฒŒ ๋œ๋‹ค.

๋ฌธ์ œ ์„œ๋ฒ„๋Š” ๊ฐ™์€ VPC์—์„œ ๋งŒ๋“  Windows AMI์—์„œ ์‹œ์ž‘ํ•œ ์ธ์Šคํ„ด์Šค์ธ๋ฐ, ์ด๋ฏธ์ง€๊ฐ€ ๋งŒ๋“ค์–ด์ง„ ์„œ๋ฒ„๊ฐ€ AD์— ์กฐ์ธ๋˜์–ด ์žˆ๋˜ ์„œ๋ฒ„๋ผ DNS ์„œ๋ฒ„ ์ฃผ์†Œ๊ฐ€ AD ์„œ๋ฒ„์˜ IP๋กœ ์„ค์ •๋˜์–ด ์žˆ์—ˆ๋‹ค. ์ด๋กœ ์ธํ•ด AWS System Manager์—์„œ ์ธ์Šคํ„ด์Šค ์ธ์‹ ๋ถˆ๊ฐ€๋Šฅ.

 

 

๐Ÿ”— ์ฐธ๊ณ  ๋งํฌ

  1. Systems Manager ์ฝ˜์†”์˜ ๊ด€๋ฆฌํ˜• ์ธ์Šคํ„ด์Šค์— EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ๋‚˜ํƒ€๋‚˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?
  2. 2๋‹จ๊ณ„: Session Manager ๊ถŒํ•œ์„ ์‚ฌ์šฉํ•˜์—ฌ IAM ์—ญํ•  ํ™•์ธ ๋˜๋Š” ์ƒ์„ฑ
  3. 7๋‹จ๊ณ„: (์˜ต์…˜) ssm-user ๊ณ„์ • ๊ด€๋ฆฌ ๊ถŒํ•œ ์„ค์ • ๋˜๋Š” ํ•ด์ œ
  4. Subnets for your VPC
  5. ์œˆ๋„์šฐ10 DNS ์„œ๋ฒ„ ๋ณ€๊ฒฝ๊ณผ ์˜๋ฏธ ์ถ”์ฒœ DNS ์ •๋ฆฌ ์˜ค๋ฅ˜ ์บ์‹œ ์ดˆ๊ธฐํ™” ๋ฐฉ๋ฒ•๊นŒ์ง€