1、安装服务器

准备一台centos7服务器
安装官方文档:https://prometheus.io/docs/prometheus/latest/installation/
使用docker方式安装
先装新版docker

  1. sudo yum install -y yum-utils
  2. sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  3. sudo yum install -y docker-ce
  4. sudo systemctl start docker
  5. sudo systemctl enable docker

准备/etc/prometheus/prometheus.yml
这是一个最简单的配置:监控prometheus自身(https://prometheus.io/docs/prometheus/latest/getting_started/

  1. [root@centos7 etc]# cat /etc/prometheus/prometheus.yml
  2. global:
  3. scrape_interval: 15s # By default, scrape targets every 15 seconds.
  4. # Attach these labels to any time series or alerts when communicating with
  5. # external systems (federation, remote storage, Alertmanager).
  6. external_labels:
  7. monitor: 'codelab-monitor'
  8. # A scrape configuration containing exactly one endpoint to scrape:
  9. # Here it's Prometheus itself.
  10. scrape_configs:
  11. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  12. - job_name: 'prometheus'
  13. # Override the global default and scrape targets from this job every 5 seconds.
  14. scrape_interval: 5s
  15. static_configs:
  16. - targets: ['localhost:9090']

运行promtheus server
注:可以换成私有仓库地址,如192.168.37.100/devops-release-docker/prom/prometheus

  1. docker run -d \
  2. -p 9090:9090 \
  3. --name prometheus \
  4. -v /etc/prometheus:/etc/prometheus \
  5. -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
  6. prom/prometheus

测试
docker ps 查看容器运行情况
在浏览器访问 http://ip:9090/targets

2、安装主机常用资源监控

就是安装node_exporter
https://github.com/prometheus/node_exporter
注,可以换成私有仓库地址:192.168.37.100/devops-release-docker/prom/node-exporter

  1. docker run -d \
  2. --net="host" \
  3. --pid="host" \
  4. -v "/:/host:ro,rslave" \
  5. quay.io/prometheus/node-exporter \
  6. --path.rootfs=/host

修改server配置,增加监控项目

3、设置告警规则

4、设置告警

4.1、邮件通知

4.2、设置告警微信通知

4.3、设置告警钉钉通知

5、安装grafna图形

监控ceph

监控k8s集群