TIL84. WetchaPedia Project : EC2, RDS ๋ฐฐํฌ

ID์งฑ์žฌยท2021๋…„ 11์›” 14์ผ
0

WeChaCha Project

๋ชฉ๋ก ๋ณด๊ธฐ
6/8
post-thumbnail

๐Ÿ“Œ ์ด ํฌ์ŠคํŒ…์—์„œ๋Š” AWS EC2, AWS RDS๋ฅผ ํ†ตํ•œ ์ƒ์— ์ฒซ ๋ฐฐํฌ ๊ณผ์ •์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.



๐ŸŒˆ AWS EC2, AWS RDS ๋ฐฐํฌ

๐Ÿ”ฅ AWS EC2 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

๐Ÿ”ฅ AWS RDS ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

๐Ÿ”ฅ AWS EC2, AWS RDS ํ™œ์šฉํ•œ ๋ฐฐํฌ ๊ณผ์ •



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

๐Ÿค” EC2 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

โœ”๏ธ 1๋‹จ๊ณ„ : AMI(Amazon Machine Image) ์„ ํƒํ•œ๋‹ค.

Ubuntu Server 18.04 LTS(HVM), SSD Volume Type ์„ ํƒํ•œ๋‹ค.

โœ”๏ธ 2๋‹จ๊ณ„ : ์ธ์Šคํ„ด์Šค ์œ ํ˜• ์„ ํƒ

"T2 micro (ํ”„๋ฆฌ ํ‹ฐ์–ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ)" ์„ ํƒํ•œ๋‹ค.

โœ”๏ธ 3๋‹จ๊ณ„ : ์ธ์Šคํ„ด์Šค ์„ธ๋ถ€ ์ •๋ณด ๊ตฌ์„ฑ

  • ์„œ๋ธŒ๋„ท ์„ ํƒ : ๊ธฐ๋ณธ์œผ๋กœ ๋ณด์ด๋Š” ์„œ๋ธŒ๋„ท์„ ์„ ํƒํ•ด์ค€๋‹ค(ex.subnet-cafccab0)
  • Public IP ์ž๋™ ํ• ๋‹น : "์„œ๋ธŒ๋„ท ์‚ฌ์šฉ ์„ค์ •(ํ™œ์„ฑํ™”)" ์ฒดํฌ
  • ์ข…๋ฃŒ ๋ฐฉ์ง€ ๊ธฐ๋Šฅ ํ™œ์„ฑํ™” : "์šฐ๋ฐœ์ ์ธ ์ข…๋ฃŒ๋กœ ๋ถ€ํ„ฐ ๋ณดํ˜ธ" ์ฒดํฌ

โœ”๏ธ 5๋‹จ๊ณ„ : ํƒœ๊ทธ ์ถ”๊ฐ€

  • Key๊ฐ’ ๋ฐ Value๊ฐ’(ํ”„๋กœ์ ํŠธ ์ด๋ฆ„) ์ž…๋ ฅ

โœ”๏ธ 6๋‹จ๊ณ„ : ๋ณด์•ˆ ๊ทธ๋ฃน ๊ตฌ์„ฑ

  • ๊ทœ์น™ ์ถ”๊ฐ€ : ์œ ํ˜•(์‚ฌ์šฉ์ž ์ง€์ • TCP), ํ”„๋กœํ† ์ฝœ(TCP), ํฌํŠธ๋ฒ”์œ„(8000), ์†Œ์Šค(์œ„์น˜๋ฌด๊ด€)
  • ์™„๋ฃŒํ•˜์˜€๋‹ค๋ฉด ๊ฒ€ํ†  ๋ฐ ์‹œ์ž‘ ๋ฒ„ํŠผ ํด๋ฆญ!

๐Ÿค” ๊ธฐ์กด ํ‚ค ํŽ˜์–ด ์„ ํƒ ๋˜๋Š” ์ƒˆ ํ‚ค ํŽ˜์–ด ์ƒ์„ฑ

โœ”๏ธ "์ƒˆ ํ‚ค ํŽ˜์–ด ์ƒ์„ฑ" ์„ ํƒ โ‡ข ํ‚ค ํŽ˜์–ด ์ด๋ฆ„ ์ž…๋ ฅ ํ›„ โ‡ข "ํ‚ค ํŽ˜์–ด ๋‹ค์šด๋กœ๋“œ" ํด๋ฆญ

โœ”๏ธ ํ‚ค ํŽ˜์–ด ์ด๋ฆ„์€ "wecode"๋กœ ํ–ˆ๋‹ค. โ‡ข ์ธ์Šคํ„ด์Šค ์‹œ์ž‘ ๋ฒ„ํŠผ ํด๋ฆญ!

โœ”๏ธ ํ‚ค ํŽ˜์–ด๋Š” ๋‹ค์‹œ ๋‹ค์šด๋ฐ›์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ณด๊ด€์„ ์ž˜ํ•ด์•ผํ•˜๊ณ , ์ด ํ‚คํŽ˜์–ด๋ฅผ ํ†ตํ•ด Ubuntu์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋‹ค.

โœ”๏ธ ๋˜ํ•œ ํ‚คํŽ˜์–ด๊ฐ€ pemํŒŒ์ผ์ผ ์ค„ ์•Œ์•˜๋Š”๋ฐ, ๋‚œ cer ํŒŒ์ผ์ด์—ˆ๋‹ค. ํŒŒ์ผ๋งŒ ๋‹ค๋ฅด๊ณ  ์ž‘๋™๋ฐฉ์‹์€ ๊ฐ™๋‹ค.

๐Ÿค” pem ํŒŒ์ผ ๋ชจ๋“œ ์„ค์ •

โœ”๏ธ ํ„ฐ๋ฏธ๋„ ์—ด์–ด์„œ ํ‚คํŽ˜์–ด ํŒŒ์ผ์ด(pem ๋˜๋Š” cerํŒŒ์ผ) ์กด์žฌํ•˜๋Š” ๊ณณ์œผ๋กœ ์ด๋™ํ•œ๋‹ค.

โœ”๏ธ ์ตœ์ดˆ ์‚ฌ์šฉํ•˜๋Š” ํ‚คํŽ˜์–ด๋ผ๋ฉด ๋ชจ๋“œ ๋ณ€๊ฒฝ๋ฅผ ๋ณ€๊ฒฝํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

$ chmod 400 [ํŒŒ์ผ๋ช….cer]

โœ”๏ธ ssh ์ ‘์† ์„ค์ •

$ ssh -i [ํŒŒ์ผ๋ช….cer] ubuntu@[๊ณต์ธIP] ๐Ÿ‘ˆ EC2 ์ธ์Šคํ„ด์Šค์—์„œ Ipv4 ํผ๋ธ”๋ฆญ IP ์ฃผ์†Œํ™•์ธ ๊ฐ€๋Šฅ

โœ”๏ธ ๊ณ„์† Yes ๋˜๋Š” Enter๋ฅผ ๋ˆ„๋ฅด๋ฉด์„œ ์ง„ํ–‰ํ•ด์ค€๋‹ค. Ubuntu ์ ‘์†์ด๋˜์—ˆ๋‹ค๋ฉด ์ž˜ ์ง„์ž…๋œ ๊ฒƒ์ด๋‹ค.



2. AWS RDS ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

๐Ÿค” ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน ์ƒ์„ฑ

โœ”๏ธ ๋ฌธ์ž์—ด์„ ํ‘œ๊ธฐํ•˜๋Š” ๋ฐฉ์‹์— ์žˆ์–ด ํ•œ๊ธ€, ์ด๋ชจํ‹ฐ์ฝ˜ ๋“ฑ์ด ๊นจ์ง€์ง€์•Š๋„๋ก ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน์„ ์„ค์ •ํ•ด์ค€๋‹ค.

"ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน ์ƒ์„ฑ" ๋ฒ„ํŠผ ํด๋ฆญ โ‡ข ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน ํŒจ๋ฐ€๋ฆฌ(๐Ÿ”Žmysql 5.7 ์„ ํƒ)

โœ”๏ธ ๊ทธ๋ฃน ์ด๋ฆ„ ๋ฐ ์„ค๋ช… ์ž…๋ ฅํ•œ ๋’ค, ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน์„ ์ƒ์„ฑํ•˜๊ณ  ์ƒ์„ ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ํŽธ์ง‘ ํŽ˜์ด์ง€๋กœ ์ง„์ž…ํ•œ๋‹ค.

โœ”๏ธ ๊ฒ€์ƒ‰์ฐฝ์— character๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์•„๋ž˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋“ค์˜ ์ด๋ฆ„์„ ๋ชจ๋‘ "utf8mb4"๋กœ ์ง€์ • ํ›„ ์ „์ฒด ์ฒดํฌํ•œ ๋’ค์— ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ €์žฅ

  • character_set_client โ‡ข utf8mb4
  • character_set_connection โ‡ข utf8mb4
  • character_set_database โ‡ข utf8mb4
  • character_set_filesystem โ‡ข utf8mb4
  • character_set_results โ‡ข utf8mb4
  • character_set_server โ‡ข utf8mb4

โœ”๏ธ collation ๊ฒ€์ƒ‰ํ•ด์„œ ๋‚˜์˜ค๋Š” ์•„๋ž˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์•„๋ž˜์ฒ˜๋Ÿผ ์ง€์ • ํ›„ ์ „์ฒด ์ฒดํฌํ•œ ๋’ค์— ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ €์žฅํ•œ๋‹ค.

  • collation_connection โ‡ข utf8mb4_general_ci
  • collation_server โ‡ข utf8mb4_unicode_ci

๐Ÿค” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ

โœ”๏ธ "ํ‘œ์ค€ ์ƒ์„ฑ", "MySQL", "MySQL Community", "ํ”„๋ฆฌํ‹ฐ์–ด" ์„ ํƒ

โœ”๏ธ "DB ์ธ์Šคํ„ด์Šค ์‹๋ณ„์ž" ์ž…๋ ฅ ๋ฐ "๋งˆ์Šคํ„ฐ ์‚ฌ์šฉ์ž ์ด๋ฆ„" ์€ root, ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ค€๋‹ค.

โœ”๏ธ "์Šคํ† ๋ฆฌ์ง€ ์ž๋™ ์กฐ์ •" ์ฒดํฌ ํ•ด์ œ

โœ”๏ธ "ํผ๋ธ”๋ฆญ ์•ก์„ธ์Šค ๊ฐ€๋Šฅ"์€ "์˜ˆ"๋กœ ๋ณ€๊ฒฝ

โœ”๏ธ VPC ๋ณด์•ˆ ๊ทธ๋ฃน์—์„œ "์ƒˆ๋กœ ์ƒ์„ฑ" ์ฒดํฌ โ‡ข ์ƒˆ VPC ๋ณด์•ˆ ๊ทธ๋ฃน ์ด๋ฆ„(ex: project๋ช…-rules)

โœ”๏ธ ๊ฐ€์šฉ์˜์—ญ ์ค‘ ํ•˜๋‚˜ ์„ ํƒํ•˜๊ณ , ํฌํŠธ๋Š” 3306 ์ธ์ง€ ํ™•์ธ

โœ”๏ธ ์ถ”๊ฐ€ ๊ตฌ์„ฑ

  • ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„์€ local์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋‚˜์ค‘์— ์ง์ ‘ ์ƒ์„ฑํ•ด์ค˜๋„ ๋œ๋‹ค.

    mysql >>> > (aws)$ create database [AWS db์ด๋ฆ„] character set utf8mb4 collate utf8mb4_general_ci; โ‡ข exit

  • DB ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน์€ ์œ„์—์„œ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ทธ๋ฃน ์ƒ์„ฑํ•œ ๊ฒƒ์œผ๋กœ ์ง€์ •

  • ์˜ต์…˜ ๊ทธ๋ฃน์€ default๋กœ ๋˜์žˆ๋Š”๊ฑฐ ์‚ฌ์šฉ

  • "์ž๋™ ๋ฐฑ์—… ํ™œ์„ฑํ™”" ์ฒดํฌํ•ด์ œ, "๋ชจ๋‹ˆํ„ฐ๋ง" ์ฒดํฌ ํ•ด์ œ

  • "์œ ์ง€๊ด€๋ฆฌ ๋งˆ์ด๋„ˆ ๋ฒ„์ „ ์ž๋™ ์—…๊ทธ๋ ˆ์ด๋“œ ์‚ฌ์šฉ" ์ฒดํฌ

  • "์‚ญ์ œ ๋ฐฉ์ง€ ํ™œ์„ฑํ™”" ์ฒดํฌ

โœ”๏ธ ๋ชจ๋‘ ์™„๋ฃŒํ–ˆ๋‹ค๋ฉด, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ ํด๋ฆญํ•œ ๋’ค, ๊ธฐ๋‹ค๋ ธ๋‹ค๊ฐ€ ์•„๋ž˜ ๋ณด์•ˆ ๊ทธ๋ฃน ๊ทœ์น™์„ ์„ค์ •ํ•ด์ค€๋‹ค.

๐Ÿค” ๋ณด์•ˆ ๊ทธ๋ฃน ๊ทœ์น™

โœ”๏ธ ๋ณด์•ˆ ๊ทธ๋ฃน์— inbound์™€ outbound๊ฐ€ ์žˆ๋Š”๋ฐ, inbound ํด๋ฆญ

โœ”๏ธ ํ•˜๋‹จ ์ฐฝ์— ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ ํŽธ์ง‘ ํด๋ฆญํ•ด์„œ 3๊ฐ€์ง€ ๊ทœ์น™ ์ถ”๊ฐ€

  • HTTPS / 443 / ์œ„์น˜๋ฌด๊ด€
  • HTTP / 80 / ์œ„์น˜๋ฌด๊ด€
  • TCP / 8000 / ์œ„์น˜๋ฌด๊ด€

โœ”๏ธ ์ถ”์ฒœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋‹ˆ๋‚˜ ์šฐ์„  ์ด๋ ‡๊ฒŒํ•ด๋‘๊ณ  ์ถ”ํ›„ ๋‹ค์‹œ ๋ณ€๊ฒฝ, EC2 ์„œ๋ฒ„์˜ IP์ฃผ์†Œ๋„ ํ•จ๊ป˜ ์ถ”๊ฐ€ํ•ด์ค˜ํ•œ๋‹ค.

๐Ÿค” AWS RDS ์ ‘์†ํ•˜๊ธฐ

โœ”๏ธ ํ„ฐ๋ฏธ๋„์—์„œ AWS RDS ์ ‘์† ๋ฐฉ๋ฒ•

(local)$ mysql -h [์—”๋“œํฌ์ธํŠธ ๋ถ™์—ฌ๋„ฃ๊ธฐ] -u root -p โ‡ข ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ

๐Ÿค” MySQL dump & injection

โœ”๏ธ AWS RDS ์ ‘์†์— ๋ฌธ์ œ์—†๋‹ค๋ฉด, local MySQL์˜ DB๋ฅผ ํ†ต์ฑ„๋กœ ์˜ฎ๊ธฐ๊ธฐ ์œ„ํ•ด dump๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์ž.

โœ”๏ธ DB Dumpํ•ด์„œ sqlํŒŒ์ผ๋กœ ๋งŒ๋“ค๊ธฐ

(local)$ mysqldump -u root -p [DB์ด๋ฆ„] > [ํŒŒ์ผ๋ช…].sql โ‡ข ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ

โœ”๏ธ dumpํ•œ local DB๋ฅผ AWS RDS์— injectionํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

โœ”๏ธ injection ๋ฐฉ๋ฒ•

(local)$ mysql -h [์—”๋“œํฌ์ธํŠธ ๋ถ™์—ฌ๋„ฃ๊ธฐ] -u root -p [AWS db์ด๋ฆ„] < [ํŒŒ์ผ๋ช…].sql โ‡ข ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ



3. AWS EC2, AWS RDS ํ™œ์šฉํ•œ ๋ฐฐํฌ ๊ณผ์ •

๐Ÿค” AWS EC2 ์ง„์ž… ๋ฐ Miniconda ์„ค์น˜

โœ”๏ธ ์ธ์ฆ์„œ๊ฐ€ ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•ด์„œ EC2 ์ง„์ž… ์‹œ์ž‘

$ ssh -i [ํŒŒ์ผ๋ช….cer] ubuntu@[๊ณต์ธIP] ๐Ÿ‘ˆ EC2 ์ธ์Šคํ„ด์Šค์—์„œ Ipv4 ํผ๋ธ”๋ฆญ IP ์ฃผ์†Œํ™•์ธ ๊ฐ€๋Šฅ

โœ”๏ธ ์ง„์ž…๋˜์—ˆ๋‹ค๋ฉด, ubuntu์— miniconda๋ถ€ํ„ฐ ์„ค์น˜ํ•œ๋‹ค. ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ ํด๋ฆญํ•˜์—ฌ ๊ฒฝ๋กœ๋ณต์‚ฌ๋ฅผ ํ•œ๋‹ค.

$ wget [linux ๋ฒ„์ „ miniconda ๊ฒฝ๋กœ๋ณต์‚ฌํ•œ ์ฃผ์†Œ]

โœ”๏ธ ls๋กœ ํ™•์ธํ•˜๋ฉด "Miniconda3-py38_4.10.3-Linux-x86_64.sh"๊ฐ€ ์กด์žฌํ•œ๋‹ค. ๊ถŒํ•œ๋ถ€ํ„ฐ ์„ค์ •ํ•œ๋‹ค.

$ chmod +x Miniconda3-py38_4.10.3-Linux-x86_64.sh

โœ”๏ธ ๊ถŒํ•œ ์„ค์ •ํ•˜์˜€๋‹ค๋ฉด mini ํŒŒ์ผ ์‹คํ–‰ํ•˜์—ฌ ์„ค์น˜ํ•ด์ค€๋‹ค.

$ ./Miniconda3-py38_4.10.3-Linux-x86_64.sh

โœ”๏ธ local ์ฒ˜๋Ÿผ (base)๊ฐ€ ๋‚˜ํƒ€๋‚˜๋„๋ก ์„ค์ •ํ•ด์ค€๋‹ค.

$ source .bashrc

๐Ÿค” mysql ์„ค์น˜

โœ”๏ธ apt๋ฅผ ์—…๋ฐ์ดํŠธ ๋ฐ ์—…๊ทธ๋ ˆ์ด๋“œ ์‹œํ‚จ๋‹ค.

(base)$ sudo apt-get update

(base)$ sudo apt-get upgrade

โœ”๏ธ mysql ์„ค์น˜์‹œ์— ์—๋Ÿฌ๋ฅผ ์˜ˆ๋ฐฉํ•˜๊ธฐ ์œ„ํ•ด gcc ์„ค์น˜ํ•œ๋‹ค.

(base)$ sudo apt-get install gcc

โœ”๏ธ mysql์„ ๊ฐœ๋ฐœ์ž ๋ฒ„์ „์œผ๋กœ ์„ค์น˜ํ•ด์ค€๋‹ค.

(base)$ sudo apt-get install libmysqlclient-dev

๐Ÿค” conda ๊ฐ€์ƒํ™˜๊ฒฝ ์„ค์น˜ ๋ฐ ํ™œ์„ฑํ™”

โœ”๏ธ ๊ฐ€์ƒํ™˜๊ฒฝ ์„ค์น˜ ๋ฐ ํ™œ์„ฑํ™”

(base)$ conda create -n project python=3.8 ๐Ÿ‘ˆ project ์ด๋ฆ„์œผ๋กœ ์ƒ์„ฑ

(base)$ conda activate project

๐Ÿค” git clone

โœ”๏ธ git clone์„ ์‹คํ–‰ํ•œ๋‹ค.

(project)$ git clone [github ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ ์ฃผ์†Œ]

โœ”๏ธ ๋””๋ ‰ํ† ๋ฆฌ ์ด๋™ ํ›„ requirements.txt ํŒŒ์ผ ํ™•์ธ ๋ฐ ์„ค์น˜

(project)$ pip install -r requirements.txt ๐Ÿ‘ˆ requirements.txt์— ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ ๋ชจ๋‘ ํ•œ๋ฒˆ์— ์„ค์น˜

๐Ÿค” settings.py์˜ IPv4 Pulic IP ์„ค์ •

โœ”๏ธ settings.py์— ์ง„์ž…ํ•œ๋‹ค.

(project)$ vi config/settings.py

โœ”๏ธ AWS EC2์˜ IPv4 Pulic IP๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

ALLOWED_HOSTS = ["*", "IPv4 Pulic IP", "IPv4 Pulic IP:8000"] # ๐Ÿ‘ˆ EC2์˜ ํผํ”Œ๋ฆญ ip ์ž…๋ ฅ

๐Ÿค” settings.py ์ƒ์„ฑ

โœ”๏ธ manage.py ๊ฐ€ ์žˆ๋Š” ์œ„์น˜์— my_settings.py ์ƒ์„ฑ

(project)$ vi my_settings.py

โœ”๏ธ locale์—์„œ ์•„๋ž˜ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜จ ๋’ค, AWS RDS์™€ ์—ฐ๊ฒฐ์‹œ์ผœ ์ค€๋‹ค.

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "DB์ด๋ฆ„ ์ž…๋ ฅ",
        "USER": "root",
        "PASSWORD": "๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ",
        "HOST": "AWS RDS ์—”๋“œํฌ์ธํŠธ ์ž…๋ ฅ",
        "PORT": "3306",
    }
}
SECRET_KEY = "SECRET_KEY ์ž…๋ ฅ"
ALGORITHM = "ALGORITHM ๋ฐฉ์‹ ์ž…๋ ฅ"

๐Ÿค” ์„œ๋ฒ„ ์‹คํ–‰ ๋ฐ Postman ์‹คํ—˜

โœ”๏ธ 8000๋ฒˆ ํฌํŠธ๋กœ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค.

(project)$ python manage.py runserver 0:8000

โœ”๏ธ ๊ฒฝ๋กœ๋Š” Ipv4 ๊ณต์ธ IP์™€ 8000๋ฒˆ ํฌํŠธ๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

  • http://[IPv4 Pulic IP]:8000/


4. gunicorn ์„ค์น˜ ๋ฐ ์„ธํŒ…

๐Ÿค” gunicon ์„ค์น˜

โœ”๏ธ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„ ํ”„๋กœ๊ทธ๋žจ gunicorn์€ ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ๋ฅผ ์ง€์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋งŽ์€ request๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

(project)$ pip install gunicorn

๐Ÿค” gunicon ์‹คํ–‰

โœ”๏ธ gunicorn์œผ๋กœ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

(project)$ gunicorn --bind=0.0.0.0:8000 [ํ”„๋กœ์ ํŠธ๋ช…].wsgi

โœ”๏ธ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์‹คํ–‰์‹œ์•„๋ž˜์™€ ๊ฐ™์ด ์‹คํ–‰์‹œํ‚ค๋ฉด ๊ณ„์† ์ผœ์ ธ์žˆ๋‹ค.

(project)$ nohup gunicorn --bind=0.0.0.0:8000 [ํ”„๋กœ์ ํŠธ๋ช…].wsgi &

โœ”๏ธ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์„œ๋ฒ„๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š”๋ฐ ์ด๋ฅผ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

(project)$ ps -ef | grep python

โœ”๏ธ ์ด๋ฅผ ์ข…๋ฃŒ์‹œํ‚ค๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ๊ฐ€๋Šฅํ•˜๋‹ค.

(project)$ kill [PID ๋ฒˆํ˜ธ]

profile
Keep Going, Keep Coding!

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