搭建BBS博客系统

  • Nginx + Django
  • Django + MySQL

一:搭建BBS项目

1.部署数据库
[root@db01 ~]# yum install mariadb* -y
2.启动数据库
[root@db01 ~]# systemctl start mariadb
3.进入数据库
mysql
4.远程连接MySQL数据
(创建数据库用户)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
  • Query OK, 0 rows affected (0.00 sec)
刷新权限
MariaDB [(none)]> FLUSH PRIVILEGES;
  • Query OK, 0 rows affected (0.00 sec)
创建数据库(bbs)
MariaDB [(none)]> CREATE DATABASE `bbs` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  • Query OK, 1 row affected (0.00 sec)
5.pycham连接Mysql

image

二:开始部署BBS

1.上传代码

image

解压
[root@db01 ~]# unzip bbs.zip
移动
[root@db01 ~]# mv bbs /opt/
2.数据库迁移
切换路径
cd /opt
数据库迁移
[root@web01 opt]# cd /opt/bbs/app01/migrations/
[root@web01 migrations]# pwd
/opt/bbs/app01/migrations
3.删除文件
[root@web01 migrations]# rm -rf 00*
[root@web01 migrations]# rm -rf __pycache__/

image


[root@web01 migrations]# cd /opt/bbs/
[root@web01 bbs]# pwd
/opt/bbs
4.修改Django版本
卸载原django
[root@web01 bbs]# pip3 uninstall django
重新安装django版本
[root@web01 bbs]# pip3 install django==1.11
5.安装MySQL数据库插件
[root@web01 bbs]# pip3 install pymysql
6.修改数据连接
[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'
    }
}

image

7.创建数据库迁移文件
[root@web01 bbs]# python3 manage.py makemigrations
8.数据库迁移
[root@web01 bbs]# python3 manage.py migrate
9.配置UWSGI
[root@localhost ~]# vim /opt/bbs/myweb_uwsgi.ini

image

[uwsgi]
# 端口号
socket            = :8002
# 指定项目的目录
chdir           = /opt/bbs
# wsgi文件路径
wsgi-file       = bbs/wsgi.py
# 模块wsgi路径
module          = bbs.wsgi
# 是否开启master进程
master          = true
# 工作进程的最大数目
processes       = 4
# 结束后是否清理文件
vacuum          = true
10.启动uwsig
[root@web01 bbs]# uwsgi -d --ini myweb_uwsgi.ini --uid 666
11.配置Nginx
[root@localhost ~]# vim /etc/nginx/conf.d/python.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;
    }
}
12.测试
nginx -t
13.重启
[root@web01 bbs]# systemctl restart nginx 
14.DNS域名解析
bbs.test.com  192.168.15.7
15.测试访问BBS
bbs.test.com

image

posted @ 2022-01-05 22:37  AlexEvans  阅读(198)  评论(0编辑  收藏  举报