Skip to content

Latest commit

ย 

History

History
332 lines (194 loc) ยท 15.5 KB

aws-monitoring.md

File metadata and controls

332 lines (194 loc) ยท 15.5 KB

Monitoring

AWS ๋ฆฌ์†Œ์Šค์˜ ๋กœ๊ทธ ๊ด€๋ฆฌ, ์ด๋ฒคํŠธ ๋ชจ๋‹ˆํ„ฐ๋ง ์„œ๋น„์Šค

CloudTrail

  • AWS ๋ฆฌ์†Œ์Šค์˜ ๋ชจ๋“  ์ฝ๊ธฐ, ์“ฐ๊ธฐ ์ž‘์—…์˜ ์ƒ์„ธ ๋กœ๊ทธ(์ž‘์—… ๋‚ด์—ญ, ๊ด€๋ จ ๋ฆฌ์†Œ์Šค์™€ ๋ฆฌ์ „, ์ž‘์—… ์ˆ˜ํ–‰์ž์˜ ์ž‘์—… ์‹œ๊ฐ„ ๋“ฑ)๋ฅผ ๋ณด๊ด€

  • API ์ž‘์—…๊ณผ ๋น„ API ์ž‘์—…์„ ๋ชจ๋“œ ๊ธฐ๋ก

    • API ์ž‘์—…
      • ์˜ˆ : ์ธ์Šคํ„ด์Šค ์‹œ์ž‘, S3 ๋ฒ„ํ‚ท ์ƒ์„ฑ, VPC ์ƒ์„ฑ
    • ๋น„ API ์ž‘์—…
      • ์˜ˆ : AWS Management Console์— ๋กœ๊ทธ์ธ ๋“ฑ
  • ์ด๋ฒคํŠธ(event)

    • AWS ๊ณ„์ •์˜ ํ™œ๋™ ๊ธฐ๋ก
    • ๊ด€๋ฆฌ ์ด๋ฒคํŠธ = ์ œ์–ด ํ”Œ๋ ˆ์ธ ์ž‘์—…(Control Plane Operations)
      • ๋ณด์•ˆ ์ฃผ์ฒด๊ฐ€ AWS ๋ฆฌ์†Œ์Šค์—์„œ ์‹คํ–‰ํ•˜๋Š” ์ž‘์—…์„ ํฌํ•จ
        • ๋ณด์•ˆ ๊ตฌ์„ฑ
          • โ†’ IAM AttachRolePolicy API
        • ๋””๋ฐ”์ด์Šค ๋“ฑ๋ก
          • โ†’ EC2 AttachRolePolicy API
        • ๋ฐ์ดํ„ฐ ๋ผ์šฐํŒ… ๊ทœ์น™ ๊ตฌ์„ฑ
          • โ†’ EC2 CreateSubnet API
        • ๋กœ๊น… ์„ค์ •
          • โ†’ CloudTrail CreateTrail API
      • ๊ณ„์ •์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๋น„ API ์ด๋ฒคํŠธ
        • ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•˜๋Š” ๊ฒฝ์šฐ ConsoleLogin ์ด๋ฒคํŠธ๊ฐ€ ๋กœ๊น…
      • ์“ฐ๊ธฐ ์ „์šฉ๊ณผ ์ฝ๊ธฐ ์ „์šฉ์œผ๋กœ ๋ถ„๋ฅ˜
        • ์“ฐ๊ธฐ ์ „์šฉ ์ด๋ฒคํŠธ : ๋ฆฌ์†Œ์Šค๋ฅผ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋Š” API ์ž‘์—…
        • ์ฝ๊ธฐ ์ „์šฉ ์ด๋ฒคํŠธ : ๋ฆฌ์†Œ์Šค๋ฅผ ์ฝ๊ธฐ๋งŒํ•˜๊ณ  ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š” API ์ž‘์—…
    • ๋ฐ์ดํ„ฐ ์ด๋ฒคํŠธ = ๋ฐ์ดํ„ฐ ํ”Œ๋ ˆ์ธ ์ž‘์—…(Data Plane Operations)
      • ๋ฆฌ์†Œ์Šค ๋˜๋Š” ๋ฆฌ์†Œ์Šค ๋‚ด์—์„œ ์ˆ˜ํ–‰๋˜๋Š” ๋ฆฌ์†Œ์Šค ์ž‘์—…์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณต
      • ๋Œ€๋Ÿ‰์˜ ์ž‘์—…์ด ์ˆ˜ํ–‰๋˜๋Š” S3 ๊ฐ์ฒด ์ˆ˜์ค€ ํ™œ๋™, Lambda ํ•จ์ˆ˜ ์‹คํ–‰
        • S3 ๊ฐ์ฒด ์ˆ˜์ค€ ํ™œ๋™ โ†’ GetObject, DeleteObject, PutObject API
        • Lambda ํ•จ์ˆ˜ ์‹คํ–‰ โ†’ Invoke API
      • ์ถ”์ ์„ ์ƒ์„ฑํ•  ๋•Œ ๋ฐ์ดํ„ฐ ์ด๋ฒคํŠธ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ธฐ๋ก๋˜์ง€ ์•Š์Œ
      • ๋ฐ์ดํ„ฐ ์ด๋ฒคํŠธ๋ฅผ ๊ธฐ๋กํ•˜๋ ค๋ฉด ํ™œ๋™์„ ์ˆ˜์ง‘ํ•  ๋ฆฌ์†Œ์Šค ๋˜๋Š” ๋ฆฌ์†Œ์Šค ์œ ํ˜•์„ ์ถ”์ ์— ๋ช…์‹œ์ ์œผ๋กœ ์ถ”๊ฐ€ํ•ด์•ผ ํ•จ
    • ์ธ์‚ฌ์ดํŠธ ์ด๋ฒคํŠธ
      • AWS ๊ณ„์ •์˜ ๋น„์ •์ƒ์ ์ธ ํ™œ๋™์„ ์บก์ณ
      • ๊ณ„์ • API ์‚ฌ์šฉ๋Ÿ‰ ๋ณ€ํ™”๊ฐ€ ๊ณ„์ •์˜ ์ผ๋ฐ˜์ ์ธ ์‚ฌ์šฉ ํŒจํ„ด๊ณผ ํฌ๊ฒŒ ๋‹ค๋ฅผ ๋•Œ ๋กœ๊น…
        • S3 deleteBucket API ํ˜ธ์ถœ์ด ํ‰๊ท ์ ์œผ๋กœ ๋ถ„๋‹น 20ํšŒ ํ˜ธ์ถœ
          • โ†’ ๋ถ„๋‹น 100ํšŒ ํ˜ธ์ถœ์ด ๊ฐ์ง€
          • โ‡’ ๋น„์ •์ƒ์ ์ธ ํ™œ๋™
          • โ‡’ ๋น„์ •์ƒ์ ์ธ ํ™œ๋™์ด ์‹œ์ž‘๋  ๋•Œ์™€ ์ •์ƒ์œผ๋กœ ๋Œ์•„๊ฐ”์„ ๋•Œ๋ฅผ ๊ธฐ๋ก
  • ์ด๋ฒคํŠธ ๊ธฐ๋ก (Event History)

    • CloudTrail ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ง€๋‚œ 90์ผ ๊ฐ„์˜ ๊ธฐ๋ก
    • ์กฐํšŒ, ๊ฒ€์ƒ‰, ๋‹ค์šด๋กœ๋“œ ๋“ฑ์ด ๊ฐ€๋Šฅ
    • ๊ฐ ๋ฆฌ์ „๋ณ„๋กœ __์ด๋ฒคํŠธ ๊ธฐ๋ก__์„ ์ž‘์„ฑํ•˜๊ณ  ํ•ด๋‹น ๋ฆฌ์ „์—์„œ์˜ ํ™œ๋™๋งŒ ๊ธฐ๋ก
    • IAM, Route 53 ๋“ฑ์˜ ๊ธ€๋กœ๋ฒŒ ์„œ๋น„์Šค ์ด๋ฒคํŠธ๋Š” ๋ชจ๋“  ๋ฆฌ์ „์˜ ์ด๋ฒคํŠธ ๊ธฐ๋ก์— ํฌํ•จ
  • ์ถ”์  (trail)

    • 90์ผ์ด ๊ฒฝ๊ณผํ•œ ์ด๋ฒคํŠธ ๊ธฐ๋ก์„ ์ €์žฅํ•˜๊ฑฐ๋‚˜ CloudTrail์ด ๊ธฐ๋กํ•˜๋Š” ์ด๋ฒคํŠธ ์œ ํ˜•์„ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ๋•Œ ์ƒ์„ฑ
    • ํŠน์ • ์ด๋ฒคํŠธ๋ฅผ ๊ธฐ๋กํ•˜๊ณ  ์ง€์ •ํ•œ S3 ๋ฒ„ํ‚ท์— CloudTrail ๋กœ๊ทธ ํŒŒ์ผ์„ ์ „๋‹ฌ, ๋กœ๊ทธ ํŒŒ์ผ์—๋Š” JSON ํ˜•์‹์˜ ํ•ญ๋ชฉ์ด ํ•˜๋‚˜ ์ด์ƒ ๋“ค์–ด ์žˆ์Œ
      • eventTime
      • userIdentity
      • eventSource
      • eventName
      • awsResion
      • sourceIPAddress

CloudWatch

  • AWS ๋ฆฌ์†Œ์Šค์™€ AWS์—์„œ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์‹คํ–‰๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ชจ๋‹ˆํ„ฐ๋ง
  • ๋ฆฌ์†Œ์Šค์™€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์ง€ํ‘œ(= ์ธก์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ณ€์ˆ˜)๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ  ์ถ”์ 
  • CloudWatch ์›น ์‚ฌ์ดํŠธ์—๋Š” ์‚ฌ์šฉ ์ค‘์ธ ๋ชจ๋“  AWS ์„œ๋น„์Šค์— ํ•œ ์ง€ํ‘œ๊ฐ€ ์ž๋™์œผ๋กœ ํ‘œ์‹œ๋˜๊ณ , ์‚ฌ์šฉ์ž ์ง€์ • ๋Œ€์‹œ๋ณด๋“œ ์ถ”๊ฐ€๊ฐ€ ๊ฐ€๋Šฅ
  • ์ง€ํ‘œ๋ฅผ ๊ฐ์‹œํ•ด ์•Œ๋ฆผ์„ ๋ณด๋‚ด๊ฑฐ๋‚˜ ์ž„๊ณ„๊ฐ’์„ ์œ„๋ฐ˜ํ•œ ๊ฒฝ์šฐ ๋ชจ๋‹ˆํ„ฐ๋ง ์ค‘์ธ ๋ฆฌ์†Œ์Šค๋ฅผ ์ž๋™์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒฝ๋ณด๋ฅผ ์ƒ์„ฑ
  • ์‹œ์Šคํ…œ ์ „์ฒด์˜ ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ๋Ÿ‰, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ฑ๋Šฅ ๋ฐ ์šด์˜ ์ƒํƒœ๋ฅผ ํŒŒ์•…



LAB1 : Monitoring and Notifications with CloudWatch Events and SNS

img

#1 EC2 ์ธ์Šคํ„ด์Šค ํ™•์ธ

img

#2 SNS ์ฃผ์ œ(topic)์™€ ์ด๋ฉ”์ผ ๊ตฌ๋…(subscribe)์„ ์ƒ์„ฑ

img

image-20210305101223966

img

#3 SNS ์ฃผ์ œ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๋Š” CloudWatch ์ด๋ฒคํŠธ ๊ทœ์น™์„ ์ƒ์„ฑ

img

#4 EC2 ์ธ์Šคํ„ด์Šค์˜ ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ–ˆ์„ ๋•Œ ์ด๋ฉ”์ผ ํ†ต์ง€๊ฐ€ ์ˆ˜์‹ ๋˜๋Š”์ง€ ํ™•์ธ

  • ์ธ์Šคํ„ด์Šค ์ค‘์ง€

img

img

  • ์ธ์Šคํ„ด์Šค ์‹คํ–‰

img

img




LAB1-2 : EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ์ค‘์ง€(stopped)๋˜์—ˆ์„ ๋•Œ ์ด๋ฉ”์ผ๊ณผ ํ•จ๊ป˜ SMS ํ†ต์ง€๋ฅผ ๋ฐœ์ƒํ•˜๋„๋ก ์„ค์ •

  • SMS ๊ตฌ๋… ์ƒ์„ฑ

img

  • ์ด๋ฒคํŠธ ์ˆ˜์ •

    • ์ด๋ฒคํŠธ ์œ ํ˜• -> ํŠน์ •์ƒํƒœ(shutdown)

    • ์ผ์น˜ํ•˜๋Š” ์ด๋ฒคํŠธ์˜ ์ผ๋ถ€ -> JSON์—์„œ detail๋งŒ ๋ฐ›์•„ ์˜ค๊ธฐ ์œ„ํ•ด

      "detail":{"instance-id":"i-0697bdc417cb5d414","state":"stopping"}}

img

  • ์ด๋ฉ”์ผ ํ™•์ธ

image-20210305104419363

  • ๋ฌธ์ž ํ™•์ธ

image-20210305104204790

TODO. EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ์ค‘์ง€(stopped)๋˜์—ˆ์„ ๋•Œ ํฌ๋งทํŒ…๋œ ์•Œ๋ฆผ ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•˜์‹œ์˜ค.




LAB2 : AWS EC2 Custom Logging with CloudWatch

์ธ์Šคํ„ด์Šค์—์„œ ์ƒ์„ฑ๋˜๋Š” ๋กœ๊ทธ ์ •๋ณด๋ฅผ CloudWatcch๋กœ ์ „์†กํ•ด์„œ ๋กœ๊ทธ๋ฅผ ํ†ตํ•ฉ

  • EC2 ์ธ์Šคํ„ด์Šค์— CloudWatch Logs ์—์ด์ „ํŠธ๋ฅผ ์„ค์น˜ํ•˜๊ณ , ๋กœ๊ทธ ์„œ๋น„์Šค๋ฅผ ์ผœ๊ณ , ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜๋„๋ก CloudWatcch๋ฅผ ๊ตฌ์„ฑ

#1 EC2 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

img

img


img

#2 ์ž‘์—…์„ ์œ„ํ•ด EC2 ์ธ์Šคํ„ด์Šค์— SSH ์ ‘์†

img

img

#3 EC2 ์ธ์Šคํ„ด์Šค์— awslogs ์„œ๋น„์Šค๋ฅผ ์ถ”๊ฐ€

  • [ec2-user@ip-10-0-0-134 ~]$ sudo yum update -y

  • [ec2-user@ip-10-0-0-134 ~]$ sudo yum install -y awslogs

  • [ec2-user@ip-10-0-0-134 ~]$ cd /etc/awslogs

  • [ec2-user@ip-10-0-0-134 awslogs]$ ls -l

    total 20
    -rw------- 1 root root   55 Mar  5 02:14 awscli.conf	โ‡ ์ž๊ฒฉ์ฆ๋ช…๊ณผ ์ง€์—ญ์ •๋ณด๋ฅผ ํฌํ•จ
    -rw-r--r-- 1 root root 8355 Jul 25  2018 awslogs.conf	โ‡ CloudWatch ๋กœ๊น…์— ๋Œ€ํ•œ ์„ค์ • ์ •๋ณด๋ฅผ ํฌํ•จ
    drwxr-xr-x 2 root root    6 Jul 25  2018 config
    -rw-r--r-- 1 root root  147 Jul 25  2018 proxy.conf
    
  • [ec2-user@ip-10-0-0-134 awslogs]$ sudo systemctl start awslogsd

    • awslogs ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘
  • [ec2-user@ip-10-0-0-134 awslogs]$ tail -f /var/log/awslogs.log

    • awslogs ์—์ด์ „ํŠธ๊ฐ€ ์ƒ์„ฑํ•˜๋Š” ๋กœ๊ทธ๋ฅผ ํ™•์ธ
    2021-03-05 02:18:18,404 - cwlogs.push - INFO - 3448 - MainThread - Missing or invalid value for use_gzip_http_content_encoding config. Defaulting to use gzip encoding.
    2021-03-05 02:18:18,404 - cwlogs.push - INFO - 3448 - MainThread - Missing or invalid value for queue_size config. Defaulting to use 10
    2021-03-05 02:18:18,404 - cwlogs.push - INFO - 3448 - MainThread - Using default logging configuration.
    2021-03-05 02:18:18,425 - cwlogs.push.stream - INFO - 3448 - Thread-1 - Starting publisher for [1538ea66cfd1d4424de78dedc63516f8, /var/log/messages]
    2021-03-05 02:18:18,431 - cwlogs.push.stream - INFO - 3448 - Thread-1 - Starting reader for [1538ea66cfd1d4424de78dedc63516f8, /var/log/messages]
    2021-03-05 02:18:18,432 - cwlogs.push.reader - INFO - 3448 - Thread-4 - Start reading file from 0.
    2021-03-05 02:18:24,519 - cwlogs.push.publisher - WARNING - 3448 - Thread-3 - Caught exception: An error occurred (ResourceNotFoundException) when calling the PutLogEvents operation: The specified log group does not exist.
    2021-03-05 02:18:24,520 - cwlogs.push.batch - INFO - 3448 - Thread-3 - Creating log group /var/log/messages.
    2021-03-05 02:18:24,582 - cwlogs.push.batch - INFO - 3448 - Thread-3 - Creating log stream i-04545e7d208a38d21.
    2021-03-05 02:18:24,675 - cwlogs.push.publisher - INFO - 3448 - Thread-3 - Log group: /var/log/messages, log stream: i-04545e7d208a38d21, queue size: 0, Publish batch: {'skipped_events_count': 0, 'first_event': {'timestamp': 1614910316000, 'start_position': 0L, 'end_position': 162L}, 'fallback_events_count': 0, 'last_event': {'timestamp': 1614910698000, 'start_position': 68477L, 'end_position': 68564L}, 'source_id': '1538ea66cfd1d4424de78dedc63516f8', 'num_of_events': 789, 'batch_size_in_bytes': 88289}
    
  • [ec2-user@ip-10-0-0-134 awslogs]$ sudo systemctl enable awslogsd.service

    • ๋ถ€ํŒ… ์‹œ awslogs ์„œ๋น„์Šค๋ฅผ ์ž๋™ ์‹คํ–‰

#4 EC2์—์„œ ๋ณด๋‚ธ CloudWatch Logs ํ™•์ธ (์ˆ˜์ง‘๋œ ๋กœ๊ทธ๋ฅผ ํ™•์ธ)




LAB3 : AWS Access Control Alerts with CloudWatch and CloudTrail

image-20210305133839606

#1 ์ค‘์š” ์ •๋ณด๋ฅผ ๋‹ด์„ S3 ๋ฒ„ํ‚ท ์ƒ์„ฑ โ† ๋ชจ๋‹ˆํ„ฐ๋ง์ด ํ•„์š”

img

#2 CloudTrail ์„œ๋น„์Šค์— ์ถ”์ (trail)์„ ์ƒ์„ฑ

img

img

img

#3 CloudWatch ๋กœ๊ทธ ๊ทธ๋ฃน์„ ์ƒ์„ฑ

img

img

#4 CloudWatch์—์„œ ์ง€ํ‘œ๋ฅผ ์„ค์ •

img

  • ํŒจํ„ด ํ•„ํ„ฐ๋ง
{ ($.eventSource = s3.amazonaws.com) && (($.eventName = PutObject) || ($.eventName = GetObject)) }

img

img

#5 CloudWatch์—์„œ ๊ฒฝ๋ณด๋ฅผ ์„ค์ •

img

img

img


  • ๊ฒฝ๋ณด๋ฅผ ์•Œ๋ฆด ๋ฐ์ดํ„ฐ ํฌ์ธํŠธ๊ฐ€ 3/3์œผ๋กœ ์„ค์ •๋œ ๊ฒฝ์šฐ

img

  • ์ง€ํ‘œ ๊ฒฝ๋ณด ์ƒํƒœ
    • OK
      • ์ง€ํ‘œ ๋˜๋Š” ํ‘œํ˜„์‹์ด ์ •์˜๋œ ์ž„๊ณ„๊ฐ’ ๋‚ด์— ์žˆ์Œ
    • ALARM
      • ์ง€ํ‘œ ๋˜๋Š” ํ‘œํ˜„์‹์ด ์ •์˜๋œ ์ž„๊ณ„๊ฐ’์„ ๋ฒ—์–ด๋‚ฌ์Œ
    • INSUFFICIENT_DATA
      • ๊ฒฝ๋ณด๊ฐ€ ๋ฐฉ๊ธˆ ์‹œ์ž‘๋˜์—ˆ๊ฑฐ๋‚˜, ์ง€ํ‘œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฑฐ๋‚˜, ์ง€ํ‘œ๋ฅผ ํ†ตํ•ด ๊ฒฝ๋ณด ์ƒํƒœ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š”๋ฐ ์ถฉ๋ถ„ํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ

img

#6 S3 ๋ฒ„ํ‚ท์— ํŒŒ์ผ์„ ์—…๋กœ๋“œ ํ›„ ๊ฒฝ๋ณด ๋ฐœ์ƒ ์—ฌ๋ถ€ ํ™•์ธ

ํŒŒ์ผ ์—…๋กœ๋“œ ์‹œ, ์„ค์ •ํ•œ ๊ฒฝ๋ณด๋ฅผ ํ™•์ธํ•œ๋‹ค

img

img