๐Ÿš€ AWS EC2 ๋ฐฐํฌํ•˜๊ธฐ ๋‘๋ฒˆ์งธ: Redis ์„ค์ • ๊ด€๋ จ Trouble Shooting

์ดํ•˜์–€ยท2023๋…„ 12์›” 8์ผ
1
post-thumbnail

์ด์ „ ๋‚ด์šฉ
๐Ÿณ SpringBoot + Docker + DockerCompose๋ฅผ ์ด์šฉํ•œ AWS EC2 ๋ฐฐํฌํ•˜๊ธฐ

1. Backend ํ˜„์žฌ ๋ฌธ์ œ ์ƒํ™ฉ

EC2 ์„œ๋ฒ„

$ docker logs web

์„œ๋ฒ„ ๋‚ด Docker Image ํ™•์ธ

โ†’ ์Šคํ”„๋ง๋ถ€ํŠธ ๊ด€๋ จ ๋กœ๊ทธ๊ฐ€ ๋– ์•ผ ํ•˜๋Š”๋ฐ, ํ˜„์žฌ redis ๊ด€๋ จ ๋กœ๊ทธ๊ฐ€ ์จ์ง€๊ณ  ์žˆ๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.
(์ด์™€๋Š” ๋ณ„๊ฐœ๋กœ redis ์„ค์ •์—๋Š” ์„ฑ๊ณตํ•œ ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค...!)



2. ์›์ธ ๋ถ„์„

1๏ธโƒฃ Github Actions โ€œDeploy to serverโ€

  • redis๋ผ๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ  ๋˜์–ด ์žˆ๋Š” ์ƒํƒœ์ž…๋‹ˆ๋‹ค.



    2๏ธโƒฃ deploy.yml ์Šคํฌ๋ฆฝํŠธ ํ™•์ธ
    - name: Docker build & push to docker repo
            run: |
              docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
              docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} .
              docker push ${{ secrets.DOCKER_REPO }}
              docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO_REDIS }} .
              docker push ${{ secrets.DOCKER_REPO_REDIS }}
  • web๊ณผ redis๊ฐ€ ๊ฐ™์€ Dockerfile์— ์ •์˜๋˜์–ด ์žˆ๋Š” ๊ฒƒ์ด ๋ฌธ์ œ์ธ ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค๐Ÿง
  • ๋˜ํ•œ, ์Šคํฌ๋ฆฝํŠธ์˜ ์ˆœ์„œ์— ๋”ฐ๋ผ์„œ ๋ถ„์„ํ•ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    • ๋„์ปค ์ด๋ฏธ์ง€๊ฐ€ web(springboot) ๊ด€๋ จ ๋‚ด์šฉ์œผ๋กœ ๋นŒ๋“œ
    • push ์ง„ํ–‰
    • ๋„์ปค ์ด๋ฏธ์ง€๊ฐ€ redis ๊ด€๋ จ ๋‚ด์šฉ์œผ๋กœ ๋นŒ๋“œ
      โ†’ ์ด์ „์˜ 1,2๋ฒˆ์„ ๋ฎ์–ด์“ฐ๊ธฐํ•˜๋ฉฐ ๋นŒ๋“œ
    • push ์ง„ํ–‰


3. ๊ฒฐ๋ก 

  • ์œ„์˜ ๊ณผ์ •์œผ๋กœ ์ธํ•ด bulid๊ฐ€ ๋ฎ์–ด์“ฐ๊ธฐ ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ๊ฒฌ๋˜์—ˆ์Œ์„ ํŒŒ์•…ํ–ˆ์Šต๋‹ˆ๋‹ค.
    โ†’ ๊ณผ์ •์ด ์ง„ํ–‰๋˜๋ฉฐ ๋นŒ๋“œ๋˜๋Š” redis ๊ด€๋ จ ์„ค์ •์ด web ์ปจํ…Œ์ด๋„ˆ์˜ ์ด๋ฏธ์ง€๋กœ ๋ฎ์–ด์“ฐ๊ธฐ ๋˜์–ด redis ๊ด€๋ จ ๋กœ๊ทธ๋งŒ ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๊ณ 
    โ†’ redis๋ผ๋Š” ์ด๋ฆ„์„ ๊ฐ€์ง„ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์—ˆ๋˜ ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒํ•˜๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์ž…๋‹ˆ๋‹ค.


4. ์ˆ˜์ •์‚ฌํ•ญ

๐Ÿš€ ์„ ํƒ์ง€

  • Dockerfile์„ web๊ณผ redis๋กœ ๋‹ค๋ฅธ ํŒŒ์ผ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ์ž‘์—… ์ง„ํ–‰
  • ๊ฐ™์€ Dockerfile ๋‚ด์—์„œ ์Šคํ…Œ์ด์ง•์„ ์ง€์ •ํ•ด์„œ ๋‚˜๋ˆ ์ฃผ๋Š” ์ž‘์—… ์ง„ํ–‰

์–ด๋–ค ์„ ํƒ์„ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„์ง€ ๊ณ ๋ฏผํ•˜๋Š” ๊ณผ์ •์— chatGPT์—๊ฒŒ ๊ถ๊ธˆํ–ˆ๋˜ ๋ถ€๋ถ„์„ ๋ฌผ์–ด๋ดค์Šต๋‹ˆ๋‹ค.

  • ๊ธฐ๋ณธ์ ์œผ๋กœ Dockerfile์€ ๋‹จ์ผ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋Œ€๋ถ€๋ถ„ ํ•˜๋‚˜์˜ ๋กœ์ง๋งŒ ์ž‘์„ฑํ•œ๋‹ค๊ณ  ํ•˜๋„ค์š”!
  • ํ•˜์ง€๋งŒ ํ˜„์žฌ, Dockerfile์— ์Šคํ”„๋ง๋ถ€ํŠธ ์„ค์ • + Redis ์„ค์ •์„ ๋ชจ๋‘ ํ•ด๋‘” ๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ๋  ์ˆ˜๋„ ์žˆ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ•˜๊ฒŒ ๋˜์—ˆ๊ณ  ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ• ์„ ์„ ํƒํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค.

โœ๏ธ ์ˆ˜์ • ๊ณผ์ •

โ„๏ธ IntelliJ IDEA

  • root ๊ฒฝ๋กœ์˜ Dockerfile์—์„œ redis ์„ค์ • ์ง€์šฐ๊ธฐ
    FROM openjdk:17-alpine
    # ARG JAR_FILE=parking-0.0.1-SNAPSHOT.jar
    ARG JAR_FILE=/build/libs/parking-0.0.1-SNAPSHOT.jar
    COPY ${JAR_FILE} myboot.jar
    ENTRYPOINT ["java", "-jar", "/myboot.jar"]
  • Dockerfile๊ณผ ๊ฐ™์€ ๊ฒฝ๋กœ์— Dockerfile-redis ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ
    FROM redis
    # COPY conf/redis.conf /usr/local/etc/redis/redis.conf
    CMD [ "redis-server"]
    EXPOSE 6379
  • deploy.yml ์ˆ˜์ •
    - name: Docker build & push to docker repo
      run: |
        docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
        
        # Build and push web image
        docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} .
        docker push ${{ secrets.DOCKER_REPO }}
        
        # Build and push redis image
        docker build -f Dockerfile_redis -t ${{ secrets.DOCKER_REPO_REDIS }} .
        docker push ${{ secrets.DOCKER_REPO_REDIS }}

โ„๏ธ Github Actions

  • commit&push ํ›„ Build ๊ธฐ๋‹ค๋ฆฌ๊ธฐ
  • ์ฃผ์˜ : Deploy to server ๋‹จ๊ณ„์—์„œ No Such container: redis ์•ˆ๋œจ๋Š”์ง€ ํ™•์ธ!(์•ˆ๋– ์•ผ ์ •์ƒ)
  • ๋ชจ๋‘ ์ผœ์ง€๋ฉด ๋‹ค์‹œ ec2 ์„œ๋ฒ„์— ๊ฐ€์„œ ๊ฐ ๋กœ๊ทธ ํ™•์ธํ•˜๊ธฐ

โ„๏ธ EC2

  • docker logs web โ†’ ์ด์ „์ฒ˜๋Ÿผ ์Šคํ”„๋ง๋ถ€ํŠธ ๊ด€๋ จ ๋กœ๊ทธ ๋œจ๋Š”์ง€ ํ™•์ธ
  • docker logs redis โ†’ redis ๊ด€๋ จ ๋กœ๊ทธ ๋œจ๋Š”์ง€ ํ™•์ธ


๐Ÿ”Ž ์ฐธ๊ณ  ์ž๋ฃŒ
๐Ÿ’ฌ Redis ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ ๋งŒ๋“ค๊ธฐ
๐Ÿ’ฌ redis: Docker Official Image
๐Ÿ’ฌ [Redis] Redis ์‹คํ–‰ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜ ํ•ด๊ฒฐ
๐Ÿ’ฌ Redis: Warning Memory overcommit must be enabled #1731
๐Ÿ’ฌ [DevOps/Docker]Redis๋ฅผ Docker๋กœ ๋„์šฐ๊ธฐ + Docker Compose up์œผ๋กœ ๋„์šฐ๊ธฐ
๐Ÿ’ฌ [AWS] ์žฌ๋ถ€ํŒ… ๋ฐฉ๋ฒ•
๐Ÿ’ฌ ๋„์ปค ์„ค์น˜ ํ›„ ๋„์ปค ๋ช…๋ น์–ด ์‹คํ–‰ ์—๋Ÿฌ Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
๐Ÿ’ฌ DevOps/docker/ [docker] ๋„์ปค ์ปจํ…Œ์ด๋„ˆ, ์ด๋ฏธ์ง€ ์‚ญ์ œํ•˜๊ธฐ(docker rm, rmi)

profile
์–ธ์  ๊ฐ€ ๋‚ด ์ฝ”๋“œ๋กœ ์„ธ์ƒ์— ๊ธฐ์—ฌํ•  ์ˆ˜ ์žˆ๋„๋ก, BE&Data Science ๊ฐœ๋ฐœ ๊ธฐ๋ก ๋…ธํŠธโ˜˜๏ธ

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