1、安装配置promethues和alertmanager,实现对k8s的监控,并将监控数据展示到grafana

prometheus 二进制安装
下载:https://prometheus.io/download/

tar xvf prometheus-2.11.1.linux-amd64.tar.gz 
ln -sv /usr/local/src/prometheus-2.11.1.linux-amd64 /usr/local/prometheus 
cd /usr/local/prometheus

创建prometheus启动脚本

vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/usr/local/prometheus/
ExecStart=/usr/local/prometheus/prometheus --
config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target

启动prometheus服务

systemctl daemon-reload
systemctl restart prometheus
systemctl enable prometheus

安装node exporter
收集各k8s node节点上的监控指标数据,监听端口为9100

tar xvf node_exporter-0.18.1.linux-amd64.tar.gz
ln -sv /usr/local/src/node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter

创建node exporter启动脚本

vim /etc/systemd/system/node-exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target

启动node exporter服务

systemctl daemon-reload
systemctl restart node-exporter
systemctl enable node-exporter

prometheus采集node 指标数据
配置prometheus通过node exporter采集 监控指标数据
prometheus配置文件
prometheus.yml

global:
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'promethues-node'
static_configs:
- targets: ['192.168.7.110:9100','192.168.7.111:9100']

 systemctl restart prometheus

安装grafana
调用prometheus的数据,进行更专业的可视化
rpm -hiv grafana-7.0.5-1.x86_64.rpm

配置文件

vim /etc/grafana/grafana.ini
[server]
# Protocol (http, https, socket)
protocol = http
# The ip address to bind to, empty will bind to all interfaces
http_addr = 0.0.0.0
# The http port to use
http_port = 3000

启动grafana

systemctl start grafana-server.service
systemctl enable grafana-server.service

在web界面添加prometheus数据源及模板

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。