本文涉及:如何在k8s下搭建Prometheus+grafana的监控环境

基本概念

Prometheus提供了容器和云原生领域数据搜集、存储、处理、可视化和告警一套完整的解决方案,最初时是由SoundCloud公司开发的。自2012年开源以来社区成员就不断递增。如今的Prometheus已经发展到继Kubernetes后第2个正式加入CNCF基金会的项目

Prometheus的特点?

  • 多维的数据模型(基于时间序列的k/v键值对)。
  • 灵活的查询及聚合语句(PromQL)。
  • 不依赖分布式存储,节点自治。
  • 基于HTTP的pull模式采集时间序列数据。
  • 可以使用pushgateway(prometheus的可选中间件)实现push模式。
  • 可以使用动态服务发现或静态配置采集的目标机器。
  • 支持多种图形及仪表盘。

Prometheus可以监控什么?

  • k8s、docker、mysql、redis、es、consul、rabbitmq、zabbix等等

Prometheus架构图

Prometheus安装部署

Helm 安装

Helm 是一个命令行下的客户端工具。主要用于 Kubernetes 应用程序 Chart 的创建、打包、发布以及创建和管理本地和远程的 Chart 仓库。

1
2
3
4
5
6
[root@syj ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.13.1-rc.2-linux-amd64.tar.gz
[root@syj ~]# tar -zxvf helm-v2.14.0-rc.2-linux-amd64.tar.gz
[root@syj ~]# cp linux-amd64/helm /usr/local/bin/
[root@syj ~]# helm version
Client: &version.Version{SemVer:"v2.13.1-rc.2", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
Error: could not find tiller
Tiller 服务器安装

Tiller 是 Helm 的服务端,部署在 Kubernetes 集群中。Tiller 用于接收 Helm 的请求,并根据 Chart 生成 Kubernetes 的部署文件( Helm 称为 Release ),然后提交给 Kubernetes 创建应用。Tiller 还提供了 Release 的升级、删除、回滚等一系列功能。

创建rbac-config.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system

启动

1
2
3
[root@syj ~]# kubectl apply -f rbac-config.yaml 
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created

使用阿里云镜像进行安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@syj ~]# helm init --service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.13.1 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
Happy Helming!

查看结果

1
2
3
4
5
6
7
[root@syj ~]# helm version
Client: &version.Version{SemVer:"v2.13.1", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.13.1", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
[root@syj ~]# helm repo list
NAME URL
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
local http://127.0.0.1:8879/charts
部署 Prometheus Operator

创建命名空间

1
[root@syj ~]# kubectl create namespace monitoring

下载Prometheus Operator

1
[root@syj ~]# wget https://github.com/coreos/prometheus-operator/archive/release-0.29.zip

将下载下来的依赖包解压并重命名为prometheus-operator并cd到此目录
安装prometheus相关内容

1
2
3
helm install --name prometheus-operator --set rbacEnable=true --namespace=monitoring helm/prometheus-operator
helm install --name prometheus --set serviceMonitorsSelector.app=prometheus --set ruleSelector.app=prometheus --namespace=monitoring helm/prometheus
helm install --name alertmanager --namespace=monitoring helm/alertmanager

验证

1
2
3
4
5
6
7
8
9
10
11
[root@syj ~]# kubectl get pod -n monitoring
NAME READY STATUS RESTARTS AGE
alertmanager-alertmanager-0 2/2 Running 0 58s
prometheus-operator-545b59ffc9-6g7dg 1/1 Running 0 6m32s
prometheus-prometheus-0 3/3 Running 1 3m31s
[root@syj ~]# kubectl get svc -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager ClusterIP 10.98.237.7 <none> 9093/TCP 87s
alertmanager-operated ClusterIP None <none> 9093/TCP,6783/TCP 87s
prometheus ClusterIP 10.104.185.104 <none> 9090/TCP 4m
prometheus-operated ClusterIP None <none> 9090/TCP 4m

安装 kube-prometheus

1
2
3
4
[root@syj ~]# mkdir -p helm/kube-prometheus/charts
[root@syj ~]# helm package -d helm/kube-prometheus/charts helm/alertmanager helm/grafana helm/prometheus helm/exporter-kube-dns \
> helm/exporter-kube-scheduler helm/exporter-kubelets helm/exporter-node helm/exporter-kube-controller-manager \
> helm/exporter-kube-etcd helm/exporter-kube-state helm/exporter-coredns helm/exporter-kubernetes

验证

1
2
3
4
5
6
7
8
9
10
11
[root@syj ~]# kubectl get svc -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager ClusterIP 10.98.237.7 <none> 9093/TCP 34m
alertmanager-operated ClusterIP None <none> 9093/TCP,6783/TCP 34m
kube-prometheus ClusterIP 10.101.249.82 <none> 9090/TCP 29s
kube-prometheus-alertmanager ClusterIP 10.100.29.63 <none> 9093/TCP 29s
kube-prometheus-exporter-kube-state ClusterIP 10.98.91.146 <none> 80/TCP 29s
kube-prometheus-exporter-node ClusterIP 10.98.34.11 <none> 9100/TCP 29s
kube-prometheus-grafana ClusterIP 10.108.208.247 <none> 80/TCP 29s
prometheus ClusterIP 10.104.185.104 <none> 9090/TCP 36m
prometheus-operated ClusterIP None <none> 9090/TCP 36m

将grafana的Service类型改为NodePort

1
kubectl patch svc kube-prometheus-grafana -p '{"spec":{"type":"NodePort"}}' -n monitoring

此时访问grafana的默认端口31106即可:

1
http://ip:31106

安装过程参考文章:https://blog.csdn.net/wangzan18/article/details/85270816

grafana的各种模板可参考
https://grafana.com/dashboards


微服务监控神器Prometheus的安装部署的更多相关文章

  1. 第七模块 :微服务监控告警Prometheus架构和实践

    119.监控模式分类~1.mp4 logging:日志监控,Logging 的特点是,它描述一些离散的(不连续的)事件. 例如:应用通过一个滚动的文件输出 Debug 或 Error 信息,并通过日志 ...

  2. SpringCloud微服务实战——搭建企业级开发框架(四十五):【微服务监控告警实现方式二】使用Actuator(Micrometer)+Prometheus+Grafana实现完整的微服务监控

      无论是使用SpringBootAdmin还是使用Prometheus+Grafana都离不开SpringBoot提供的核心组件Actuator.提到Actuator,又不得不提Micrometer ...

  3. Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警

    Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警 一.添加依赖 1.1 Actuator 的 /prometheus端点 二.Prometheus 配置 部 ...

  4. 微服务监控zipkin+asp.net core

    0.目录 整体架构目录:ASP.NET Core分布式项目实战-目录 监控目录:微服务监控zipkin.skywalking以及日志ELK监控系列 一.zipkin介绍 zipkin是一种分布式跟踪系 ...

  5. SpringCloud微服务实战——搭建企业级开发框架(四十四):【微服务监控告警实现方式一】使用Actuator + Spring Boot Admin实现简单的微服务监控告警系统

      业务系统正常运行的稳定性十分重要,作为SpringBoot的四大核心之一,Actuator让你时刻探知SpringBoot服务运行状态信息,是保障系统正常运行必不可少的组件.   spring-b ...

  6. 庐山真面目之八微服务架构 NetCore 基于 Dockerfile 文件部署

    庐山真面目之八微服务架构 NetCore 基于 Dockerfile 文件部署 一.简介      从今天开始,不出意外的话,以后所写的文章中所介绍项目的部署环境都应该会迁移到Linux环境上,而且是 ...

  7. Taurus.MVC 微服务框架 入门开发教程:项目部署:4、微服务应用程序发布到Docker部署(上)。

    系列目录: 本系列分为项目集成.项目部署.架构演进三个方向,后续会根据情况调整文章目录. 开源地址:https://github.com/cyq1162/Taurus.MVC 本系列第一篇:Tauru ...

  8. Taurus.MVC 微服务框架 入门开发教程:项目部署:5、微服务应用程序发布到Docker部署(下)。

    系列目录: 本系列分为项目集成.项目部署.架构演进三个方向,后续会根据情况调整文章目录. 开源地址:https://github.com/cyq1162/Taurus.MVC 本系列第一篇:Tauru ...

  9. 使用Prometheus搞定微服务监控

    最近对服务进行监控,而当前监控最流行的数据库就是 Prometheus,同时 go-zero 默认接入也是这款数据库.今天就对 go-zero 是如何接入 Prometheus ,以及开发者如何自己定 ...

随机推荐

  1. mySql执行效率分析

    1.关于SQL查询效率,100w数据,查询只要1秒,与您分享: 机器情况p4: 2.4内存: 1 Gos: windows 2003数据库: ms sql server 2000目的: 查询性能测试, ...

  2. Sprin Boot2.0之整合Mybatis整合分页插件

    pageHelper PageHelper 是一款好用的开源免费的 Mybatis 第三方物理分页插件 物理分页 支持常见的 12 种数据库.Oracle,MySql,MariaDB,SQLite,D ...

  3. 4.7 希尔(shell)排序法

    4-7 ShellSort.c #include <stdio.h> #include "4-1 CreateData.c" //生成随机数的函数 #define AR ...

  4. BZOJ 2019 [Usaco2009 Nov]找工作:spfa【最长路】【判正环】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2019 题意: 奶牛们没钱了,正在找工作.农夫约翰知道后,希望奶牛们四处转转,碰碰运气. 而 ...

  5. javascript(7)

    js中基于对象==js面向对象 js中没有类class,但是它 JavaScript是一种面向(基于)对象的动态脚本语言,是一种基于对象和事件驱动并具有安全性能的脚本语言.它具有面向对象语言所特有的各 ...

  6. 修改ubuntu14.04命令行启动

    方法1: 原来要想默认不进入xwindows,只需编辑文件”/etc/default/grub”, 把 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” 改成GRUB ...

  7. ISO文件怎么安装

    iso是光盘映像文件,打开iso文件有几种方法:1.使用光盘映像工具软件或者虚拟光驱才能打开iso文件.像软碟通(UItraISO)就是一个很好的光盘映像工具软件,使用它就可以打开iso文件,提取里面 ...

  8. BZOJ_1025_[SCOI2009]游戏_DP+置换+数学

    BZOJ_1025_[SCOI2009]游戏_DP+置换 Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按 顺序1 ...

  9. ACM学习历程—HDU 1059 Dividing(dp && 多重背包)

    Description Marsha and Bill own a collection of marbles. They want to split the collection among the ...

  10. bzoj4453

    单调栈+set+后缀数组 一道奇妙的题 这道题如果对于每个询问$r$是固定的,那么就很简单了,可惜并不是 由于r会变化,那么对于两个子串$[i...r],[j...r]$,他们的大小关系随着r的变化也 ...