选了一款开源的CMDB轮子进行二次开发, 网上帖子也有很多, 这里仅作个人部署记录, 主要是怕遗忘。
介绍一下主要的技术栈
后端技术:
- Python3
- Django
- Django REST framework
- Elasticsearch
- uwsgi
- Nginx
- Docker
前端技术:
- Vue
- Element-ui
- Vue-Router
- Vuex
- Axios
github地址:https://github.com/open-cmdb/cmdb
第一步:先把前后端拉到本地
后端: git clone https://github.com/open-cmdb/cmdb.git
前端: git clone https://github.com/open-cmdb/cmdb-web.git
第二步: 安装需要的依赖
(一)自行安装elasticsearch
下载地址如下: https://thans.cn/mirror/elasticsearch.html , 解压后到在../bin 目录下打开cmd
运行 elasticsearch.bat 注意如果系统变量设置了JAVA_HOME 建议改个名,然后浏览器输入127.0.0.1:9200 如果看到以下打印则启动成功。
(二)自行安装mysql , 此处不作介绍
(三)安装依赖
进入cmdb目录: pip3 install -r requirements.txt
如果出现 Microsoft Visual C++ 14.0 is required 报错 , 这里提供一个下载安装即可。
https://pan.baidu.com/s/12TcFkZ6KFLhofCT-osJOSg 提取码:wkgv
如果出现mysqlclient安装失败,去 https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient 下载.whl文件
如果出现python-idap安装失败, 去 https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap 下载对应版本
(四)接下来修改3个文件
- 修改 apps/mgmt/views.py 文件,注释掉 “ from . import initialize ”这一行。
- 修改 manage.py
将 APP_NAME = BASE_DIR.rsplit("/", 1)[-1] 修改为
APP_NAME = BASE_DIR.rsplit("\\", 1)[-1] ,这是因为windows的路径\ 在python 里会变成 \。 - 修改 cmdb/settings.py 文件,修改mysql 数据库的配置信息 (你的账号密码)
(五)接着在命令窗口继续执行以下操作:请关注注释内容
- python3 manage.py makemigrations
- python3 manage.py migrate
- python3 manage.py cmdb_create_superuser #这一步创建一可以登陆的管理员用户
- #修改 apps/mgmt/views.py 文件,取消注释“ from . import initialize ”
- python3 manage.py runserver #这一步启动后端的 api 服务
坑一:在makemigrations时发现抱错 SyntaxError: Generator expression must be parenthesized
是因为python3.7和django 1.11冲突导致的, 到Python37\lib\site-packages\django\contrib\admin\widgets.py", line 152 修改源码。
把逗号去掉。
坑二:忘记建库。。
命令行链接mysql 执行语句 create database cmdb default charset utf8 collate utf8_general_ci;
坑三:千万别忘记取消注释 from . import initialize 别问我怎么知道的
后端部署到这里就结束了
第三步:部署前端部分
拉好前端代码 cd cmdb-web
npm和nodejs自行安装。。
先改一下源 不然会卡的你怀疑人生 npm config set registry https://registry.npm.taobao.org
然后npm install
然后到src修改你需要修改的内容
npm build重新生成dist
第四步:前后端打通
自行安装nginx。 添加一个server
server {
listen 8080;
server_name localhost;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
root E:\GitHub\cmdb-web\dist;
index index.html;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
location ~ /api{
proxy_pass http://127.0.0.1:8000; # 你的后端地址
}
}
最后就可以通过127.0.0.1:8080访问啦
参考链接:https://www.cnblogs.com/lice-blog/p/11656488.html#WnEdYkwF