prometheus docker部署安装

发布时间 2023-11-03 17:36:32作者: liwenchao1995

prometheus prometheus docker部署安装

之前用docker-compose部署过一套自动注册的prometheus,也用k8s的operator部署过一套,详情见promethues栏的文档。
时隔许久,今天在自己虚拟机部署一套promethues玩玩

准备工作

准备三台虚拟机,规格均为 1C 2G 20G,因为是自己玩,所以对性能啥的不要求了。
192.168.40.131 prometheus
192.168.40.132 node-exporter
192.168.40.133 grafana

安装promethues

之前安装prometheus,都是百度文档安装或者自己写dockerfile打镜像。这次安装尽量就别到处搜了,直接看官网。
题外话,官网的文档永远都是最正规的。你宁肯不相信官方也要相信一个不认识的人乱说吗?对吧

prometheus安装官网地址: https://prometheus.io/docs/prometheus/latest/installation/

但是官网提供的有一些瑕疵个人感觉,所以对命令做了些调整

#文件夹创建及授权
mkdir -p /usr/local/prometheus/;chmod 777 -R /usr/local/prometheus
#创建并挂载暴露端口
docker run  -itd --name prometheus  -p 9090:9090  -v /etc/localtime:/etc/localtime:ro     -v /usr/local/prometheus/conf:/etc/prometheus  -v /usr/local/prometheus/data:/prometheus prom/prometheus

运行后应该是报错退出的状态,因为在conf下面没有配置文件,我们可以在官网找一个最基础的配置拷贝到本地的 /usr/local/prometheus/conf 下面并给可读权限

安装node-exporter

同样去看官网吧,官网地址:
https://prometheus.io/docs/instrumenting/exporters/

这里提供了各种各样的exporter,可以根据自己需求点击跳转到github。根据Readme安装,我这也做了下优化

docker run -d --name node-exporter -p 9100:9100  --net="host"   --pid="host"  -v "/etc/localtime:/etc/localtime:ro"  -v "/:/host:ro,rslave"   quay.io/prometheus/node-exporter:latest   --path.rootfs=/host

启动后修改prometheus配置

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "centos-40.132"
    static_configs:
      - targets: ["192.168.40.132:9100"]
  - job_name: "prometheus"
    static_configs:
      - targets: ["127.0.0.1:9090"]

别忘了重启prometheus

安装grafana

官网地址: https://grafana.com/docs/grafana/latest/

配置

最后配置部分是在grafana页面配置的,比较简单这里不再罗列
grafana在官网也提供了各式各样的dashboard共别人选择
官网地址: https://grafana.com/grafana/dashboards/?plcmt=footer
在页面import张贴id号即可引入