3 ๋ถ„ ์†Œ์š”

์šฐ๋ถ„ํˆฌ??

์šฐ๋ถ„ํˆฌ(Ubuntu) ๋Š” ๋ฐ๋น„์•ˆ(Debian) ๊ธฐ๋ฐ˜์˜ ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ์œผ๋กœ, ๊ฐœ์ธ ์‚ฌ์šฉ์ž๋ถ€ํ„ฐ ๊ธฐ์—…์— ์ด๋ฅด๊ธฐ๊นŒ์ง€ ๋‹ค์–‘ํ•œ ์šฉ๋„๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋ฒ„์ „ ์ •๋„๋กœ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค!

๋ฐ๋น„์•ˆ์€ ๋˜ ๋ญ”๋ฐ?

๋ฐ๋น„์•ˆ ์€ ์ด์•ˆ ๋จธ๋…(Ian Murdock)์— ์˜ํ•ด ์„ค๋ฆฝ๋œ ์ž์œ  ์†Œํ”„ํŠธ์›จ์–ด ๊ณต๋™์ฒด์ž„.

๋ฐ๋น„์•ˆ ํ”„๋กœ์ ํŠธ๋Š” GNU/Linux ์šด์˜ ์ฒด์ œ์˜ ํ•œ ์ข…๋ฅ˜์ธ ๋ฐ๋น„์•ˆ GNU/Linux ๋ฅผ ๊ฐœ๋ฐœํ•˜๊ณ  ์œ ์ง€๋ณด์ˆ˜ํ•œ๋‹ค.

๋ฐ๋น„์•ˆ ํ”„๋กœ์ ํŠธ๋Š” ์ž์œ  ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์ง€์ง€ํ•˜๊ณ , ์‚ฌ์šฉ์ž๊ฐ€ ์ž์œ ๋กญ๊ฒŒ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ํ•œ๋‹ค

์ผ๋‹จ ์ด์ •๋„๋งŒ ์•Œ๊ณ  ๋„˜์–ด๊ฐ€์ž..!

์šฐ๋ถ„ํˆฌ์˜ ์ฃผ์š” ์šฉ๋„

  • ๊ฐœ์ธ์šฉ ๋ฐ์Šคํฌํƒ‘
    • ์‚ฌ์šฉ์ž ์นœํ™”์  ์ธํ„ฐํŽ˜์ด์Šค์™€ ๊ด‘๋ฒ”์œ„ํ•œ ์†Œํ”„ํŠธ์›จ์–ด ํ˜ธํ™˜์„ฑ์œผ๋กœ ๊ฐœ์ธ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ ํ•ฉํ•จ!
  • ์„œ๋ฒ„ ํ™˜๊ฒฝ
    • ์•ˆ์ •์„ฑ๊ณผ ๋ณด์•ˆ์„ฑ์„ ๋ฐ”ํƒ•์œผ๋กœ ์›น ์„œ๋ฒ„, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„œ๋ฒ„ ๋“ฑ ๋‹ค์–‘ํ•œ ์„œ๋ฒ„ ์šฉ๋„๋กœ ์‚ฌ์šฉ๋จ!
  • ํด๋ผ์šฐ๋“œ ์ปดํ“จํŒ…
    • ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„๋Š” AWS, Azure, Google Cloud ๋“ฑ์˜ ์ฃผ์š” ํด๋ผ์šฐ๋“œ ํ”Œ๋žซํผ์—์„œ ์ง€์›๋˜๊ณ , ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ์ตœ์ ํ™”๋œ ์„ฑ๋Šฅ์„ ์ œ๊ณตํ•จ!
  • ์‚ฌ๋ฌผ ์ธํ„ฐ๋„ท
    • ์šฐ๋ถ„ํˆฌ ์ฝ”์–ด๋ฅผ ํ†ตํ•ด IoT ์žฅ์น˜์—๋„ ์ตœ์ ํ™”๋œ ์šด์˜์ฒด์ œ๋กœ ์‚ฌ์šฉ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

์šฐ๋ถ„ํˆฌ ์„ค์น˜ ๋ฐ ์„ค์ •

์šฐ๋ถ„ํˆฌ ISO ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

์šฐ๋ถ„ํˆฌ ๊ณต์‹ ์›น์‚ฌ์ดํŠธ์—์„œ ์ตœ์‹  ์šฐ๋ถ„ํˆฌ ๋ฐ์Šคํฌํƒ‘ ๋ฒ„์ „์˜ ISO ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค!

๋ถ€ํŒ… ๊ฐ€๋Šฅํ•œ USB ๋“œ๋ผ์ด๋ธŒ

์šฐ๋ถ„ํˆฌ ISO ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ๋ถ€ํŒ… ๊ฐ€๋Šฅํ•œ USB ๋“œ๋ผ์ด๋ธŒ(์ตœ์†Œ 4GB ์ด์ƒ)๋ฅผ ์ค€๋น„ํ•ด์•ผํ•จ!

Rufus

๋ถ€ํŒ… ๊ฐ€๋Šฅํ•œ USB ๋“œ๋ผ์ด๋ธŒ๋ฅผ ๋งŒ๋“œ๋Š” ๋„๊ตฌ์ž„.

Rufus ๊ณต์‹ ์›น์‚ฌ์ดํŠธ์—์„œ ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅ~!

์šฐ๋ถ„ํˆฌ ์ ‘์†ํ•˜๊ธฐ

๋กœ๊ทธ์ธ

AWS์—์„œ ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„์— ์ ‘์†ํ•˜๋ ค๋ฉด SSH ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•จ.

์ด๋ฅผ ์œ„ํ•ด AWS ๊ด€๋ฆฌ ์ฝ˜์†”์—์„œ ์ œ๊ณตํ•œ ํ‚ค ํŽ˜์–ด ๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์•ˆ ์—ฐ๊ฒฐ์„ ์„ค์ •ํ•ด์•ผํ•œ๋‹ค!

AWS ๊ธฐ์ค€ ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„ ์ ‘์† ๋ฐฉ๋ฒ•

AWS ์ธ์Šคํ„ด์Šค์— SSH๋กœ ๋“ค์–ด๊ฐ€์ž!

chmod 400 /path/to/your-key-file.pem 
ssh -i "your-key-file.pem" ubuntu@ec2-xx-xxx-xxx-xx.ap-northeast-2.compute.amazonaws.com
  • ec2-xx-xxx-xxx-xx๋Š” EC2์˜ ํผ๋ธ”๋ฆญ IP ์ฃผ์†Œ์ž„!
  • aws ec2 ๋Œ€์‹œ๋ณด๋“œ ๋“ค์–ด๊ฐ€์„œ ์ธ์Šคํ„ด์Šค ์—ฐ๊ฒฐ โ†’ SSH ์—ฐ๊ฒฐ ๋ˆ„๋ฅด๋ฉด ์•„๋ž˜์— SSH ์ ‘์† ๋ช…๋ น์–ด ์ œ๊ณตํ•จ

๋ฐฐํฌ๋Š” ์–ด๋–ป๊ฒŒ?

์˜ˆ๋ฅผ ๋“ค์–ด, Django ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•˜๋ ค๋ฉด Gunicorn ๊ณผ Nginx ๋ฅผ ๊ฒฐํ•ฉํ•˜์—ฌ ๋ฐฐํฌ๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค!

Django์—์„œ ๊ฐœ๋ฐœ ๋ฐ ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉํ•˜๋Š” runserver ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•œ ์„œ๋ฒ„๋Š” ๊ณ ์„ฑ๋Šฅ์„ ์œ„ํ•œ ์ตœ์ ํ™”๊ฐ€ ๋˜์–ด์žˆ์ง€ ์•Š์€ ์„œ๋ฒ„์ž„!!

์‹ฌ์ง€์–ด ๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ ๋ฐ ๋ฉ€ํ‹ฐ ํ”„๋กœ์„ธ์Šค ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์•„, ๊ณ ๋ถ€ํ•˜ ํ™˜๊ฒฝ์—์„œ ์•ˆ์ •์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋‹จ์ ๋„ ์žˆ๋‹ค..

๊ฒŒ๋‹ค๊ฐ€ ๋ณด์•ˆ์ ์ธ ์ธก๋ฉด์—์„œ๋„ ์•ฝ์ ์ด ๋งŽ๋‹ค๊ณ  ํ•œ๋‹ค..

๊ทธ๋Ÿผ Gunicorn์ด ๋ญ”๋ฐ?

Gunicorn(Green Unicorn) ์€ Python WSGI ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ HTTP ์„œ๋ฒ„์ž„!

  • WSGI(Web Server Gateway Interface) [WSGI ๊ณต์‹๋ฌธ์„œ]
    • ์‰ฝ๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด Python Application์ด ์›น ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜๊ธฐ ์œ„ํ•œ ํ‘œ์ค€ ์ธํ„ฐํŽ˜์ด์Šค๋กœ, ํŒŒ์ด์ฌ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค.

Gunicorn ํŠน์ง•

  • WSGI ์„œ๋ฒ„
  • ๋ฉ€ํ‹ฐ ํ”„๋กœ์„ธ์Šค ์ง€์›
    • ์—ฌ๋Ÿฌ Worker ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•ด ๋™์‹œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค!
  • ๊ฐ„๋‹จํ•œ ์„ค์ •
  • ํ™•์žฅ์„ฑ
    • Worker ํ”„๋กœ์„ธ์Šค ์ˆ˜๋ฅผ ์กฐ์ ˆํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ฒ˜๋ฆฌ ๋Šฅ๋ ฅ์„ ์‰ฝ๊ฒŒ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค!

Nginx๋Š”?

Nginx ๋Š” ์›น ์„œ๋ฒ„ & ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์„œ๋ฒ„์ด๋‹ค.

ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์•„ Gunicorn ์„œ๋ฒ„๋กœ ์ „๋‹ฌํ•˜๊ณ , ์ •์  ํŒŒ์ผ์„ ์ œ๊ณตํ•˜๋ฉฐ, ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์ค‘์š”ํ•œ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค!

Nginx ํŠน์ง•

  • ์ •์  ํŒŒ์ผ ์„œ๋น™
    • ์ •์  ํŒŒ์ผ(CSS, JavaScript, ์ด๋ฏธ์ง€ ๋“ฑ)์„ ๊ณ ์†์œผ๋กœ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋‹ค.
    • Gunicorn์€ ๋™์  ์ปจํ…์ธ  ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—, ์ •์  ํŒŒ์ผ ์„œ๋น™์„ Nginx๊ฐ€ ๋‹ด๋‹นํ•˜์—ฌ ํšจ์œจ UP!
  • ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ
    • Nginx๋Š” ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์•„ Gunicorn์— ์ „๋‹ฌํ•˜๊ณ , Gunicorn์œผ๋กœ๋ถ€ํ„ฐ์˜ ์‘๋‹ต์„ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•œ๋‹ค.
    • ์ด๋ฅผ ํ†ตํ•ด Guicorn์˜ ๋’ค์—์„œ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ, ์บ์‹ฑ, SSL ์ข…๋ฃŒ ๋“ฑ์˜ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค!
  • ๋ณด์•ˆ
    • Nginx๋Š” ๋‹ค์–‘ํ•œ ๋ณด์•ˆ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ , Dos ๊ณต๊ฒฉ ๋ฐฉ์–ด์™€ SSL/TLS ์„ค์ • ๋“ฑ์„ ํ†ตํ•ด ๋ณด์•ˆ์„ฑ์„ ๊ฐ•ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค!
  • ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ
    • ์—ฌ๋Ÿฌ Gunicorn ์ธ์Šคํ„ด์Šค์— ํŠธ๋ž˜ํ”ฝ์„ ๋ถ„์‚ฐ์‹œ์ผœ ๊ณ ๊ฐ€์šฉ์„ฑ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋‹ค!
  • ๊ณ ์„ฑ๋Šฅ
    • ๋น„๋™๊ธฐ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ์•„ํ‚คํ…์ฒ˜ ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋งค์šฐ ๋†’์€ ์„ฑ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค!

์„œ๋ฒ„ ํ™˜๊ฒฝ ์„ค์ •์„ ํ•ด๋ณด์ž!

์‹œ์Šคํ…œ ์—…๋ฐ์ดํŠธ ๋ฐ ํŒจํ‚ค์ง€ ์„ค์น˜

sudo apt update
sudo apt upgrade -y
  • ์‹œ์Šคํ…œ ํŒจํ‚ค์ง€ ๋ชฉ๋ก์„ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ๋ชจ๋“  ํŒจํ‚ค์ง€๋ฅผ ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•จ.
sudo apt install python3-pip python3-dev libpq-dev nginx curl -y
  • Python ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋„๊ตฌ์™€ ๊ฐœ๋ฐœ ํ—ค๋” ํŒŒ์ผ, PostgreSQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ์›น ์„œ๋ฒ„ Nginx, ๊ทธ๋ฆฌ๊ณ  curl์„ ์„ค์น˜ํ•จ.

์„œ๋ฒ„ ์•ˆ์—์„œ๋„ ๊ฐ€์ƒํ™˜๊ฒฝ!

curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh

source ~/.bashrc
conda create -n env python=3.10
conda activate env
pip install django
  • conda ๊ฐ€์ƒํ™˜๊ฒฝ์œผ๋กœ ์ง„ํ–‰ํ•จ

Django ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ํด๋ก  ๋ฐ›์ž!

settings.py ์—์„œ DB ์„ค์ •์„ ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•˜๋ ค๋Š” DB๋กœ ๋ฐ”๊พธ์ž!

๊ทธ๋ฆฌ๊ณ  ALLOWED_HOTS ๋ฅผ ๋งŒ์ ธ์ค˜์•ผ๋œ๋‹ค.

ALLOWED_HOSTS = ['your-ec2-public-dns', 'your-domain.com']
  • EC2 ์ธ์Šคํ„ด์Šค์˜ ํผ๋ธ”๋ฆญ DNS ๋˜๋Š” IP๋ฅผ ์ถ”๊ฐ€
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
  • ์ •์  ํŒŒ์ผ ์„ค์ •๋„ ํ•ด์ฃผ๊ณ 
python manage.py makemigrations
python manage.py migrate
  • ๋‹ค ํ–ˆ์œผ๋ฉด ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜
python manage.py createsuperuser
python manage.py runserver 0:8000
  • ๊ด€๋ฆฌ์ž ๊ณ„์ •๋„ ๋งŒ๋“ค์–ด์ฃผ๊ณ  ์‹คํ–‰ํ•ด๋ณด์ž!

Gunicorn ์‚ฌ์šฉ

๋จผ์ € gunicorn ์„ค์น˜๋ถ€ํ„ฐ ํ•ด์•ผ์ง€!

pip install gunicorn
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

Nginx๋„ ๊ฐ™์ด ์“ด๋‹ค ํ–ˆ์œผ๋‹ˆ๊นŒ!

sudo apt update
sudo apt install nginx -y
nginx -V # ๋ฒ„์ ผ ํ™•์ธ

Nginx ์„ค์ •

sudo /etc/init.d/nginx start
  • Nginx ์‹œ์ž‘ํ•ด๋ณด๊ธฐ!
# nano /etc/nginx/nginx.conf

http {
	....
	# /etc/nginx/conf.d ๋””๋ ‰ํ† ๋ฆฌ ์•„๋ž˜ ์žˆ๋Š” .conf ํŒŒ์ผ์„ ๋ชจ๋‘ ๋ถˆ๋Ÿฌ์˜ด
	include /etc/nginx/conf.d/*.conf;
}

default.conf ์ƒ์„ฑ

# nano /etc/nginx/conf.d/default.conf

server {
	listen 80;
    server_name pub_ip; 
    
    location /{
    	proxy_pass http://127.0.0.1:8000; 
    }
}
  • nano /etc/nginx/conf.d/default.conf ๋ช…๋ น์–ด๋กœ ํŒŒ์ผ์„ ์—ด๊ณ , ์ˆ˜์ • ํ›„ ์ €์žฅํ•˜๋ ค๋‹ˆ ์ž๊พธ ์˜ค๋ฅ˜ ๋ฐœ์ƒํ•จ
  • ํŒŒ์ผ์„ ์—ฌ๋Š” ๋ช…๋ น์–ด๋ฅผ sudo nano /etc/nginx/conf.d/default.conf ๋กœ ํ•˜๋ฉด ํ•ด๊ฒฐ๋จ!
sudo service nginx restar
  • Nginx ์žฌ์‹œ์ž‘ ํ•ด๋ณด๊ธฐ!

ํƒœ๊ทธ: ,

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ