4. SK Shieldus Rookies 19๊ธฐ๐Ÿคํด๋ผ์šฐ๋“œ๊ธฐ๋ฐ˜ ์ทจ์•ฝ์  ์ง„๋‹จ ๋ฐ ๋Œ€์‘ ์‹ค๋ฌด(CloudTrail , CloudWatch)

์ŸŒ์ฅฌยท2024๋…„ 5์›” 15์ผ
0
post-thumbnail

1. CloudTrail

https://docs.aws.amazon.com/ko_kr/awscloudtrail/latest/userguide/cloudtrail-user-guide.html

CloudTrail์€ AWS์—์„œ ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค๋กœ, AWS ๊ณ„์ •์˜ ๊ด€๋ฆฌ, ๊ทœ์ • ์ค€์ˆ˜, ์šด์˜ ๋ฐ ์œ„ํ—˜ ๊ฐ์‚ฌ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด ์„œ๋น„์Šค๋Š” AWS์—์„œ ๋ฐœ์ƒํ•œ ๋ชจ๋“  ์ž‘์—…์„ ๊ธฐ๋กํ•˜๊ณ  ์ถ”์ ํ•˜์—ฌ ๊ด€๋ฆฌ์ž๋“ค์ด ์ด๋ฅผ ๊ฒ€ํ† ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ์ž, ์—ญํ•  ๋ฐ ์„œ๋น„์Šค๊ฐ€ AWS Management Console, AWS Command Line Interface (CLI), AWS SDK, API ๋“ฑ์„ ํ†ตํ•ด ์ˆ˜ํ–‰ํ•œ ๋ชจ๋“  ์ž‘์—…์„ ํฌํ•จํ•˜์—ฌ ์ด๋ฒคํŠธ๋ฅผ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด AWS์—์„œ ์„œ๋น„์Šค๋˜๋Š” ๋ชจ๋“  ํ™œ๋™์„ ๋ชจ์œผ๊ณ  ๋ถ„์„ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ๋ฆฌ์†Œ์Šค ๋ณ€๊ฒฝ ์ถ”์  ๋“ฑ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

<CloudTrail์˜ ์„ธ ๊ฐ€์ง€ ์œ ํ˜•์˜ ์ด๋ฒคํŠธ>

  • ๊ด€๋ฆฌ ์ด๋ฒคํŠธ :
    ๊ณ„์ • ๋ฆฌ์†Œ์Šค์—์„œ ์ˆ˜ํ–‰๋˜๋Š” ๊ด€๋ฆฌ ์ž‘์—…์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, EC2 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ, S3 ๋ฒ„ํ‚ท ์‚ญ์ œ์™€ ๊ฐ™์€ ๊ด€๋ฆฌ์  ์ž‘์—…์„ ์ถ”์ ํ•ฉ๋‹ˆ๋‹ค.

  • ๋ฐ์ดํ„ฐ ์ด๋ฒคํŠธ :
    ๋ฆฌ์†Œ์Šค์—์„œ ์ˆ˜ํ–‰๋˜๋Š” ๋ฐ์ดํ„ฐ ์ž‘์—…์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, S3 ๋ฒ„ํ‚ท์—์„œ ํŒŒ์ผ ์—…๋กœ๋“œ, ๋‹ค์šด๋กœ๋“œ์™€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ ์ž‘์—…์„ ์ถ”์ ํ•ฉ๋‹ˆ๋‹ค.

  • Insights ์ด๋ฒคํŠธ :
    ๊ณ„์ •์—์„œ ๋ฐœ์ƒํ•œ ๋น„์ •์ƒ์ ์ธ ํ™œ๋™์— ๋Œ€ํ•œ ๊ธฐ๋ก์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ณ„์ •์˜ ๋ณด์•ˆ ์„ค์ • ๋ณ€๊ฒฝ ๋˜๋Š” ๋น„์ •์ƒ์ ์ธ ์•ก์„ธ์Šค ์‹œ๋„์™€ ๊ฐ™์€ ํ™œ๋™์„ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค.


2. CloudWatch

https://aws.amazon.com/ko/cloudwatch/

CloudWatch๋Š” AWS์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ด€๋ฆฌ ์„œ๋น„์Šค๋กœ, AWS์˜ ์ž์›๊ณผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ด ์„œ๋น„์Šค๋Š” ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๋Š” ๋ชจ๋“  ์ž์›์˜ ๋กœ๊ทธ์™€ ์ง€ํ‘œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ  ์‹œ๊ฐํ™”ํ•˜์—ฌ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • ์ง€ํ‘œ(Metrics) :
    ์–ธ์ œ ์–ด๋–ค ํ•ญ๋ชฉ์˜ ๊ฐ’์ด ๋ฌด์—‡์ด์—ˆ๋Š”์ง€๋ฅผ ๊ธฐ๋กํ•œ ๊ฐ’์œผ๋กœ, ์˜ˆ๋ฅผ ๋“ค์–ด, EC2 ์ธ์Šคํ„ด์Šค์˜ CPU ์‚ฌ์šฉ๋Ÿ‰, ๋„คํŠธ์›Œํฌ ์ „์†ก๋Ÿ‰, Auto Scaling ๊ทธ๋ฃน์ด ๊ด€๋ฆฌํ•˜๋Š” ์ธ์Šคํ„ด์Šค ์ˆ˜ ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • CloudWatch Logs :
    ๋กœ๊ทธ ์ด๋ฒคํŠธ, ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ, ๋กœ๊ทธ ๊ทธ๋ฃน๊ณผ ๊ฐ™์€ ๊ฐœ๋…๋“ค๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.

  • ๋กœ๊ทธ ์ด๋ฒคํŠธ(Log Events) :
    ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด๋‚˜ ์ž์›์—์„œ ๊ธฐ๋ก๋œ ๋กœ๊ทธ์˜ ํ•œ ์ค„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

  • ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ(Log Streams) :
    ๋™์ผํ•œ ์†Œ์Šค์—์„œ ๊ธฐ๋ก๋œ ๋กœ๊ทธ ์ด๋ฒคํŠธ๋“ค์„ ์‹œ๊ฐ„์ˆœ์œผ๋กœ ๋ชจ์•„๋‘” ์ŠคํŠธ๋ฆผ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

  • ๋กœ๊ทธ ๊ทธ๋ฃน(Log Groups) :
    ๋™์ผํ•œ ๋ณด์กด ๊ธฐ๊ฐ„, ๋ชจ๋‹ˆํ„ฐ๋ง ์„ค์ •, ์•ก์„ธ์Šค ์ œ์–ด ์„ค์ • ๋“ฑ์„ ๊ณต์œ ํ•˜๋Š” ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ์˜ ๊ทธ๋ฃน์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

๋˜ํ•œ, CloudWatch๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํŠน์ • ๊ธฐ์ค€์ด ์ถฉ์กฑ๋˜๋ฉด Amazon EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ค‘์ง€, ์‹œ์ž‘ ๋˜๋Š” ์ข…๋ฃŒํ•˜๋„๋ก ๊ฒฝ๋ณด ์ž‘์—…์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



3. ์ฐจ์ด์ 

CloudTrail:

๋ชฉ์  : AWS ๊ณ„์ •์˜ ๊ด€๋ฆฌ, ๊ทœ์ • ์ค€์ˆ˜, ์šด์˜ ๋ฐ ์œ„ํ—˜ ๊ฐ์‚ฌ๋ฅผ ์ง€์›ํ•˜๋Š” ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.

์ฃผ์š” ๊ธฐ๋Šฅ:

  • AWS ๊ณ„์ •์—์„œ ๋ฐœ์ƒํ•œ ๋ชจ๋“  ์ž‘์—…์„ ๊ธฐ๋กํ•˜๊ณ  ์ถ”์ ํ•ฉ๋‹ˆ๋‹ค.

  • ๊ด€๋ฆฌ ์ด๋ฒคํŠธ, ๋ฐ์ดํ„ฐ ์ด๋ฒคํŠธ, Insights ์ด๋ฒคํŠธ์™€ ๊ฐ™์ด ์„ธ ๊ฐ€์ง€ ์œ ํ˜•์˜ ์ด๋ฒคํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • ๊ด€๋ฆฌ์  ์ž‘์—…, ๋ฐ์ดํ„ฐ ์ž‘์—…, ๋น„์ •์ƒ์ ์ธ ํ™œ๋™ ๋“ฑ์˜ ์ด๋ฒคํŠธ๋ฅผ ๊ธฐ๋กํ•˜๊ณ  ๋ถ„์„ํ•˜์—ฌ ๋ณด์•ˆ ๋ฐ ์šด์˜์„ ๊ฐ•ํ™”ํ•ฉ๋‹ˆ๋‹ค.

CloudWatch:

๋ชฉ์ : AWS์˜ ์ž์›๊ณผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ , ๋กœ๊ทธ ๋ฐ ์ง€ํ‘œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ ์ œ๊ณตํ•˜๋Š” ๊ด€๋ฆฌ ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.

์ฃผ์š” ๊ธฐ๋Šฅ:

  • ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๋Š” ์ž์›์˜ ๋กœ๊ทธ ๋ฐ ์ง€ํ‘œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ  ์‹œ๊ฐํ™”ํ•˜์—ฌ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • ์ง€ํ‘œ๋Š” ์–ด๋–ค ํ•ญ๋ชฉ์˜ ๊ฐ’์ด ์–ธ์ œ ์–ด๋–ค ๊ฒƒ์ด์—ˆ๋Š”์ง€๋ฅผ ๊ธฐ๋กํ•˜๋ฉฐ, ์˜ˆ๋ฅผ ๋“ค์–ด, CPU ์‚ฌ์šฉ๋Ÿ‰, ๋„คํŠธ์›Œํฌ ์ „์†ก๋Ÿ‰๊ณผ ๊ฐ™์€ ์ง€ํ‘œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • ๋กœ๊ทธ๋Š” ๋กœ๊ทธ ์ด๋ฒคํŠธ, ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ, ๋กœ๊ทธ ๊ทธ๋ฃน์œผ๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ, ๋กœ๊ทธ ์ด๋ฒคํŠธ๋Š” ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋˜๋Š” ์ž์›์˜ ํ•œ ์ค„์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

  • CloudWatch๋Š” ํŠน์ • ๊ธฐ์ค€์ด ์ถฉ์กฑ๋˜๋ฉด Amazon EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ค‘์ง€, ์‹œ์ž‘ ๋˜๋Š” ์ข…๋ฃŒํ•˜๋„๋ก ๊ฒฝ๋ณด ์ž‘์—…์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋น„๊ต:

  • CloudTrail์€ ์ฃผ๋กœ AWS ๊ณ„์ •์˜ ํ™œ๋™์„ ์ถ”์ ํ•˜๊ณ  ๊ฐ์‚ฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋ฉฐ, ๋ณด์•ˆ ๋ฐ ๊ทœ์ • ์ค€์ˆ˜๋ฅผ ๊ฐ•ํ™”ํ•˜๋Š” ๋ฐ ์ค‘์ ์„ ๋‘ก๋‹ˆ๋‹ค.

  • CloudWatch๋Š” AWS์˜ ์ž์›๊ณผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ , ์šด์˜ ๋ฐ ์„ฑ๋Šฅ์„ ์ถ”์ ํ•˜๋ฉฐ, ๋กœ๊ทธ ๋ฐ ์ง€ํ‘œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜์—ฌ ์‹œ์Šคํ…œ์˜ ์ƒํƒœ๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.




๐Ÿ“Œ 1. CloudTrail ์ถ”์  ์ƒ์„ฑ

์„ค์ •ํ•œ ๋‚ด์šฉ์„ ํ™•์ธํ•˜๊ณ  [์ถ”์  ์ƒ์„ฑ] ๋ฒ„ํŠผ์„ ํด๋ฆญ

์ถ”์ ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธ

๋กœ๊ทธ ๊ทธ๋ฃน์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธ

S3 ๋ฒ„ํ‚ท์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธ



2. ๊ธฐ๋ณธ VPC ์ƒ์„ฑ



3. VPC-Flow-Logs ์„ค์ •

1) IAM ์ •์ฑ… ์ƒ์„ฑ

2) IAM ์—ญํ•  ์ƒ์„ฑ

๋‚ด์šฉ ํ™•์ธ ํ›„ [์—ญํ•  ์ƒ์„ฑ] ๋ฒ„ํŠผ์„ ํด๋ฆญ

Service ํ•ญ๋ชฉ์„ vpc-flow-logs.amazonaws.com ๋กœ ๋ณ€๊ฒฝํ•œ ํ›„ [์ •์ฑ… ์—…๋ฐ์ดํŠธ] ๋ฒ„ํŠผ์„ ํด๋ฆญ

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

4) VPC ํ”Œ๋กœ์šฐ ๋กœ๊ทธ๋ฅผ ์ƒ์„ฑ

5) ์ฒซ๋ฒˆ์งธ ๊ฐ€์šฉ์˜์—ญ์— ๋งŒ๋“ค์–ด์ง„ ์„œ๋ธŒ๋„ท์— ํ”Œ๋กœ์šฐ ๋กœ๊ทธ๋ฅผ ์„ค์ •



4. CloudWatch์— CloudTrail ๊ด€๋ จ ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ์ด ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ

CloudWatch์—์„œ ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ์€ ๋กœ๊ทธ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ๊ฐœ๋ณ„์ ์ธ ๋‹จ์œ„์ž…๋‹ˆ๋‹ค. CloudTrail๊ณผ ๊ฐ™์€ AWS ์„œ๋น„์Šค์˜ ๋กœ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์‹ ํ•˜๋ฉด ์ด๋Ÿฌํ•œ ๋ฐ์ดํ„ฐ๋Š” ๋กœ๊ทธ ์ŠคํŠธ๋ฆผ์œผ๋กœ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.



5. EC2 ์ธ์Šคํ„ด์Šค์— CloudWatch Agent๋ฅผ ์„ค์น˜

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

๋‚˜๋จธ์ง€ ์„ค์ •์„ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•œ ์ƒํƒœ์—์„œ [์ธ์Šคํ„ด์Šค ์‹œ์ž‘] ๋ฒ„ํŠผ์„ ํด๋ฆญ

2) ์—ญํ•  ์ƒ์„ฑ

๋‚˜๋จธ์ง€ ์„ค์ •์„ ํ™•์ธํ•˜๊ณ  [์—ญํ•  ์ƒ์„ฑ] ๋ฒ„ํŠผ์„ ํด๋ฆญ

3) EC2 ์ธ์Šคํ„ด์Šค์— ์—ญํ• ์„ ๋ถ€์—ฌ(์ˆ˜์ •)

4) EC2 ์ธ์Šคํ„ด์Šค์— CloudWatch Agent ์„ค์น˜

https://docs.aws.amazon.com/ko_kr/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html

(1) ํŒจํ‚ค์ง€ ๋‹ค์šด๋กœ๋“œ ๋งํฌ ํ™•์ธ

์ธ์Šคํ„ด์Šค ์—ฐ๊ฒฐํ•œ ํ›„

(2) ํŒจํ‚ค์ง€ ๋‹ค์šด๋กœ๋“œ

ubuntu@ip-172-31-9-148:~$ wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

(3) ํŒจํ‚ค์ง€ ์„ค์น˜

ubuntu@ip-172-31-9-148:~$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

(4) ์—์ด์ „ํŠธ ์„ค์ •

ubuntu@ip-172-31-9-148:~$ cd /opt/aws/amazon-cloudwatch-agent/bin/
ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo ./amazon-cloudwatch-agent-config-wizard

================================================================
= Welcome to the Amazon CloudWatch Agent Configuration Manager =
=                                                              =
= CloudWatch Agent allows you to collect metrics and logs from =
= your host and send them to CloudWatch. Additional CloudWatch =
= charges may apply.                                           =
================================================================
On which OS are you planning to use the agent?
1. linux
2. windows
3. darwin
default choice: [1]:
1
Trying to fetch the default region based on ec2 metadata...
I! imds retry client will retry 1 timesAre you using EC2 or On-Premises hosts?
1. EC2
2. On-Premises
default choice: [1]:
1
Which user are you planning to run the agent?
1. cwagent
2. root
3. others
default choice: [1]:
2
Do you want to turn on StatsD daemon?
1. yes
2. no
default choice: [1]:
2
Do you want to monitor metrics from CollectD? WARNING: CollectD must be installed or the Agent will fail to start
1. yes
2. no
default choice: [1]:
2
Do you want to monitor any host metrics? e.g. CPU, memory, etc.
1. yes
2. no
default choice: [1]:
1
Do you want to monitor cpu metrics per core?
1. yes
2. no
default choice: [1]:
2
Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available?
1. yes
2. no
default choice: [1]:
1
Do you want to aggregate ec2 dimensions (InstanceId)?
1. yes
2. no
default choice: [1]:
2
Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution for all metrics, but you can customize for specific metrics in the output json file.
1. 1s
2. 10s
3. 30s
4. 60s
default choice: [4]:
4
Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:
2
Current config as follows:
{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "root"
        },
        "metrics": {
                "append_dimensions": {
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
                        "ImageId": "${aws:ImageId}",
                        "InstanceId": "${aws:InstanceId}",
                        "InstanceType": "${aws:InstanceType}"
                },
                "metrics_collected": {
                        "cpu": {
                                "measurement": [
                                        "cpu_usage_idle",
                                        "cpu_usage_iowait",
                                        "cpu_usage_user",
                                        "cpu_usage_system"
                                ],
                                "metrics_collection_interval": 60,
                                "totalcpu": false
                        },
                        "disk": {
                                "measurement": [
                                        "used_percent",
                                        "inodes_free"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "diskio": {
                                "measurement": [
                                        "io_time"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "mem": {
                                "measurement": [
                                        "mem_used_percent"
                                ],
                                "metrics_collection_interval": 60
                        },
                        "swap": {
                                "measurement": [
                                        "swap_used_percent"
                                ],
                                "metrics_collection_interval": 60
                        }
                }
        }
}
Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additional items.
1. yes
2. no
default choice: [1]:
1
Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration?
1. yes
2. no
default choice: [2]:
2
Do you want to monitor any log files?
1. yes
2. no
default choice: [1]:
2
Do you want the CloudWatch agent to also retrieve X-ray traces?
1. yes
2. no
default choice: [1]:
2
Existing config JSON identified and copied to:  /opt/aws/amazon-cloudwatch-agent/etc/backup-configs
Saved config file to /opt/aws/amazon-cloudwatch-agent/bin/config.json successfully.
Current config as follows:
{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "root"
        },
        "metrics": {
                "append_dimensions": {
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
                        "ImageId": "${aws:ImageId}",
                        "InstanceId": "${aws:InstanceId}",
                        "InstanceType": "${aws:InstanceType}"
                },
                "metrics_collected": {
                        "cpu": {
                                "measurement": [
                                        "cpu_usage_idle",
                                        "cpu_usage_iowait",
                                        "cpu_usage_user",
                                        "cpu_usage_system"
                                ],
                                "metrics_collection_interval": 60,
                                "totalcpu": false
                        },
                        "disk": {
                                "measurement": [
                                        "used_percent",
                                        "inodes_free"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "diskio": {
                                "measurement": [
                                        "io_time"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "mem": {
                                "measurement": [
                                        "mem_used_percent"
                                ],
                                "metrics_collection_interval": 60
                        },
                        "swap": {
                                "measurement": [
                                        "swap_used_percent"
                                ],
                                "metrics_collection_interval": 60
                        }
                }
        }
}
Please check the above content of the config.
The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json.
Edit it manually if needed.
Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:
2
Program exits now.


(5) ์—์ด์ „ํŠธ ์‹คํ–‰

ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo mkdir -p /usr/share/collectd/

ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo touch /usr/share/collectd/types.db

ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo ./amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s

(6) CloudWatch์—์„œ ์‚ฌ์šฉ์ž ์ง€์ • ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค์— CWAgent ์ง€ํ‘œ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋Š”์ง€ ํ™•์ธ

5) EC2 ์ธ์Šคํ„ด์Šค์˜ ์›น ์„œ๋ฒ„ ์ ‘์† ๋กœ๊ทธ๋ฅผ CloudWatch๋กœ ์ „๋‹ฌ

(1) EC2 ์ธ์Šคํ„ด์Šค์— ์•„ํŒŒ์น˜ ์›น ์„œ๋ฒ„๋ฅผ ์„ค์น˜

ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin sudo apt-get install -y apache2

(2) ๋กœ๊ทธ ๊ทธ๋ฃน ์ƒ์„ฑ

(3) CloudWatch Agent ์„ค์ •์„ ๋ณ€๊ฒฝ

ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo vi config.json

{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "root"
        },
       ๐Ÿ‘‰ "logs": {
                "logs_collected": {
                        "files": {
                                "collect_list": [
					{
                                        "file_path": "/var/log/apache2/access.log",
                                        "log_group_name": "rookies_inst_ec2_web_logs",
                                        "log_stream_name": "access_logs"
					}
                                ]
                        }
                }
        }, ๐Ÿ‘ˆ ์ด๊ฑฐ ์ถ”๊ฐ€ํ•˜๊ธฐ 
        "metrics": {
		... (์ƒ๋žต) ...

(4) ์—์ด์ „ํŠธ ์ข…๋ฅ˜ ํ›„ ์žฌ์‹œ์ž‘

ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo ./amazon-cloudwatch-agent-ctl -m ec2 -a stop

** processing amazon-cloudwatch-agent **
ubuntu@ip-172-31-9-148:/opt/aws/amazon-cloudwatch-agent/bin$ sudo ./amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file://opt/aws/amazon-cloudwatch-agent/bin/config.json -s

** processing amazon-cloudwatch-agent **
I! Trying to detect region from ec2 D! [EC2] Found active network interface I! imds retry client will retry 1 timesSuccessfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp
Start configuration validation...
2024/04/29 06:06:44 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp ...
2024/04/29 06:06:44 I! Valid Json input schema.
2024/04/29 06:06:44 D! ec2tagger processor required because append_dimensions is set
2024/04/29 06:06:44 D! delta processor required because metrics with diskio or net are set
2024/04/29 06:06:44 D! ec2tagger processor required because append_dimensions is set
2024/04/29 06:06:44 Configuration validation first phase succeeded
I! Detecting run_as_user...
I! Trying to detect region from ec2
D! [EC2] Found active network interface
I! imds retry client will retry 1 times
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml
Configuration validation second phase succeeded
Configuration validation succeeded
amazon-cloudwatch-agent has already been stopped

(5) CloudWatch์—์„œ ์•„ํŒŒ์น˜ ์ ‘์† ๋กœ๊ทธ๋ฅผ ํ™•์ธ



6. ๋Œ€์‹œ๋ณด๋“œ ์„ค์ •



7. ๊ฒฝ๋ณด(alert) ์„ค์ •

์„ค์ • ๋‚ด์šฉ ํ™•์ธ ํ›„ [๊ฒฝ๋ณด ์ƒ์„ฑ] ๋ฒ„ํŠผ์„ ํด๋ฆญ

๊ตฌ๋… ์Šน์ธ ์•ˆ๋‚ด ๋ฉ”์ผ ์ˆ˜์‹  ์—ฌ๋ถ€ ํ™•์ธ ํ›„ ๊ตฌ๋… ์Šน์ธ์„ ์ฒ˜๋ฆฌ

๊ฒฝ๋ณด ํ™•์ธ



8. ๋Œ€์‹œ๋ณด๋“œ์— ๊ฒฝ๋ณด๋ฅผ ์ถ”๊ฐ€



9. S3๋กœ ์ „์†ก

๋ฒ„์ปท์— ํด๋”๋ฅผ ์ƒ์„ฑ

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "AWSCloudTrailAclCheck20150319-0882ce1a-2d45-4557-a10a-f7a7a316ebb3",
			"Effect": "Allow",
			"Principal": {
				"Service": "cloudtrail.amazonaws.com"
			},
			"Action": "s3:GetBucketAcl",
			"Resource": "arn:aws:s3:::rookies-inst-cloudtrail-logs",
			"Condition": {
				"StringEquals": {
					"AWS:SourceArn": "arn:aws:cloudtrail:ap-northeast-2:471112797705:trail/rookies_inst_cloudtrail"
				}
			}
		},
		{
			"Sid": "AWSCloudTrailWrite20150319-69bc4745-723c-456f-bdc4-6bbafbc3e7fd",
			"Effect": "Allow",
			"Principal": {
				"Service": "cloudtrail.amazonaws.com"
			},
			"Action": "s3:PutObject",
			"Resource": "arn:aws:s3:::rookies-inst-cloudtrail-logs/AWSLogs/471112797705/*",
			"Condition": {
				"StringEquals": {
					"s3:x-amz-acl": "bucket-owner-full-control",
					"AWS:SourceArn": "arn:aws:cloudtrail:ap-northeast-2:471112797705:trail/rookies_inst_cloudtrail"
				}
			}
		},
		{
			"Effect": "Allow", 
			"Principal": {
				"Service": "logs.ap-northeast-2.amazonaws.com"
			},
			"Action": "s3:GetBucketAcl",
			"Resource": "arn:aws:s3:::rookies-inst-cloudtrail-logs"
		}, 
		๐Ÿ‘‰{
			"Effect": "Allow", 
			"Principal": {
				"Service": "logs.ap-northeast-2.amazonaws.com"
			},
			"Action": "s3:PutObject",
			"Resource": "arn:aws:s3:::rookies-inst-cloudtrail-logs/vpc-flow-logs/*",
			"Condition": {
				"StringEquals": {
					"s3:x-amz-acl": "bucket-owner-full-control"
				}
			}
		}๐Ÿ‘ˆ
	]
}

CloudWatch์—์„œ ๋กœ๊ทธ ๊ทธ๋ฃน์„ S3 ๋ฒ„ํ‚ท์œผ๋กœ ์ „๋‹ฌ

S3 ๋ฒ„ํ‚ท ํ™•์ธ



10. ๋ฆฌ์†Œ์Šค ์ •๋ฆฌ

1) EC2 ์ธ์Šคํ„ด์Šค ์ข…๋ฃŒ ๋ฐ ํ‚คํŽ˜์–ด ์‚ญ์ œ

2) SNS ๊ตฌ๋… ์‚ญ์ œ ํ›„ ์ฃผ์ œ ์‚ญ์ œ

3) CloudWatch ๊ฒฝ๋ณด ์‚ญ์ œ

4) VPC ์‚ญ์ œ

5) CloudTrail ์ถ”์  ์‚ญ์ œ

6) CloudWatch ๋กœ๊ทธ ๊ทธ๋ฃน๊ณผ ๋Œ€์‹œ ๋ณด๋“œ ์‚ญ์ œ

7) S3 ๋ฒ„ํ‚ท ๋น„์šฐ๊ณ  ์‚ญ์ œ

8) IAM ์—ญํ• , ์ •์ฑ… ์‚ญ์ œ

0๊ฐœ์˜ ๋Œ“๊ธ€