취미삼아 배우는 프로그래밍

장고 aws ec2 배포 메모 본문

코드 자가리뷰(장고)

장고 aws ec2 배포 메모

Nadure 2020. 8. 30. 12:49

한국어 설명

www.youtube.com/watch?v=oGQ1HteFYnQ&t=1233s

 

AWS 사용하기 :

WSL을 통한 우분투 접속
# WSL 진입
ssh -i <pem_path>.pem ubuntu@<AWS_EC2_IP>

# 이게 안되면 
chmod 400 <pem_path>.pem 

# 이거도 안되면
sudo ssh -i <pem_path>.pem ubuntu@<AWS_EC2_IP>

 

진입 후 필요한것 설치
sudo apt-get update
sudo apt-get install build-essential python3 python3-dev python3-pip python3-venv libpq-dev nginx
sudo apt-get update

sudo pip3 install --upgrade pip

 

퍼블릭 키 발급
ssh-keygen -t rsa

 

만든 키 여기있음
cat /home/ubuntu/.ssh/id_rsa.pub
# (깃헙에등록)

 

가상환경 만들기
# git clone > 진입
sudo apt-get install virtualenv
virtualenv -p python3 venv


# 가상환경 활성화
source venv/bin/activate

# pip 업그레이드
pip install --upgrade pip
pip install -r reuqirements.txt

# 메모: 
# sudo apt-get install libpq-dev
# libpq-dev < 이거 없으면 postgresql에서 오류남(psycopg) 그치만 위에서 설치함

 


Nginx 설정 : 다른 블로그 글 무진장 많음

https://cjh5414.github.io/nginx/

 

Django에서 Gunicorn, Nginx 이용하기

Jihun's Development Blog

cjh5414.github.io

위에껀 구니콘 사용 예, 아무튼 지금은 uwsgi 사용


 

git pull하고 사이트 업데이트
# 가상환경으로 들어가서 
uwsgi uwsgi.ini
# 후 
sudo service nginx reload

# gunicorn은 
# gunicorn 프로젝트명.wsgi:application

 


celery 사용 메뉴얼 정리잘된 곳 메모

gist.github.com/mau21mau/9371a95b7c14ddf7000c1827b7693801

 

Configure Celery + Supervisor With Django

Configure Celery + Supervisor With Django. GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

realpython.com/asynchronous-tasks-with-django-and-celery/

 

Asynchronous Tasks With Django and Celery – Real Python

This tutorial shows how to integrate Celery and Django and create Periodic Tasks

realpython.com

* already listening 오류시

stackoverflow.com/questions/25121838/supervisor-on-debian-wheezy-another-program-is-already-listening-on-a-port-that

 

Supervisor on Debian Wheezy: another program is already listening on a port that one of our HTTP servers is configured to use

When I run service supervisor start I run into the following error: Starting supervisor: Error: Another program is already listening on a port that one of our HTTP servers is configured to use. S...

stackoverflow.com


 

내 설정경로
sudo vi /etc/supervisor/conf.d/config-celery.conf

 

사용법
# 이걸로 키고(최초 실행만 하면됨, 자동재시작 들어가있음)
sudo supervisord

# 이걸로 컨트롤 ** 설정의 program 이름과 맞출것
sudo supervisorctl start config_celery
sudo supervisorctl stop config_celery
sudo supervisorctl reload config_celery
sudo supervisorctl status config_celery

 

윈도우에서 개발시 celery 작동 안될 때
# pip install gevent
celery -A config worker -l info -P gevent

# -P > Pool 옵션임, solo로 해도 사용가능함

 

Comments