์ธํ”„๋ผ

[AWS,Docker] No space left on device ์˜ค๋ฅ˜ + cron์œผ๋กœ docker๋ฏธ์‚ฌ์šฉ ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ

HHRR 2024. 9. 22. 21:51

์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€

No space left on device ์˜ค๋ฅ˜๊ฐ€ ๋– ์„œ ๊ตฌ๊ธ€๋งํ•ด๋ณด๋‹ˆ ์„œ๋ฒ„ ์ €์žฅ๊ณต๊ฐ„ ๋ถ€์กฑ ์˜ค๋ฅ˜๋ผ๊ณ  ํ•œ๋‹ค

java.io.IOException: No space left on device
    at java.base/java.io.FileOutputStream.writeBytes(Native Method)
    at java.base/java.io.FileOutputStream.write(FileOutputStream.java:349)
    at org.apache.tomcat.util.http.fileupload.ThresholdingOutputStream.write(ThresholdingOutputStream.java:127)
    at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:104)
    at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:317)
    at org.apache.catalina.connector.Request.parseParts(Request.java:2834)
    at org.apache.catalina.connector.Request.getParts(Request.java:2735)
    at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:795)
    at javax.servlet.http.HttpServletRequestWrapper.getParts(HttpServletRequestWrapper.java:326)
    at javax.servlet.http.HttpServletRequestWrapper.getParts(HttpServletRequestWrapper.java:326)
    at javax.servlet.http.HttpServletRequestWrapper.getParts(HttpServletRequestWrapper.java:326)
    at

 

ํ•ด๊ฒฐ ๊ณผ์ •

1. ์ €์žฅ๊ณต๊ฐ„ ํ™•์ธ

ํ˜„์žฌ EC2 ์œ„์—์„œ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„๊ฐ€ ๋Œ์•„๊ฐ€๊ณ ์žˆ์–ด์„œ ์ฝ˜์†”๋กœ ์ ‘๊ทผํ•ด์„œ ์„œ๋ฒ„ ์ €์žฅ๊ณต๊ฐ„์„ ํ™•์ธํ•ด๋ณด์ž

  System load:                      0.21630859375
  Usage of /:                       99.9% of 28.89GB
  Memory usage:                     62%
  Swap usage:                       18%
  Processes:                        112
  ...

  => / is using 99.9% of 28.89GB

 

99.9% ์‚ฌ์šฉ์ค‘์ธ๊ฑธ ๋ฐœ๊ฒฌ.. ๋กœ๊ทธ ๊ด€๋ฆฌ๋ฅผ ์•ˆํ–ˆ๋”๋‹ˆ ์ด๋Ÿฐ ๋Œ€์ฐธ์‚ฌ๊ฐ€ ์ผ์–ด๋‚ฌ๋‹ค.

์ด ์„œ๋ฒ„์—์„œ๋Š” Spring Boot, Kafka, Redis, MongoDB ๋ชจ๋‘ Docker๋กœ ๋„์›Œ๋†“๊ณ  ์žˆ์–ด์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ๋„์ปค ์ด๋ฏธ์ง€ ๋ฐ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ญ์ œํ•ด์•ผ๊ฒ ๋‹ค.

 

2. ๋ถˆํ•„์š”ํ•œ Docker ์ด๋ฏธ์ง€ ๋ฐ ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ

docker system prune -a

 

3. ์‚ญ์ œ ํ›„ ์ €์žฅ๊ณต๊ฐ„ ํ™•์ธ

  System load:                      0.22607421875
  Usage of /:                       27.9% of 28.89GB
  Memory usage:                     46%
  Swap usage:                       28%
  Processes:                        118

 

99.9% ์—์„œ ๋ฌด๋ ค 27.9%๋กœ ๊ฐ์†Œํ–ˆ๋‹ค!!

 

๊ทผ๋ฐ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ž‘ ์ด๋ฏธ์ง€๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ์‚ญ์ œํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ

cron์œผ๋กœ 2์ฃผ๋งˆ๋‹ค ์ผ์š”์ผ ์˜ค์ „ 3์‹œ์— ` docker system prune -a ` ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ์„ค์ •ํ•ด์•ผ๊ฒ ๋‹ค.

 


cron์œผ๋กœ docker prune ๋ช…๋ น์–ด ์ฃผ๊ธฐ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ

1. ํฌ๋ก ํƒญ ํŽธ์ง‘

` crontab -e `

 

2. ํฌ๋ก ํƒญ ํŒŒ์ผ์— ์ž‘์—… ์ถ”๊ฐ€

2์ฃผ๋งˆ๋‹ค ์ผ์š”์ผ ์˜ค์ „ 3์‹œ์— ๋ช…๋ น์ด ์‹คํ–‰๋˜๋„๋ก ์„ค์ •ํ–ˆ๋‹ค.

0 3 */14 * * /usr/bin/docker system prune -a --force