Linux Django项目部署

时间:2022-12-21 00:12:41

步骤

1.数据库的处理
1.1 上传bbs.sql 
1.2 在mysql中创建bbs库,并导入数据库SQL脚本
mysql> create database bbs charset utf8mb4;
mysql> use bbs
mysql> source /opt/bbs.sql
mysql> drop database bbs;


1.3 查看项目settings.py配置文件,修改以下两处

ALLOWED_HOSTS = ['*']

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'bbs',
        'HOST': "10.0.0.100",
        'USER': 'root',
        'PASSWORD': '123',
        'PORT': 3306,
    }


MySQL用户的定义

USERNAME@'白名单'

白名单: 主机域IP地址

root@'localhost'
root@'10.0.0.110'
root@'10.0.0.%'
root@'10.0.0.0/255.255.240.0'
root@'10.0.0.5%'
root@'%'
    
grant all     
grant select,update,insert
root:数据库DBA
wd开发人员:grant select,insert,update,delete on day1130.* to wd@'10.0.0.%' identified by '1';

    

解压django项目,cd进到settings.py    
vim 编辑    
ALLOWED_HOSTS = ["*"]#改
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'bbs',
        'HOST': "10.0.0.100", #改
        'USER': 'bbs',        #改
        'PASSWORD': '123',    #改
        'PORT': 3306,
    }
}
    



2. BBS项目部署

2.1 配置Nginx
[root@web01 BBS]# vim /etc/nginx/conf.d/py.conf
server {
listen 80;
server_name 10.0.0.100;
client_max_body_size 100M;

location  /static {
alias /opt/BBS/static/;
}

location /media {
alias /opt/BBS/media;
}

location / {
index index.html;
include uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
uwsgi_param UWSGI_SCRIPT BBS.wsgi;
uwsgi_param UWSGI_CHDIR /opt/BBS;
}
}

2.2 配置uwsgi
关闭所有已有的uwsgi进程
kill -9 `ps -ef |grep uwsgi|awk {'print $2'}`

[root@web01 BBS]# vim  uwsgi.ini
[uwsgi]
socket = 127.0.0.1:9090
master = true
workers = 2
reload-mercy = 10
vacuum = true
max-requests = 1000
limit-as = 512
buffer-size = 30000

#启动uwsgi
uwsgi --ini uwsgi.ini &

重启nginx
systemctl restart nginx

==================