Skip to content

dingonefly/watchlist

Repository files navigation

watchlist

First Flask Project

tutorial: https://tutorial.helloflask.com/hello/

部署

  1. 安装python3.8或者以上版本,安装Git
yum install python38
python3 -V

yum install git
git -v
  1. 克隆项目

mkdir -p /opt/website/logs && cd /opt/website/
git clone https://github.com/dingonefly/watchlist.git
  1. 在项目根目录创建 .env 文件,写入
cd /opt/website/watchlist
vi .env

SECRET_KEY=3d6f45a5fc12445dbac2f59c3b6cwebsitex  
DATABASE_FILE=data-prod.db
  1. 新建虚拟环境
cd /opt/website/
$ python3 -m venv env  # 创建虚拟环境
$ . env/bin/activate  # 激活虚拟环境
cd /opt/website/watchlist
(env) $ pip install -r requirements.txt  # 安装所有依赖
(env) $ flask initdb  # 初始化数据库
(env) $ flask admin  # 创建管理员账户 admin/admin123
  1. 启动项目 Development
(env) [root@website watchlist]#  flask run
 * Serving Flask app 'watchlist' (lazy loading)
 * Environment: development
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 205-802-684

或者

ln -sf /opt/website/env/bin/gunicorn /usr/bin/gunicorn(可选)

(env) [root@website watchlist]# gunicorn -b localhost:5000 -w 4 wsgi:app

Production

(env) [root@website watchlist]#

cp ./deploykit/watchlist.service /etc/systemd/system/
systemctl daemon-reload

# 启动、查看、停止、重启
systemctl start watchlist.service
systemctl status watchlist.service
systemctl stop watchlist.service
systemctl restart watchlist.service
  1. Nginx配置
yum install nginx
mv /opt/nginx/conf.d/default.conf /opt/nginx/conf.d/default.conf.bak
mv ./deploykit/nginx_watchlist.conf /opt/nginx/conf.d/
systemctl start nginx
systemctl status nginx
  1. 项目更新
$ cd watchlist
$ git pull
  1. Q&A
  • 项目放在/home/yourname目录下,部署systemd服务的时候出现一个permission deny的错误,应该是SElinu没有关闭导致的,所以建议放在/opt/website下