๐Ÿš€ Languege/Django-Python

[Django #2] Django ์„ค์น˜ํ•˜๊ธฐ -EC2 - Amazon Linux2

mini_world 2021. 1. 14. 09:43
๋ชฉ์ฐจ ์ ‘๊ธฐ

์•ˆ๋…•ํ•˜์„ธ์š” ๐Ÿ™‹‍โ™€๏ธ ๐Ÿ™‹‍โ™‚๏ธ 

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” Amazon EC2 (Amazon Linux2)๋ฅผ ์ด์šฉํ•ด์„œ Django๋ฅผ ์„ค์น˜ํ•˜๊ณ  ๊ธฐ๋ณธ ํŽ˜์ด์ง€๋ฅผ ๋„์›Œ ๋ณผ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

Amazon EC2 ํ”„๋ฆฌํ‹ฐ์–ด๋กœ๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ, ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” Amazon EC2๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋ณ„๋„๋กœ ๋‹ค๋ฃจ์ง€ ์•Š์Šต๋‹ˆ๋‹ค!

์•„๋ž˜ ์บก์ณ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด, ์ด๋ฏธ ํ…Œ์ŠคํŠธ ์šฉ๋„์˜ EC2๋ฅผ ์ƒ์„ฑํ–ˆ์œผ๋ฉฐ, SSH ์ ‘์†์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ตฌ์„ฑ์ด ๋˜์–ด์žˆ๋‹ค!๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

 

 


โ— Django ํ”„๋ ˆ์ž„์›Œํฌ ์„ค์น˜

๋”๋ณด๊ธฐ

Django๋Š” Python ์›น ํ”„๋ ˆ์ž„์›Œํฌ ์ž…๋‹ˆ๋‹ค. Django๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ Python์ด  ์„ค์น˜๋˜์–ด์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค :)

2021-01-12(ํ™”) ์˜ค๋Š˜ ๊ธฐ์ค€์œผ๋กœ Djaogo 3.1์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Python 3.6, 3.7, 3.8, 3.9๊ฐ€ ํ•„์š”ํ•˜๋„ค์š”! ํ™•์ธ๋งํฌ

๋จผ์ €, Python ์„ค์น˜์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. 
์ถœ๋ ฅ ๊ฒฐ๊ณผ๊ฐ€ ์•„๋ฌด๊ฒƒ๋„ ์•ˆ๋‚˜์˜ค๋ฉด, ์„ค์น˜ ์•ˆ๋˜์–ด์žˆ๋Š”๊ฑฐ์—์š”๐Ÿ˜ญ ์„ค์น˜ํ•ด๋ด…์‹œ๋‹ค!

[root@django-host /]# yum list installed | grep -i python3

์„ค์น˜ ๋ช…๋ น์–ด๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

[root@django-host /]# sudo yum install python3 -y

์„ค์น˜ ์™„๋ฃŒ๋œ ํ›„์—๋Š” ์ด๋ ‡๊ฒŒ ์•„๋ž˜์— ์„ค์น˜๋œ ํŒจํ‚ค์ง€๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด์ œ ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ Django๋ฅผ ์„ค์น˜ํ•ฉ์‹œ๋‹ค!

[root@django-host /]# sudo python3 -m pip install Django

์„ค์น˜๊ฐ€ ์ž˜ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด Django ๋ฒ„์ „์„ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.

[root@django-host /]# python3 -m django --version

ํ”„๋ ˆ์ž„ ์›Œํฌ๋Š” ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

โ— ํ™˜๊ฒฝ์„ค์ • & ๊ธฐํƒ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

๋”๋ณด๊ธฐ

์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ๋ณต์‚ฌ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ฉ๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ํ•˜๋Š” ์ด์œ ๋Š”, django-admin ๋ช…๋ น์–ด ์‹คํ–‰์„ ์œ„ํ•ด PATH๋ฅผ ์„ค์ •ํ•˜๊ณ  python๋ช…๋ น์–ด ์‹คํ–‰์‹œ ๋ฒ„์ „์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค!

[root@django-host ~]# sudo echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
[root@django-host ~]# sudo echo alias python=python3 >> ~/.bash_profile

์„ค์ •์ด ์ž˜ ๋๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜ ๋‘๊ฐœ์˜ ๋ช…๋ น์–ด๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
๋‘๋ฒˆ์งธ ๋ช…๋ น์–ด์—์„œ python ๋ฒ„์ „์ด 3.7๋กœ ๋‚˜์˜จ๋‹ค๋ฉด ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ€์„ธ์š”!

[root@django-host ~]# source ~/.bash_profile
[root@django-host ~]# python --version

์ด๋ฒˆ์—๋Š” tree๋ช…๋ น์–ด๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

[root@django-host /]# sudo yum install tree -y

Django๋Š” ๊ธฐ๋ณธ DB๋กœ SQLite๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Django 3.1.5๋ฒ„์ „์—์„œ๋Š” SQLite 3.8.3์ด์ƒ ๋ฒ„์ „์ด ํ˜ธํ™˜๋ฉ๋‹ˆ๋‹ค.
AmazonLinux2์— ๊ธฐ๋ณธ ๋‚ด์žฅ๋œ SQLite ํŒจํ‚ค์ง€ ๋ฒ„์ „์€ 3.7.17์ด๋ฏ€๋กœ ๋ณ„๋„๋กœ SQLlite๋„ ์„ค์น˜ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

[root@django-host /]# wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm
[root@django-host /]# sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm sqlite-devel-3.8.11-1.fc21.x86_64.rpm

์ด์ œ ์„ค์น˜๊ฐ€ ์ž˜ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด์ค๋‹ˆ๋‹ค :)

[root@django-host /]# rpm -qa | grep sql

์„ค์น˜๊ฐ€ ์ž˜ ๋˜์—ˆ๋„ค์š”!!  ์ด์ œ ์ค€๋น„๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 

 

โ— Django ์›น ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

๋”๋ณด๊ธฐ

Django๋ฅผ ์‹คํ–‰ ํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

[root@django-host /]# sudo mkdir /my-django && cd /my-django

๊ทธ๋ฆฌ๊ณ  ์ด์ œ ์›น ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

[root@django-host my-django]# django-admin startproject mysite

์ด ๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ tree ๋ช…๋ น์–ด๋กœ ํ™•์ธ ์‹œ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Amazon EC2๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๊ณ ์žˆ๊ธฐ๋•Œ๋ฌธ์—, ๋กœ์ปฌ IP์ฃผ์†Œ๋กœ ์ ‘์†ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ, ์™ธ๋ถ€์—์„œ ์ ‘์†์ด ๊ฐ€๋Šฅํ•˜๋„๋ก(EC2 ๊ณต์ธIP์ ‘์†) ์„ค์ •์„ ๋ณ€๊ฒฝํ•ด์ฃผ๋„๋ก ํ•ฉ์‹œ๋‹ค ;)

๋จผ์ € Amazon EC2์˜ EIP๋ฅผ ํ™•์ธํ•ฉ์‹œ๋‹ค. ์ œ Amazon EC2์˜ ๊ณต์ธ IP์ฃผ์†Œ๋Š” 13.124.3.200 ์ด๋„ค์š” :)

 ์ด์ œ ์™ธ๋ถ€์—์„œ ์ ‘์† ๊ฐ€๋Šฅํ•˜๋„๋ก settings.py ์„ค์ •์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

vim ํŽธ์ง‘๊ธฐ๋กœ ์—ด์–ด์„œ ALLOWD_HOSTS ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. 
๊ณต์ธIP์ฃผ์†Œ๋ฅผ ๋„ฃ์–ด์ฃผ์…”์•ผ ํ•ด์š”!!

[root@django-host my-django]# vim mysite/mysite/settings.py 

 

์ด์ œ, ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•ด๋ด…์‹œ๋‹ค!!! 

[root@django-host my-django]# python mysite/manage.py runserver 0:8000

์˜ค! ๋ญ”๊ฐ€ ๋œจ๋„ค์š”!
์ด์ œ ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ ์ ‘์† ๋˜๋Š”์ง€ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.

์Ÿ๊ณ ๊ฐ€ ์ž˜ ๋กœ๋”ฉ ๋˜์—ˆ๋„ค์š”!!! 

 


์ด ๋‹จ๊ณ„๊นŒ์ง€ ๋งˆ๋ฌด๋ฆฌ ๋˜์—ˆ๋‹ค๋ฉด, Django๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์‹œ์ž‘ํ•˜๋Š”๊ฒƒ๊นŒ์ง€ ์™„๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค :)

Django Web Project๋ฅผ ๋งŒ๋“œ๋Š” ์ด๋ฒˆ ๋‹จ๊ณ„๊นŒ์ง€ ๋งˆ๋ฌด๋ฆฌ ํ–ˆ๋‹ค๋ฉด ๋””๋ ‰ํ† ๋ฆฌ๋Š” ์ด๋ ‡๊ฒŒ ๊ตฌ์„ฑ๋˜์—ˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. 

์ด ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ตฌ์กฐ๋Š” ์‹ค์Šต ์ง„ํ–‰ ๋‹จ๊ณ„๋งˆ๋‹ค ์ •์˜ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :)

์ด์ œ ๋‹ค์Œ ์‹ค์Šต์œผ๋กœ ๋„˜์–ด๊ฐ€์„œ ์‹ค์Šต์„ ๋งˆ๋ฌด๋ฆฌ ํ•ฉ๋‹ˆ๋‹ค! (์ˆœ์ฐจ์ ์œผ๋กœ ์—…๋กœ๋“œ ๋  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค)๐Ÿ˜˜

 

 

728x90