소스코드 설치
1 $ mkdir projects
2 $ cd projects
3 $ git clone git@github.com:<github-user>/<github-repo>.git mynewproject
virtualenv 설정
1 $ sudo pip3 install virtualenv
2 $ mkdir PYENVS
3 $ cd PYENVS
4 $ virtualenv -p python3 mynewproject
5 $ source mynewproject/bin/activate
6 (mynewproject) $ cd ~/projects/mynewproject
7 (mynewproject) $ pip install -r requirments.txt
gunicorn 설정
1 (mynewproject) $ pip install gunicorn
2 $ sudo vi /etc/systemd/system/mynewproject.service
3 $ sudo systemctl enable mynewproject.service
4 $ sudo systemctl start mynewproject
5 $ mkdir ~/logs
# service 파일 수정 시 설정 리로드
6 $ sudo systemctl daemon-reload
# 서버 시작
7 $ sudo systemctl start mynewproject
# 서버 재시작
8 $ sudo systemctl restart mynewproject
# 서버 상태 체크
9 $ sudo systemctl status mynewproject -l
gunicorn 설정을 위한 systemd 파일
[Unit]
Description=My New Project
After=network.start
[Service]
Restart=always
RestartSec=5
WorkingDirectory=/home/ec2-user/projects/mynewproject
User=ec2-user
ExecStart=/home/ec2-user/PYENVS/mynewproject/bin/gunicorn \
--workers=2 \ # (CPU core 수 + 1)
--access-logfile=/home/ec2-user/logs/mynewproject-access.log \
--error-logfile=/home/ec2-user/logs/mynewproject-error.log \
--log-level=error \
--bind=0.0.0.0:8000 \
--timeout=600 \
mynewproject.wsgi
[Install]
WantedBy=multi-user.target
Amazon Linux Catalog 업데이트
1 $ sudo amazon-linux-extras list
PostgreSQL 설치
1 $ sudo amazon-linux-extras install 41
2 $ sudo yum install postgresql-server postgresql-devel -y
3 $ sudo service postgresql initdb
4 $ sudo systemctl start postgresql.service
5 $ sudo -u postgres psql postgres
postgres=# create database mynewproject;
NGINX 설치
1 $ sudo amazon-linux-extras install 38