728x90
๋ฐ˜์‘ํ˜•
  1. ec2 ๋ฐœ๊ธ‰
  2. ufw ์„ค์ • ๋ฐ port ๊ตฌ์„ฑ๋„
  3. swap ๋ฉ”๋ชจ๋ฆฌ ์„ค์ •
  4. docker ์„ค์น˜ (+ Ubuntu ๊ธฐ๋ณธ ํ™˜๊ฒฝ ์„ธํŒ…)
  5. docker-compose & jenkins ์„ค์น˜
  6. jenkins gitlab ์—ฐ๋™(project-build) ๋ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜
  7. Nginx
  8. https ์ ์šฉ
  9. Jenkins Pipeline ์ž‘์„ฑ
  10. S3 ์„ค์น˜ ๋ฐ ์„ค์ •
  11. RDS ์„ค์น˜ ๋ฐ ์„ค์ •

 

jenkins gitlab ์—ฐ๋™(project-build) ๋ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜

 

Backend Dockerfile(๋ฐฑ์—”๋“œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ปจํ…Œ์ด๋„ˆํ™”ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ)

FROM openjdk:17-jdk-alpine
VOLUME /tmp 
ADD ./build/libs/backend-0.0.1-SNAPSHOT.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT ["java", "-jar", "/app.jar"]

 

  1. FROM openjdk:17-jdk-alpine
    : openjdk:17-jdk-alpine ์ด๋ฏธ์ง€๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒˆ docker ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑ
    - openjdk:17-jdk-alpine ๋Š” OpenJDK 17์„ ํฌํ•จ + ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ ์ค‘ ํ•˜๋‚˜์ธ Alpine Linux ๊ธฐ๋ฐ˜์˜ ์ด๋ฏธ์ง€
    - Alpine Linux๋Š” ๊ฒฝ๋Ÿ‰ํ™”๊ฐ€ ์ž˜ ๋˜์–ด ์žˆ์–ด ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์ž‘๊ฒŒ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค
  2. VOLUME /tmp
    : /tmp ๊ฒฝ๋กœ์— ๋ณผ๋ฅจ์„ ๋งˆ์šดํŠธ ํ•จ
    - ์ผ๋ฐ˜์ ์œผ๋กœ Spring Boot ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” /tmp๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž„์‹œ ํŒŒ์ผ ๋“ฑ์„ ์ €์žฅํ•˜๋Š”๋ฐ ์‚ฌ์šฉ
  3. ADD ./build/libs/backend-0.0.1-SNAPSHOT.jar app.jar
    : ๋กœ์ปฌ ํŒŒ์ผ ์‹œ์Šคํ…œ์˜ backend-0.0.1-SNAPSHOT.jar ํŒŒ์ผ์„ ์ปจํ…Œ์ด๋„ˆ์˜ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— app.jar๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ณต์‚ฌ
    -  ADD๋Š” COPY์™€ ์œ ์‚ฌํ•˜์ง€๋งŒ ์›๊ฒฉ URL์—์„œ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ๋กœ์ปฌ ํŒŒ์ผ์„ ์ž๋™์œผ๋กœ ์••์ถ• ํ•ด์ œํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€๋กœ ์ œ๊ณต
  4. ENV JAVA_OPTS=""
    : ํ™˜๊ฒฝ ๋ณ€์ˆ˜  JAVA_OPTS๋ฅผ ์„ค์ •

    - ๊ธฐ๋ณธ์ ์œผ๋กœ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์„ค์ •๋˜์–ด ์žˆ์Œ
  5. ENTRYPOINT ["java", "-jar", "/app.jar"]
    : ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ์‹คํ–‰๋˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์ง€์ •
    - java ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ช…๋ น์–ด
    - -jar ์˜ต์…˜ ๋‹ค์Œ์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ JAR ํŒŒ์ผ์˜ ๊ฒฝ๋กœ์ธ /app.jar๋ฅผ ์ง€์ •ํ•จ

 

 

Frontend Dockerfile

FROM node:20.12.0

WORKDIR /app

COPY package.json /app

RUN npm install
COPY . /app

EXPOSE 3000
RUN npm run docs-build

CMD ["npm","run", "docs"]

 

 

  1. 'FROM node:20.12.0'.
    : 'node:20.12.0' ์ด๋ฏธ์ง€๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒˆ Docker ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑ
  2. WORKDIR /app
    : 'WORKDIR' ๋ช…๋ น์–ด๋Š” Docker ์ด๋ฏธ์ง€ ๋‚ด์—์„œ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ '/app' ์œผ๋กœ ์„ค์ •
     ์ดํ›„์˜ ๋ช…๋ น์–ด๋“ค์€ ์ด ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‹คํ–‰
  3. COPY package.json /app
    : ํ˜ธ์ŠคํŠธ ๊ธฐ๊ธฐ์˜ 'package.json' ํŒŒ์ผ์„ ์ด๋ฏธ์ง€ ๋‚ด์˜ '/app' ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋ณต์‚ฌ
  4. RUN npm install
    : npm install ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ package.json์— ์ •์˜๋œ Node.js ํ”„๋กœ์ ํŠธ์˜ ์˜์กด์„ฑ์„ ์„ค์น˜
  5. COPY . /app
    : ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๋ชจ๋“  ํŒŒ์ผ๊ณผ ์„œ๋ธŒ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ด๋ฏธ์ง€ ๋‚ด์˜ '/app' ๋””๋ ‰ํ† ๋ฆฌ์— ๋ณต์‚ฌ
  6. EXPOSE 3000
    : ์นธํ…Œ์ธ์ €๊ฐ€ ๋ฆฌ์Šค๋‹ํ•  ํฌํŠธ ๋ฒˆํ˜ธ 3000์„ Docker์— ์•Œ๋ฆผ. ์ด ํฌํŠธ๋ฅผ ํ†ตํ•ด ์™ธ๋ถ€์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค
  7. RUN npm run docs-build
    : npm run docs-build ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ฌธ์„œ๋ฅผ ๋นŒ๋“œํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰
  8. CMD ["npm","run", "docs"]
    : ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹คํ–‰๋  ๋–„ 'npm run docs' ๋ช…๋ น์„ ์‹คํ–‰(์ผ๋ฐ˜์ ์œผ๋กœ ๋ฌธ์„œ๋ฅผ ํ˜ธ์ŠคํŒ…ํ•˜๊ฑฐ๋‚˜ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ)

 

Ngnix

Ngnix ????

: ๊ฒฝ๋Ÿ‰ ์›น์„œ๋ฒ„๋กœ ์ •์ ํŒŒ์ผ์„ serving ํ•˜๋Š” web server ๋˜๋Š” ์š”์ฒญ์„ ๋‹ค๋ฅธ ์„œ๋ฒ„๋กœ ์ „๋‹ฌํ•˜๋Š” reverse proxy server๋กœ ํ™œ์šฉ๋˜์–ด was์˜ ๋ถ€ํ•˜๋ฅผ ์ค„์ด๋Š” ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค


=> ์›น  ์„œ๋ฒ„์ค‘ apache์™€์˜ ํŒŒ์ด์  : ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹
apache ์›น ์„œ๋ฒ„์˜ ๊ฒฝ์šฐ ์š”์ฒญ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์“ฐ๋ ˆ๋“œ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์š”์ฒญ์„ ์ฒ˜๋ฆฌ๋˜๋ฏ€๋กœ ์š”์ฒญ์ด ๋งŽ์œผ๋ฉด ๋งŽ์„์ˆ˜๋ก ์ž์›์ด ๋งŽ์ด ์†Œ๋ชจ๋œ๋‹ค
๋ฐ˜๋ฉด์— nginx๋Š” event-driven ๊ตฌ์กฐ๋กœ ๋™์ž‘ํ•˜๋Š”๋ฐ, ์ด ๋•Œ๋ฌธ์— ํ•˜๋‚˜ ๋˜๋Š” ๊ณ ์ •๋œ ๊ฐœ์ˆ˜์˜ ํ”„๋กœ์„ธ์Šค๋งŒ ์ƒ์„ฑ๋˜๊ณ  ์š”์ฒญ๋“ค์€ ๋™์‹œ์ ์œผ๋กœ ์ฒ˜๋ฆฌ๋œ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋ณด๋‹ค ์ ์€ ์ž์›์œผ๋กœ๋„ ํšจ์œจ์ ์ธ ์šด์šฉ์ด ๊ฐ€๋Šฅ

 

 

sudo apt update 
sudo apt-get install nginx

 

- sudo apy update : ์‹œ์Šคํ…œ์˜ ํŒจํ‚ค์ง€ ๋ชฉ๋ก ์—…๋ฐ์ดํŠธ

- sudo apt-get install nginx :  nginx ์›น ์„œ๋ฒ„๋ฅผ ์„ค์น˜

 

 

nginx ์›น ์„œ๋ฒ„์—์„œ ์ƒˆ๋กœ์šด ์‚ฌ์ดํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•

sudo nano /etc/nginx/sites-available/๋‚ด๊ฐ€ ๋งŒ๋“ค ๊ฒƒ
vi์ฝ”๋“œ๋กœ ์—ด๊ณ  ๋ฐ‘์— ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. 

server {
    listen 80;					// ์„œ๋ฒ„๊ฐ€ 80๋ฒˆ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ HTTP ์š”์ฒญ์„ ์ˆ˜์‹ ํ•˜๋„๋ก ์„ค์ •
    server_name abc.com www.abc.com;		// ํ•ด๋‹น ๋„๋ฉ”์ธ์œผ๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•จ

    root /var/www/abc.com/html;				// ์›น ๋ฌธ์„œ์˜ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ €์žฅ(์‹ค์ œ ์›น ํŒŒ์ผ๋“ค์ด ์—ฌ๊ธฐ ์œ„์น˜/ abc.com์€ ๋‚ด ๋„๋ฉ”์ธ์œผ๋กœ ๋ณ€๊ฒฝํ•ด์•ผํ•จ)
    index index.html index.htm index.nginx-debian.html;	// ๊ธฐ๋ณธ ์ธ๋ฑ์Šค ํŒŒ์ผ๋“ค์„ ์ •์˜ nginx๋Š” ์š”์ฒญ๋œ ๋””๋ ‰ํ† ๋ฆฌ์— ์ด ํŒŒ์ผ์ด ์žˆ์œผ๋ฉด ํ•ด๋‹น ํŒŒ์ผ์„ ์‘๋‹ต์œผ๋กœ ๋ณด๋ƒ„

    location / {						// ๋ฃจํŠธ url('/') ์— ๋Œ€ํ•œ ์„ค์ •์„ ์ •์˜
        try_files $uri $uri/ =404;		// ์š”์ฒญ๋œ ํŒŒ์ผ์ด ์žˆ์œผ๋ฉด ํ•ด๋‹น ํŒŒ์ผ์„ ์„œ๋น™, ์—†์œผ๋ฉด ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ํ™•์ธ, ๋‘˜๋‹ค ์—†์œผ๋ฉด 404 ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜
    }
}

 

 

ํ•ด๋‹น ํŒŒ์ผ์„ sites-enabled๋กœ ์˜ฎ๊ฒจ์ค€๋‹ค.


: sites-available ๋””๋ ‰ํ† ๋ฆฌ๋Š” ๋ชจ๋“  ์‚ฌ์ดํŠธ์˜ ์„ค์ • ํŒŒ์ผ์„ ๋ณด๊ด€ํ•˜๋Š” ๊ณณ / sites-enabled๋Š” ํ˜„์žฌ ํ™œ์„ฑํ™”๋œ ์‚ฌ์ดํŠธ์˜ ์„ค์ • ํŒŒ์ผ์— ๋Œ€ํ•œ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๋ณด๊ด€ํ•จ์œผ๋กœ์จ, ํŠน์ • ์‚ฌ์ดํŠธ๋ฅผ ์‰ฝ๊ฒŒ ํ™œ์„ฑํ™”ํ•˜๊ฑฐ๋‚˜ ๋น„ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค

 

 

nginx ์žฌ์‹คํ–‰

 

sudo nginx -t 	 			// nginx์˜ ์„ค์ • ํŒŒ์ผ์— ๋ฌธ์ œ๊ฐ€ ์—†๋Š”์ง€ ํ™•์ธ
sudo systemctl restart nginx		// nginx ์žฌ์‹œ์ž‘
sudo service nginx status		// nginx๊ฐ€ ์ž˜ ์‹คํ–‰์ค‘์ธ์ง€ ํ™•์ธ

 

 

๊ทธ ํ›„์— ec2 ํผ๋ธ”๋ฆญ ip์ฃผ์†Œ๋กœ ์ ‘์†ํ•˜๋ฉด 

๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค

 

 

์ฐธ๊ณ 

https://blog.naver.com/gi_balja/223028077537

 

Nginx๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

Nginx(์—”์ง„์—‘์Šค)๋Š” ๋†’์€ ์„ฑ๋Šฅ๊ณผ ์•ˆ์ •์„ฑ ๊ทธ๋ฆฌ๊ณ  ํ˜„์žฌ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” ์›น ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค. Apache(์•„...

blog.naver.com

 

https://velog.io/@dev_leewoooo/Forward-Proxy-Reverse-Proxy%EC%97%90-%EA%B4%80%ED%95%98%EC%97%AC

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts