Go语言开发灵活管理资源的开源CMDB
source link: https://www.fdevops.com/2022/04/16/go-cmdb-31077
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
之前开源过一个比较灵活多云的 CMDB,只有没有时间整理部署方式,最近总是有朋友问,所以本文就介绍一下,如何部署 fiy 开源CMDB。
如果你还没有了解过,这款 CMDB,欢迎看下演示站点或者之前些的文章。
Github:https://github.com/lanyulei/fiy
演示站点默认账号密码:admin / 123456
文章介绍:https://blog.51cto.com/u_11293981/2783015
下面介绍两种部署方式,脚本一键部署和前后端分离的部署方式。
脚本一键部署的话,相当于将前端编译后放入后端的静态文件存放的位置。省去了部署及维护前端的操作,简单一些。
前后端分离的部署方式,则是通过 nginx 部署前端,同时通过 nginx 的反向代理将请求代理到后端的方式,如果对 nginx 熟悉的,可以尝试这种方式。
脚本一键部署和前后端分离的部署方式,任选其一
即可。
脚本一键部署
在此感谢 @Jiang-boyang 提供的部署脚本。
部署应用程序之前,请自行部署 MySQL、ES。
git clone https://github.com/lanyulei/fiy.git
# 或者
git clone https://gitee.com/yllan/fiy
执行部署脚本
cd fiy
./build.sh install
部署脚本执行的过程中,会有需要确认的输入项目,仔细看下,很清晰的描述。
执行完成后,启动程序。
./build.sh start
# 或者
cd build
./fiy server -c=config/settings.yml
启动成功则表示安装成功了。
默认情况下启动端口为 8000
,可通过 http://ip:port
访问。
例如:http://localhost:8000 。
前后端分离部署
git clone https://github.com/lanyulei/fiy.git
# 或者
git clone https://gitee.com/yllan/fiy.git
go env -w GOPROXY=https://goproxy.cn,direct
cd fiy
go mod tidy
go build -ldflags="-s -w" -o fiy main.go
配置数据库
vim config/settings.yml
# 修改为你们自己的数据库配置。 层级:settings.database.source 。
同步基础数据
# 注意,这一步必须要数据库配置好后,才可进行后续步骤。
./fiy migrate -c config/settings.yml
./fiy server -c config/settings.yml
服务成功启动后,后端就完事了。
git clone https://github.com/lanyulei/fiy-ui.git
# 或者
git clone https://gitee.com/yllan/fiy-ui.git
cd fiy-ui
npm install # 若是慢的话,请自行下载 cnpm 尝试。
修改 env 文件,调整为当前程序的访问地址,域名或者IP+端口。
vim .env.production
# 修改 VUE_APP_BASE_API 的值为,你应用的访问地址。
npm run build:prod
mkdir -p /opt/fiy-ui
mv dist /opt/fiy-ui/
若是没有安装 nginx 请自行安装配置。
以下为我的 Nginx 配置,可根据各自实际场景进行相应的调整。
端口若冲突,请自行修改为不冲突的端口。
server {
listen 8001; # 监听端口
server_name fdevops.com:8001; # 域名可以有多个,用空格隔开
# access_log /opt/fiy-ui/logs/nginx.access.log;
# error_log /opt/fiy-ui/logs/nginx.error.log;
location / {
root /opt/fiy-ui/dist;
index index.html index.htm; #目录内的默认打开文件,如果没有匹配到index.html,则搜索index.htm,依次类推
}
#ssl配置省略
location /api {
# rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8000; #node api server 即需要代理的IP地址
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ($request_method !~* GET) {
return 403;
}
}
# 登陆
location /login {
proxy_pass http://127.0.0.1:8000; #node api server 即需要代理的IP地址
proxy_redirect off;
proxy_ignore_client_abort on;
proxy_max_temp_file_size 256m;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 32k;
proxy_temp_file_write_size 64k;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# 刷新token
location /refresh_token {
proxy_pass http://127.0.0.1:8000; #node api server 即需要代理的IP地址
proxy_set_header Host $host:$server_port;
}
# 接口地址
location /swagger {
proxy_pass http://127.0.0.1:8000; #node api server 即需要代理的IP地址
proxy_set_header Host $host:$server_port;
}
# 后端静态文件路径
location /static/uploadfile {
proxy_pass http://127.0.0.1:8000; #node api server 即需要代理的IP地址
proxy_set_header Host $host:$server_port;
}
#error_page 404 /404.html; #对错误页面404.html 做了定向配置
# redirect server error pages to the static page /50x.html
#将服务器错误页面重定向到静态页面/50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
nginx 启动成功后,则可通过 http://IP:8001
的方式访问,测试。
展示部分功能截图,更详细具体的内容,还请自行进入演示站点查看。
结合 ES 实现所有资源的统一搜索,在这里不需要关注是什么类型的资源,只需要输入关键字,即可搜索出对应关键字的数据。
根据业务划分资源数据,可清晰的看出当前业务所拥有的资源数据。
服务有那些进程及进程的一些基本信息,例如:进程重启命令、进程停止命令、进程重载命令、工作用户、启动数量等等。
所有资源的一个汇总,通过这里可以进入对应的资源列表页面。
批量导入资源
云账号添加,方便进行云资源的同步,目前支持百度云、阿里云、腾讯云。
配置云资源同步的任务。
模型管理,即通过模型及配置的模型字段,添加对应的数据。能更加灵活的让我们管理我们的资源,需要什么资源就创建对应的模型即可。
语言描述的有点苍白,可看下面的截图或者演示站点上去点击测试,更能容易理解。
通过配置模型之间的上下游关系,自动生成对应的模型关系图。
用户的增删改操作,统统记录下来,方便排查及修复误操作的数据。
本次操作的新旧数据对比
更多功能,就不一一介绍了。可自行进行演示站点体验。
本文为原创文章,未经授权禁止转载本站文章。
原文出处:兰玉磊的个人博客
原文链接:https://www.fdevops.com/2022/04/16/go-cmdb-31077
版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK