Python运维开发(CMDB资产管理系统)——环境部署下篇

实践是知识的母亲,知识是生活的明灯。这篇文章主要讲述Python运维开发(CMDB资产管理系统)——环境部署下篇相关的知识,希望能为你提供帮助。
创建管理员用户

(web) [root@k8s-node02 myweb]# python manage.py createsuperuser --username admin --email admin@test.com

运行项目,访问后台

后台地址:
http://192.168.43.203:8001/admin/login/?next=/admin/
user: admin
password: 123456

【Python运维开发(CMDB资产管理系统)——环境部署下篇】
配置数据库为mysql
vim myweb/settings.py

注释掉:

DATABASES =
default:
ENGINE: django.db.backends.sqlite3,
NAME: BASE_DIR / db.sqlite3,



新加:
import pymysql
pymysql.install_as_MySQLdb()
DATABASES =
default:
ENGINE: django.db.backends.mysql,
NAME: myweb
USER: root,
PASSWORD: 123456,
HOST: 127.0.0.1,
PORT: 3306,
OPTIONS: charset:utf8mb4,
,

安装pymysql模块
(web) [root@k8s-node02 myweb]# pip install pymysql -i https://mirrors.aliyun.com/pypi/simple/

安装mysql服务
#下载yum源
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
#安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
#检查MySQL源是否安装成功
yum repolist enabled |grep mysql

mysql-connectors-community/x86_64 MySQL Connectors Community230
mysql-tools-community/x86_64MySQL Tools Community138
mysql57-community/x86_64MySQL 5.7 Community Server564
#安装MySQL
yum install mysql-community-server
#启动mysql服务
systemctl start mysqld
systemctl enable mysqld
#查看MySQL下root账号的默认password
grep temporary password /var/log/mysqld.log
#修改root password
alter user root@localhost identified by 123456;

创建项目数据库
mysql> create database myweb;

启动项目

会提示:You have 18 unapplied migration(s),这是因为我们重新更换了mysql数据库
需要执行命令:
python manage.py migrate



查看数据库,已经产生了新表

创建新账户登录django后台
python manage.py createsuperuser --username admin --email admin@test.com


web登录

下节继续更新 pychar安装和pycharm如何管理和调试linux中的项目
链接:  ??  https://ke.qq.com/course/4300856?tuin=d8aedf68??

    推荐阅读