Linux - pythonav

1、安装python基础环境

[root@nginx ~]# yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel python3 python3-devel

2、安装Django框架、uwsgi

[root@nginx ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip

[root@nginx ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ django==2.1.8

[root@nginx ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ uwsgi

3、下载pythonav项目包,安装项目所需要的依赖包

[root@nginx ~]# unzip pythonav.zip -d /opt/

## 需要下载的依赖在项目目录下的requirements.txt文件中记录
[root@nginx ~]# cat /opt/pythonav/requirements.txt 
certifi==2018.11.29
chardet==3.0.4
Django==1.11
idna==2.8
Pillow==5.4.1
PyMySQL==0.9.3
pytz==2018.9
requests==2.21.0
urllib3==1.24.1

## 直接使用此文件下载
[root@nginx ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -r /opt/pythonav/requirements.txt

4、通过uwsgi的方式运行项目

[root@nginx ~]# uwsgi --ini /opt/pythonav/pythonav_uwsgi.ini 
[uWSGI] getting INI configuration from /opt/pythonav/pythonav_uwsgi.ini

[root@nginx ~]# netstat -lntp | grep 8811
tcp        0      0 127.0.0.1:8811          0.0.0.0:*               LISTEN      2838/uwsgi

5、修改配置nginx

[root@nginx ~]# vim /etc/nginx/conf.d/test.conf
server {
  listen 80;
  server_name www.test.org;
    client_max_body_size 100M;
  location / {
    uwsgi_pass 127.0.0.1:8811;
    include uwsgi_params;
  }
}

## 重新加载
[root@nginx ~]# systemctl reload nginx

6、修改配置、连接数据库

[root@nginx ~]# vim /opt/pythonav/pythonav/settings.py
# ################### MySQL ###################
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pythonav',
        'USER': 'test',
        'PASSWORD': '111111',
        'HOST': '192.168.200.127',
        'PORT': '3306',
    }
}

7、创建数据库远程用户、库

MariaDB [(none)]> grant all on *.* to test@'192.168.200.%' identified by '111111';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> create database pythonav;
Query OK, 1 row affected (0.00 sec)

8、初始化数据库

[root@nginx pythonav]# python3 manage.py makemigrations
Migrations for 'rbac':
  rbac/migrations/0001_initial.py
    - Create model Menu
    - Create model Permission
    - Create model Role
Migrations for 'web':
  web/migrations/0001_initial.py
    - Create model Admin
    - Create model Book
    - Create model Chapter
    - Create model Index
    - Create model Module
    - Create model Question
    - Create model Recommend
    - Create model Teacher
    - Create model TextBook
    - Create model UserAnswer
    - Create model UserInfo
    - Create model Video
    - Add field user to useranswer


[root@nginx pythonav]# python3 manage.py migrate
System check identified some issues:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
	HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, rbac, sessions, web
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying rbac.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying web.0001_initial... OK

9、将项目中的静态资源存储到指定位置中

[root@nginx pythonav]# python3 manage.py collectstatic

10、重修nginx配置、重新加载

[root@nginx pythonav]# vim /etc/nginx/conf.d/test.conf 
server {
  listen 80;
  server_name www.test.org;
    client_max_body_size 100M;
  location / {
    uwsgi_pass 127.0.0.1:8811;
    include uwsgi_params;
  }
  location /static {
    alias /opt/pythonav/static;
  }
}


[root@nginx pythonav]# systemctl reload nginx.service 

11、重启uwsgi

[root@nginx pythonav]# kill $(ps -ef | grep uwsgi | grep -v grep | awk '{print $2}')

[root@nginx pythonav]# uwsgi --ini /opt/pythonav/pythonav_uwsgi.ini 
[uWSGI] getting INI configuration from /opt/pythonav/pythonav_uwsgi.ini

[root@nginx pythonav]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:8811          0.0.0.0:*               LISTEN      3228/uwsgi    

12、浏览器访问

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦有一把琐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值