Linux之部署BBS项目

部署数据库

[root@db01 ~]# yum install mariadb* -y

启动数据库

[root@db01 ~]# systemctl start mariadb 

远程链接MySQL数据

  用户名和密码

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;FLUSH PRIVILEGES;

  bbs

CREATE DATABASE `bbs` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

 部署BBS

  1、上传代码并解压

[root@db01 ~]# unzip bbs.zip
[root@db01 ~]# mv bbs /opt/

  2、数据库迁移

    [root@web01 migrations]# pwd
    /opt/bbs/app01/migrations
    [root@web01 migrations]# rm -rf 00*
    [root@web01 migrations]# rm -rf __pycache__/

[root@web01 migrations]# cd /opt/bbs/
[root@web01 bbs]# pwd
/opt/bbs

# 修改Django版本
[root@web01 bbs]# pip3 uninstall django
[root@web01 bbs]# pip3 install django==1.11

# 安装MySQL数据库插件
[root@web01 bbs]# pip3 install pymysql

# 修改数据连接
[root@web01 bbs]# vim bbs/settings.py
ALLOWED_HOSTS = ['*']
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'bbs',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '172.16.1.61',
        'PORT': 3306,
        'CHARSET': 'utf8'
    }
}

# 创建数据库迁移文件
[root@web01 bbs]# python3 manage.py makemigrations

# 数据库迁移
[root@web01 bbs]# python3 manage.py migrate

 

   数据迁移完之后

 

  3、配置uwsgi

[root@localhost ~]# cat /opt/bbs/myweb_uwsgi.ini 
[uwsgi]
# 端口号
socket            = :8002
# 指定项目的目录
chdir           = /opt/bbs
# wsgi文件路径
wsgi-file       = bbs/wsgi.py
# 模块wsgi路径
module          = bbs.wsgi
# 是否开启master进程
master          = true
# 工作进程的最大数目
processes       = 4
# 结束后是否清理文件
vacuum          = true

[root@web01 bbs]# uwsgi -d --ini myweb_uwsgi.ini --uid 666

   4、配置Nginx

[root@localhost ~]# cat /etc/nginx/conf.d/bbs.conf 
server {
    listen 80;
    server_name bbs.test.com;
    location / { 
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8002;
        uwsgi_read_timeout 2;
        uwsgi_param UWSGI_SCRIPT bbs.wsgi;
        uwsgi_param UWSGI_CHDIR /opt/bbs;
        index  index.html index.htm;
        client_max_body_size 35m;
    }
}
启动nginx
[root@web01 bbs]# systemctl restart nginx

  5、域名解析

测试

 

posted @ 2022-01-05 20:46  那就凑个整吧  阅读(119)  评论(0编辑  收藏  举报