Skip to content

Commit 4967ae6

Browse files
author
杨红飞
committed
[Update]基于Tornado重构了CMDB,为Beta0.3做准备
1 parent dd27b13 commit 4967ae6

File tree

365 files changed

+6571
-35764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

365 files changed

+6571
-35764
lines changed

BaseDockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM cloudopendevops/codo_base:latest
2+
# 已经装好的Python3镜像,可以docker pull cloudopendevops/codo_base,在国外有点慢
3+
# 设置编码
4+
#ENV LANG en_US.UTF-8
5+
# 同步时间
6+
#ENV TZ=Asia/Shanghai
7+
#RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
8+
9+
## 1. 安装基本依赖
10+
#RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget unzip epel-release nginx xz gcc automake zlib-devel openssl-devel supervisor groupinstall development libxslt-devel libxml2-devel libcurl-devel git -y
11+
##WORKDIR /var/www/
12+
13+
## 2. 准备python
14+
#RUN wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
15+
#RUN xz -d Python-3.6.6.tar.xz && tar xvf Python-3.6.6.tar && cd Python-3.6.6 && ./configure && make && make install
16+
17+
# 3. 安装websdk
18+
RUN pip3 install --upgrade pip
19+
RUN pip3 install -U git+https://github.com/ss1917/ops_sdk.git
20+
# 4. 复制代码
21+
RUN mkdir -p /var/www/
22+
ADD . /var/www/codo-cmdb/
23+
24+
# 5. 安装pip依赖
25+
RUN pip3 install -r /var/www/codo-cmdb/doc/requirements.txt
26+
27+
# 6. 日志
28+
VOLUME /var/log/
29+
30+
# 7. 准备文件
31+
COPY doc/nginx_ops.conf /etc/nginx/conf.d/default.conf
32+
COPY doc/supervisor_ops.conf /etc/supervisord.conf
33+
34+
EXPOSE 80
35+
CMD ["/usr/bin/supervisord"]

Dockerfile

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
FROM centos:7
2-
# 设置编码
3-
ENV LANG en_US.UTF-8
4-
5-
# 同步时间
6-
ENV TZ=Asia/Shanghai
7-
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
8-
9-
# 1. 安装基本依赖
10-
RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget unzip epel-release nginx xz gcc automake zlib-devel openssl-devel supervisor net-tools mariadb-devel groupinstall development libxslt-devel libxml2-devel libcurl-devel git -y
11-
12-
# 2. 准备python
13-
RUN wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
14-
RUN xz -d Python-3.6.6.tar.xz && tar xvf Python-3.6.6.tar && cd Python-3.6.6 && ./configure && make && make install
15-
16-
# 3. 复制代码
17-
ADD . /var/www/CMDB/
18-
WORKDIR /var/www/CMDB/
19-
20-
# 4. 安装pip依赖
21-
RUN pip3 install --user --upgrade pip
22-
RUN pip3 install -r requirements.txt
23-
24-
# 5. 数据初始化
25-
# RUN python3 /var/www/CMDB/manage.py makemigrations
26-
# RUN python3 /var/www/CMDB/manage.py migrate
27-
28-
# 6. 日志
29-
VOLUME /var/log/
30-
31-
# 7. 准备文件
32-
COPY cmdb-example.conf cmdb.conf
33-
COPY docs/supervisor_cmdb.conf /etc/supervisord.conf
34-
COPY docs/nginx_cmdb.conf /etc/nginx/conf.d/
35-
36-
EXPOSE 80
37-
CMD ["/usr/bin/supervisord"]
38-
39-
##### build测试
40-
# docker build -t cmdb .
1+
FROM centos:7
2+
# 设置编码
3+
ENV LANG en_US.UTF-8
4+
# 同步时间
5+
ENV TZ=Asia/Shanghai
6+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
7+
8+
# 1. 安装基本依赖
9+
RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget unzip epel-release nginx xz gcc automake zlib-devel openssl-devel supervisor groupinstall development libxslt-devel libxml2-devel libcurl-devel git -y
10+
#WORKDIR /var/www/
11+
12+
# 2. 准备python
13+
RUN wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
14+
RUN xz -d Python-3.6.6.tar.xz && tar xvf Python-3.6.6.tar && cd Python-3.6.6 && ./configure && make && make install
15+
16+
# 3. 安装websdk
17+
RUN pip3 install --upgrade pip
18+
RUN pip3 install -U git+https://github.com/ss1917/ops_sdk.git
19+
# 4. 复制代码
20+
RUN mkdir -p /var/www/
21+
ADD . /var/www/codo-cmdb/
22+
23+
# 5. 安装pip依赖
24+
RUN pip3 install -r /var/www/codo-cmdb/doc/requirements.txt
25+
26+
# 6. 日志
27+
VOLUME /var/log/
28+
29+
# 7. 准备文件
30+
COPY doc/nginx_ops.conf /etc/nginx/conf.d/default.conf
31+
COPY doc/supervisor_ops.conf /etc/supervisord.conf
32+
33+
EXPOSE 80
34+
CMD ["/usr/bin/supervisord"]

Jenkinsfile

Lines changed: 0 additions & 32 deletions
This file was deleted.

README.md

Lines changed: 82 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,108 @@
1-
## CMDB 介绍
1+
### 资产管理
22

3-
- 资产录入,查询,管理
4-
- 资产信息自动搜集
5-
- Web Terminal登录
6-
- 操作审计,录像回放
73

8-
## 组件栈
9-
- python3.7
10-
- Tornado4.5
11-
- DRF3.9
12-
- MYSQL
4+
**前言**
5+
> 简单说明下,Beta0.3版本CMDB进行了重构,后端使用Tornado ,老版Django资产管理代码没有删除,在Tag里面,后续CMDB将持续更新支持跳板审计的功能
136
147

15-
## 部署
8+
**目前功能**
169

17-
#### 一 安装依赖
18-
```
19-
yum -y install $(cat rpm_requirements.txt)
20-
pip3 install --upgrade pip
21-
pip3 install -r requirements.txt
22-
```
10+
- 支持主机记录
11+
- 支持数据库记录
12+
- 支持从主机列表系统获取信息(定时、手动)
13+
- 支持从AWS/阿里云/腾讯云自动获取数据(可选、定时)
14+
- 支持主表和详情表分离,可不影响数据的情况下进行扩展
15+
- 众多功能我们一直在开发中,请耐心等待
2316

24-
#### 二 配置
25-
- 配置文件 cmdb.conf
26-
- 配置数据库信息
27-
```
28-
cp /var/www/CMDB/cmdb-example.conf /var/www/CMDB/cmdb.conf
29-
```
17+
#### 截图
18+
19+
- 放一些简单示例图片,详细的使用可参考[部署文档](http://docs.opendevops.cn/zh/latest/codo-cmdb.html)[Demo体验](https://demo.opendevops.cn/login)、视频示例
20+
21+
![](./static/images/cmdb_host_list.png)
22+
23+
![](./static/images/cmdb_server_detail.png)
24+
25+
![](./static/images/cmdb_asset_config.png)
26+
27+
#### 部署文档
28+
29+
> Docker部署方式
30+
31+
**创建数据库**
3032

31-
#### 三 同步数据库
3233
```
33-
mysql -h 127.0.0.1 -u root -p123456 -e "create database cmdb default character set utf8mb4 collate utf8mb4_unicode_ci;"
34-
mysql -h 127.0.0.1 -u root -p123456 cmdb < docs/cmdb.sql
34+
create database `codo_cmdb` default character set utf8mb4 collate utf8mb4_unicode_ci;
3535
```
36+
**修改配置**
37+
38+
- 修改`settings.py`配置信息
39+
- 注意:需要修改的信息在`settings.py`里面已经标注
40+
- 请确保你`settings`信息里面`mysql redis`等配置信息的准确性
41+
- `docs/nginx_ops.conf`文件
42+
- 建议保持默认,毕竟都是内部通信,用什么域名都无所谓,到时候只修改前端访问的域名即可
43+
- 若你这里修改了,后面DNS、网关都要记得跟着修改为这个域名
44+
45+
46+
47+
**打包镜像**
3648

37-
#### 四 Supervisor
3849
```
39-
cat >> /etc/supervisord.conf <<EOF
40-
[program:cmdb]
41-
command=python3 startup.py --port=90%(process_num)02d
42-
process_name=%(program_name)s_%(process_num)02d
43-
numprocs=3
44-
directory=/var/www/CMDB
45-
user=root
46-
autostart=true
47-
autorestart=true
48-
redirect_stderr=true
49-
stdout_logfile=/var/log/supervisor/cmdb.log
50-
loglevel=info
51-
logfile_maxbytes=100MB
52-
logfile_backups=3
53-
EOF
54-
55-
supervisorctl update
56-
supervisorctl reload
50+
docker build . -t codo_cmdb
5751
```
5852

59-
#### 五 Nginx配置
53+
**启动Docker**
54+
55+
```
56+
docker-compose up -d
6057
```
61-
upstream cmdb{
62-
server 127.0.0.1:9000;
63-
server 127.0.0.1:9001;
64-
server 127.0.0.1:9002;
65-
}
6658

67-
location /v1/cmdb/ws/ {
68-
#proxy_set_header Host $http_host;
69-
proxy_redirect off;
70-
proxy_set_header X-Real-IP $remote_addr;
71-
proxy_set_header X-Scheme $scheme;
72-
proxy_pass http://cmdb;
73-
proxy_http_version 1.1;
74-
proxy_set_header Upgrade $http_upgrade;
75-
proxy_set_header Connection "upgrade";
76-
}
59+
**初始化表结构**
7760

78-
location /api/cmdb/ {
79-
proxy_set_header Host $http_host;
80-
proxy_redirect off;
81-
proxy_set_header X-Real-IP $remote_addr;
82-
proxy_set_header X-Scheme $scheme;
83-
proxy_pass http://cmdb;
84-
}
61+
```
62+
#若是在本地执行需要安装很多SDK包的依赖,建议进入容器执行
63+
docker exec -ti <CONTAINER ID> /bin/bash
64+
cd /var/www/codo-cmdb/
65+
python3 db_sync.py
8566
```
8667

87-
## 六 前台展示
88-
#### 主机管理
89-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/01.png)
68+
**日志文件**
69+
- 服务日志:`/var/log/supervisor/cmdb.log` #主程序日志
70+
- 定时日志:`/var/log/supervisor/cmdb_cron.log` #一些后端守护自动运行的日志
9071

91-
#### WebTerminal
92-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/04.png)
72+
**接口测试**
9373

94-
#### 授权规则
95-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/02.png)
96-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/03.png)
74+
- 可查看日志看是否有报错
75+
- 默认端口:8050,可直接测试Are you ok?
76+
```
77+
#返回200
78+
curl -I -X GET -m 10 -o /dev/null -s -w %{http_code} http://cmdb2.opendevops.cn:8050/are_you_ok/
79+
```
9780

98-
#### 登录日志
99-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/05.png)
10081

101-
#### 命令统计
102-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/06.png)
10382

104-
#### 录像回放
105-
![image](https://raw.githubusercontent.com/yangmv/SuperCMDB/master/static/images/07.png)
83+
### 服务注册
10684

85+
> 由于我们每个模板都是单独部署的,微服务需要在API网关进行注册
10786
108-
## License
87+
**示例**
10988

110-
Everything is [GPL v3.0](https://www.gnu.org/licenses/gpl-3.0.html).
89+
```
90+
rewrite_conf = {
91+
[gw_domain_name] = {
92+
rewrite_urls = {
93+
{
94+
uri = "/cmdb2",
95+
rewrite_upstream = "cmdb2.opendevops.cn:8050" #nginx配置的域名
96+
},
97+
{
98+
uri = "/mg",
99+
rewrite_upstream = "mg.opendevops.cn:8010"
100+
},
101+
{
102+
uri = "/accounts",
103+
rewrite_upstream = "mg.opendevops.cn:8010"
104+
},
105+
}
106+
}
107+
}
108+
```

apps/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.
-219 Bytes
Binary file not shown.
-222 Bytes
Binary file not shown.
-221 Bytes
Binary file not shown.
-149 Bytes
Binary file not shown.
-148 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)