Home
SeungYong Baek edited this page Jun 21, 2021
·
20 revisions
- 구성 검증은 하였으나 환경에 따라 오류가 있을 수 있음
- Python 3.5 --> 3.6 업그레이드 완료 - 2020/12/15
- Zipline 1.3.0 --> 1.4.1 업그레이드 보류 - 패키지 의존성 및 많은 코드 수정이 발생하여 1.3.0 버전 유지
- Ubuntu 18.04 --> 20.04 업그레이드 보류 - 패키지 의존성 문제로 18.04 버전 유지
- Google Cloud Platform - g1-small(vCPU 1개, 1.7GB 메모리)
- 또는 Amazon Web Services - t2.micro(vCPU 1개, 1GB 메모리)
- Ubuntu 18.04.5 LTS
- VPC 네트워크 방화벽 규칙 변경 필요 - http/https, ssh, Django 테스트,MySQL, Jupyter 노트북등
- 현재 Zipline은 Python 2.7, 3.5, 3.6을 지원 - https://github.com/quantopian/zipline
- Ubuntu 18.04.5의 기본 Python은 3.6
seungyong@findmore:~$ sudo apt update seungyong@findmore:~$ sudo apt upgrade
- Python 3.6 추가 패키지 및 Zipline을 위한 패키지 설치 - https://www.zipline.io/install.html
seungyong@findmore:~$ sudo apt install python3-venv python3-dev seungyong@findmore:~$ sudo apt install libatlas-base-dev python-dev gfortran pkg-config libfreetype6-dev hdf5-tools
- 불필요한 패키지 삭제
- 간혹 Zipline에 필요한 Cython이 컴파일이 되지 않음
seungyong@findmore:~$ sudo apt autoremove
- Python 3.6 가상 환경 생성
seungyong@findmore:~$ python3 -m venv zipline seungyong@findmore:~$ source /home/seungyong/zipline/bin/activate
- 가상환경에서 Python 모듈 및 Zipline 패키지 설치
(zipline) seungyong@findmore:~$ pip install --upgrade pip (zipline) seungyong@findmore:~$ pip install wheel pandas pandas_datareader finance-datareader numpy bs4 matplotlib (zipline) seungyong@findmore:~$ pip install zipline==1.3.0
-
Zipline 설치 완료 후에, 지원 중단된 API가 있어서 zipline benchmark.py 수정 필요
-
IEX CLOUD 가입 및 TOKEN 발급 필요 - https://iexcloud.io
-
/home/seungyong/zipline/lib/python3.6/site-packages/zipline/data/benchmark.py
# r = requests.get( # 'https://api.iextrading.com/1.0/stock/{}/chart/5y'.format(symbol) # ) IEX_TOKEN='pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxx' r = requests.get( 'https://cloud.iexapis.com/stable/stock/{}/chart/5y?token={}'.format(symbol,IEX_TOKEN) )
(zipline) seungyong@findmore:~$ sudo apt install nginx mysql-server libssl-dev libmysqlclient-dev (zipline) seungyong@findmore:~$ pip install uwsgi Django mysqlclient
(zipline) seungyong@findmore:~$ sudo mysql -u root mysql> use mysql; mysql> update user set plugin='mysql_native_password' where user='root'; mysql> alter user 'root'@'localhost' identified by 'xxxxxx'; mysql> create database findmore character set utf8; mysql> create user django@'localhost' identified by 'djangopassword'; mysql> grant all privileges on findmore.* to 'django'@'localhost'; mysql> create user django@'%' identified by 'djangopassword'; mysql> grant all privileges on findmore.* to 'django'@'%'; mysql> flush privileges ;
- 소스 코드 다운로드
(zipline) seungyong@findmore:~$ git clone https://github.com/SeungYong-Baek/FindMore.git /home/seungyong/FindMore/
- Django 구성
- SECRET KEY 분리 - https://wayhome25.github.io/django/2017/07/11/django-settings-secret-key/
- ALLOWED_HOSTS - IP 추가
- STATIC_ROOT - 데이터베이스 migrate 전에 주석 처리
(zipline) seungyong@findmore:~$ vi /home/seungyong/FindMore/FindMore/setting.py
- Django 데이터베이스 migrate - MySQL의 findmore 데이터베이스에 필요한 테이블 생성
- Django 관리자 생성
- STATIC_ROOT - 데이터베이스 migrate가 정상 완료 되면 다시 주석 삭제
(zipline) seungyong@findmore:~$ cd /home/seungyong/FindMore/ (zipline) seungyong@findmore:~$ python manage.py migrate (zipline) seungyong@findmore:~$ python manage.py createsuperuser (zipline) seungyong@findmore:~$ vi /home/seungyong/FindMore/FindMore/setting.py
(zipline) seungyong@findmore:~$ cd /etc/nginx/sites-enabled/ (zipline) seungyong@findmore:~/sites-enabled$ sudo rm default (zipline) seungyong@findmore:~$ cd /etc/nginx/sites-available/ (zipline) seungyong@findmore:~/sites-avaiable$ sudo mv default default.org (zipline) seungyong@findmore:~$ sudo ln -s /home/seungyong/FindMore/FindMore/findmore_nginx.conf /etc/nginx/sites-enabled (zipline) seungyong@findmore:~$ cp /etc/nginx/uwsgi_params /home/seungyong/FindMore/FindMore/
- 수동 실행
(zipline) seungyong@findmore:~$ sudo systemctl restart nginx (zipline) seungyong@findmore:~$ source /home/seungyong/zipline/bin/activate (zipline) seungyong@findmore:~$ nohup uwsgi --ini /home/seungyong/FindMore/FindMore/findmore_uwsgi.ini &
- 스크립트 실행
(zipline) seungyong@findmore:~$ cd /home/seungyong/FindMore/console (zipline) seungyong@findmore:~$ ./findmore.nohup
- 웹 브라우저 접속 테스트 - http://xxx.xxxx.xxx.xxxx
- 서비스 실행 확인
(zipline) seungyong@findmore:~$ sudo systemctl status nginx (zipline) seungyong@findmore:~$ ps -ef | grep uwsgi