Skip to content
SeungYong Baek edited this page Jun 21, 2021 · 20 revisions

FindMore 구성 방법

  • 구성 검증은 하였으나 환경에 따라 오류가 있을 수 있음
  • 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 버전 유지

1. 가상 머신 구성

  • 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 노트북등

2. 필요 패키지 설치

seungyong@findmore:~$ sudo apt update
seungyong@findmore:~$ sudo apt upgrade
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

3. Zipline 가상 환경 구성

  • 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
#    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)
    )

4. NGINX, uWSGI, Django, MySQL 설치

(zipline) seungyong@findmore:~$ sudo apt install nginx mysql-server libssl-dev libmysqlclient-dev
(zipline) seungyong@findmore:~$ pip install uwsgi Django mysqlclient

5. MySQL 데이터베이스 기본 구성

(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 ;

6. 소스 코드 다운로드 및 Django 구성

  • 소스 코드 다운로드
(zipline) seungyong@findmore:~$ git clone https://github.com/SeungYong-Baek/FindMore.git /home/seungyong/FindMore/
(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

7. Nginx 및 uWSGI 구성

(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/

8. NGINX, uwsgi 실행

  • 수동 실행
(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

9. 서비스 실행 상태 확인

(zipline) seungyong@findmore:~$ sudo systemctl status nginx 
(zipline) seungyong@findmore:~$ ps -ef | grep uwsgi