服务器集群可视化监控-Prometheus+Grafana

监控软件 Prometheus

官网:https://prometheus.io/

监控:monitor 监视我们的服务器或者服务,一旦出现问题,要告诉我们(告警),运维人员及时去处理,将公司的损失减少到最小

监控软件:

1.cacti 仙人掌: 出图比较好
2.nagios 监控脚本特别多
3.zabbix 集合cacti+nagios的优点: --》企业里使用非常多
4.openfalcon 小米公司开源的监控软件: 京东,滴滴,小米,字节等
5.prometheus :开源的监控软件

普罗米修斯的主要特点是:

  • 具有由指标名称和键/值对标识的时间序列数据的多维数据模型
  • PromQL,一种灵活的查询语言 来利用这个维度
  • 不依赖分布式存储;单个服务器节点是自治的
  • 时间序列收集通过 HTTP 上的拉模型进行
  • 通过中间网关支持推送时间序列
  • 通过服务发现或静态配置发现目标
  • 多种图形和仪表板支持模式

Prometheus的架构及组件

在这里插入图片描述

组件:
1.tsdb time series database 时序数据库 --》hdd/ssd hdd机械磁盘 hard disk drive ssd固态磁盘 -->solid state drive
promQL : select ,insert等
2.http server web服务
3.pushgateway 中间件(代理)
4.alertmanager 告警的软件
5.exporter 收集数据,采集数据 木马程序 : 安装到被监控的机器上

采集数据:exporter pushgateway 中间件(代理)
存储数据:tsdb
提供数据:http server
显示数据: grafana
告警、报警:alertmanager


Prometheus搭建

第1步:安装prometheus server

源码安装
1.上传下载的源码包到linux服务器

[root@sc-prom ~]# mkdir /prom
[root@sc-prom ~]# cd /prom
[root@sc-prom prom]# ls
prometheus-2.34.0.linux-amd64.tar.gz
[root@sc-prom prom]#

2.解压源码包

[root@sc-prom prom]# tar xf prometheus-2.34.0.linux-amd64.tar.gz
[root@sc-prom prom]# ls
prometheus-2.34.0.linux-amd64  prometheus-2.34.0.linux-amd64.tar.gz
[root@sc-prom prom]#

3.修改解压后的压缩包名字

[root@sc-prom prom]# mv prometheus-2.34.0.linux-amd64 prometheus
[root@sc-prom prom]# ls
prometheus  prometheus-2.34.0.linux-amd64.tar.gz
[root@sc-prom prom]#

4.临时和永久修改PATH变量,添加prometheus的路径

[root@sc-prom prometheus]# PATH=/prom/prometheus:$PATH
[root@sc-prom prometheus]# cat /root/.bashrc

.bashrc

User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

Source global definitions

if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
PATH=/prom/prometheus:$PATH   #添加

5.执行prometheus程序

[root@prometheus prometheus]# nohup prometheus  --config.file=/prom/prometheus/prometheus.yml &
[1] 8431
[root@prometheus prometheus]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@prometheus prometheus]# 

6.查看prometheus的进程

[root@prometheus prometheus]# ps aux|grep prome  
root       8431  4.5  2.4 782084 46204 pts/0    Sl   11:21   0:00 prometheus --config.file=/prom/prometheus/prometheus.yml
root       8439  0.0  0.0 112824   980 pts/0    S+   11:21   0:00 grep --color=auto prome
[root@prometheus prometheus]# 

7.查看prometheus监听的端口号

[root@prometheus prometheus]# netstat -anplut|grep prome
tcp6       0      0 :::9090                 :::*                    LISTEN      8431/prometheus     
tcp6       0      0 ::1:9090                ::1:51738               ESTABLISHED 8431/prometheus     
tcp6       0      0 ::1:51738               ::1:9090                ESTABLISHED 8431/prometheus     
[root@prometheus prometheus]# 

8.关闭服务器上的firewalld服务

[root@prometheus prometheus]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@prometheus prometheus]# systemctl disable firewalld 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@prometheus prometheus]# 

9.把prometheus做成一个服务来进行管理,非常方便

[root@prometheus prometheus]# vim /usr/lib/systemd/system/prometheus.service 
[Unit]
Description=prometheus
[Service]
ExecStart=/prom/prometheus/prometheus --config.file=/prom/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@prometheus prometheus]# systemctl daemon-reload 重新加载systemd相关的服务

[root@prometheus prometheus]# 

第一次因为是使用nohup 方式启动的prometheus,还是需要使用后kill 的方式杀死第一次启动的进程
后面可以使用service方式管理prometheus了

[root@prometheus prometheus]#  service prometheus stop
Redirecting to /bin/systemctl stop prometheus.service
[root@prometheus prometheus]# ps aux|grep prome
root       8431  0.2  3.2 782340 61472 pts/0    Sl   11:21   0:01 prometheus --config.file=/prom/prometheus/prometheus.yml
root       8650  0.0  0.0 112824   980 pts/0    S+   11:35   0:00 grep --color=auto prome
[root@prometheus prometheus]# kill -9 8431
[root@prometheus prometheus]# ps aux|grep prome
root       8652  0.0  0.0 112824   976 pts/0    R+   11:35   0:00 grep --color=auto prome
[1]+  已杀死               nohup prometheus --config.file=/prom/prometheus/prometheus.yml
[root@prometheus prometheus]# 


[root@prometheus prometheus]#  service prometheus start
Redirecting to /bin/systemctl start prometheus.service
[root@prometheus prometheus]# ps aux|grep prome
root       8671 14.0  2.4 782084 45764 ?        Ssl  11:35   0:00 /prom/prometheus/prometheus --config.file=/prom/prometheus/prometheus.yml
root       8679  0.0  0.0 112824   980 pts/0    S+   11:35   0:00 grep --color=auto prome
[root@prometheus prometheus]#  service prometheus stop
Redirecting to /bin/systemctl stop prometheus.service

[root@prometheus prometheus]# 
[root@prometheus prometheus]# ps aux|grep prome
root       8698  0.0  0.0 112824   976 pts/0    S+   11:35   0:00 grep --color=auto prome
[root@prometheus prometheus]#

第2步:在node节点服务器上安装exporter程序

1.下载node_exporter-1.4.0-rc.0.linux-amd64.tar.gz源码,上传到节点服务器上
2.解压

[root@node-liangrui ~]# ls
anaconda-ks.cfg  name_ip.txt                                  sanchuang1290
feng.txt         node_exporter-1.4.0-rc.0.linux-amd64.tar.gz  sanchuang1965
input.sh         onekey_install_changjinghu.sh                sanchuang{random.randint(1,10000)}
liang            sanchuang
[root@node-liangrui ~]# tar xf node_exporter-1.4.0-rc.0.linux-amd64.tar.gz
[root@node-liangrui ~]# ls
anaconda-ks.cfg  name_ip.txt                                  sanchuang
feng.txt         node_exporter-1.4.0-rc.0.linux-amd64         sanchuang1290
input.sh         node_exporter-1.4.0-rc.0.linux-amd64.tar.gz  sanchuang1965
liang            onekey_install_changjinghu.sh                sanchuang{random.randint(1,10000)}

3.单独存放到/node_exporter文件夹

[root@node-liangrui ~]# mv node_exporter-1.4.0-rc.0.linux-amd64 /node_exporter
[root@node-liangrui ~]#
[root@node-liangrui ~]# cd /node_exporter/
[root@node-liangrui node_exporter]# ls
LICENSE  node_exporter  NOTICE
[root@node-liangrui node_exporter]#

4.修改PATH变量

[root@node-liangrui node_exporter]# PATH=/node_exporter/:$PATH
[root@node-liangrui node_exporter]# vim /root/.bashrc
PATH=/node_exporter/:$PATH #添加

5.执行node exporter 代理程序agent

[root@node-liangrui node_exporter]#nohup node_exporter --web.listen-address 0.0.0.0:8090  &

6.具体的端口号,可以自己定义,只要不和其他的服务冲突就可以

[root@node-liangrui node_exporter]# ps aux|grep node
root      24958  0.6  0.6 716288  6476 pts/0    Sl+  11:45   0:00 node_exporter --web.listen-address 0.0.0.0:8090
root      24981  0.0  0.0 112824   988 pts/1    R+   11:46   0:00 grep --color=auto node
[root@node-liangrui node_exporter]# netstat -anplult|grep 8090
tcp6       0      0 :::8090                 :::*                    LISTEN      24958/node_exporter
[root@node-liangrui node_exporter]#

7.访问node节点上的metrics
http://192.168.1.194:8090/metrics
在这里插入图片描述

第3步: 在prometheus server里添加我们在哪些机器里安装了exporter程序,这样就可以知道去哪里pull数据

1.在prometheus服务器上添加抓取数据的配置,添加node节点服务器,将抓取的数据存储到时序数据库里

[root@sc-prom prometheus]# vim prometheus.yml

scrape_configs:

The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  - job_name: "prometheus"
    static_configs:

      - targets: ["localhost:9090"]

    添加下面的配置采集node-liangrui服务器的metrics

  - job_name: "node-liangrui"
    static_configs:

      - targets: ["192.168.1.194:8090"]

  - job_name: "LB1"
    static_configs:

      - targets: ["192.168.227.144:8090"]

  - job_name: "LB2"
    static_configs:

      - targets: ["192.168.227.148:8090"]

2.重启prometheus服务

[root@prometheus prometheus]# service  prometheus restart
Redirecting to /bin/systemctl restart prometheus.service
[root@prometheus prometheus]# 

3.登录prometheus查看是否添加targets成功
http://192.168.1.137:9090/targets
在这里插入图片描述


Grafana:

1.概述–美观、强大的可视化监控指标展示工具
Grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具,目前已经支持绝大部分常用的时序数据库。最好的参考资料就是官网(http://docs.grafana.org/)

Grafana 和Prometheus server安装在一台服务器上

安装部署

1.先去官方网站下载

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.5-1.x86_64.rpm

2.安装

[root@sc-prom grafana]# ls
grafana-enterprise-8.4.5-1.x86_64.rpm
[root@sc-prom grafana]# yum install grafana-enterprise-8.4.5-1.x86_64.rpm -y

3.启动grafana

[root@sc-prom grafana]# service grafana-server start
Starting grafana-server (via systemctl):                   [  确定  ]
[root@sc-prom grafana]#

4.设置grafana开机启动

[root@prometheus grafana]# systemctl enable grafana-server  
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.
[root@prometheus grafana]# 

5.监听的端口号是3000

[root@sc-prom grafana]# netstat -anplut|grep grafana
tcp        0      0 192.168.1.137:52062     34.120.177.193:443      ESTABLISHED 5413/grafana-server
tcp6       0      0 :::3000                 :::*                    LISTEN      5413/grafana-server
[root@sc-prom grafana]#

6.登录,在浏览器里登录
http://192.168.1.137:3000/
默认的用户名和密码是
用户名admin
密码admin
在这里插入图片描述


1.先配置prometheus的数据源

在这里插入图片描述

2.导入grafana的模板
https://grafana.com/grafana/dashboards
步骤:
1.需要知道哪些模板可以使用,可以去官方找,也可以百度
1-node-exporter-for-prometheus-dashboard-cn-v20200628_rev1.json
2.导入模板

创建文件夹,存放模板 sanchuang
这2个模板非常好用,推荐使用
1860
8919

在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Grafana是一个用于监控可视化数据的开源工具,而Kubernetes(K8s)是一个用于容器编排和管理的开源平台。当在Grafana监控K8s时遇到"坏网关"(Bad Gateway)错误,意味着Grafana无法正常连接到K8s集群或者中间代理出现了问题。 出现"坏网关"错误可能是由以下几个原因引起的: 1. 网络问题:首先需要确保在Grafana所在的环境中,能够正常访问K8s集群的网络。检查网络连接是否正常,并通过ping或telnet命令测试Grafana是否能够与K8s集群通信。 2. 授权设置:检查Grafana连接K8s集群的配置是否正确。确保在Grafana中正确配置了正确的K8s API服务器地址、证书和凭据。如果错误,可能导致Grafana无法连接到K8s API服务器,从而触发"坏网关"错误。 3. 代理问题:如果在Grafana与K8s集群之间有中间代理服务器,可能是代理服务器出现了问题。请检查代理服务器的配置是否正确,并确保代理服务器与K8s集群的连接正常。 4. K8s API服务器问题:检查K8s集群中的API服务器是否正常运行。尝试通过其他方式访问K8s API服务器,例如使用kubectl命令行工具。如果无法连接,可能需要检查K8s集群配置或者API服务器是否正常运行。 总而言之,当在Grafana监控K8s时遇到"坏网关"错误,需要检查网络连接、授权设置、代理配置以及K8s API服务器是否正常运行等多个方面。通过逐一排除这些问题,可以解决"坏网关"错误并使Grafana成功监控K8s集群

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值