prometheus operator监控k8s集群之外的haproxy组件

本文涉及的产品
可观测监控 Prometheus 版,每月50GB免费额度
简介: prometheus operator监控k8s集群之外的haproxy组件

安装haproxy

在k8s的master1节点安装haproxy,k8s的master1节点的机器ip是192.168.0.6,haproxy1.8.6版本压缩包所在的百度网盘地址如下:

链接:https://pan.baidu.com/s/1glUeOwnvZrdnETr4KayNjg
提取码:i3rn

把压缩包上传到自己的k8s master1节点,手动解压,然后编译安装:


tar zxvf haproxy-1.8.6.tar.gz

cd haproxy-1.8.6

make TARGET=linux31

make install PREFIX=/usr/local/haproxy

mkdir /usr/local/haproxy/conf

cp  examples/option-http_proxy.cfg  /usr/local/haproxy/conf/haproxy.cfg


修改/usr/local/haproxy/conf/haproxy.cfg文件里的监听端口,把bind后面的值改成*:5000,这个是haproxy的监听端口,大家可以随意改,符合自己的环境即可:

cat /usr/local/haproxy/conf/haproxy.cfg


修改haproxy启动脚本文件:

在/etc/init.d/新建一个haproxy文件,haproxy文件所在百度网盘地址如下,

链接:https://pan.baidu.com/s/1zFxHftdAHob-Rtyizk10Xg
提取码:u2lz

可从百度网盘下载,然后拷贝到自己haproxy机器的/etc/init.d/目录下:

 

具体内容也可以参考如下,建议直接从百度王盼盼下载,这样不会出现乱码问题:

cat  /etc/init.d/haproxy
#!/bin/sh
# chkconfig 2345 on
# description: HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments.
if [ -f /etc/init.d/functions ]; then
 . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
 . /etc/rc.d/init.d/functions
else
 exit 0
fi
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
config="/usr/local/haproxy/conf/haproxy.cfg"
exec="/usr/local/haproxy/sbin/haproxy"
PID="/var/run/haproxy.pid"
[ -f $config ] || exit 1
RETVAL=0
start() {
  daemon $exec -c -q -f $config
    if [ $? -ne 0 ]; then
        echo "Errors found in configuration file."
        return 1
    fi
  echo -n "Starting HAproxy: "
  $exec -D -f $config -p $PID
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/haproxy
  return $RETVAL
}
stop() {
 echo -n "Shutting down HAproxy: "
 killproc haproxy -USR1
 RETVAL=$?
 echo
 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/haproxy
 [ $RETVAL -eq 0 ] && rm -f $PID
 return $RETVAL
}
restart() {
 $exec -c -q -f $config
   if [ $? -ne 0 ]; then
       echo "Errors found in configuration file, check it with 'haproxy check'."
       return 1
   fi
 stop
 start
}
rhstatus() {
 status haproxy
}
# See how we were called.
case "$1" in
 start)
        start
        ;;
 stop)
        stop
        ;;
 restart)
        restart
        ;;
 status)
        rhstatus
        ;;
 *)
        echo $"Usage: haproxy {start|stop|restart|status}"
        RETVAL=1
        esac
        exit $RETVAL


启动haproxy:

    chmod  +x  /etc/init.d/haproxy
    service  haproxy start

    查看haproxy是否启动成功:

      ss -antulp | grep :5000

      显示如下,说明启动成功:

        tcp    LISTEN     0      128       *:5000                  *:*                   u

        安装haproxy_exporter

        haproxy_exporter需要的压缩包是:


          haproxy_exporter-0.9.0.linux-386.tar.gz

          压缩包所在的百度网盘地址如下:

            链接:https://pan.baidu.com/s/1zFxHftdAHob-Rtyizk10Xg
            提取码:u2lz

            可从百度网盘把压缩包下载到电脑,然后上传到k8s的master1节点进行解压安装:

            tar  zxvf  haproxy_exporter-0.9.0.linux-386.tar.gz

            cd   haproxy_exporter-0.9.0.linux-386

            cp haproxy_exporter  /usr/bin

             

            启动haproxy_exporter:

            haproxy_exporter --haproxy.scrape-uri="http://192.168.0.6:5000/baz?stats;csv" --web.listen-address="192.168.0.6:9100" &

             

            注意:

            192.168.0.6是部署haproxy和haproxy_exporter所在机器的ip,5000端口是haproxy组件端口,9100是haproxy_exporter端口

             

            验证haproxy_exporter是否启动成功:

            ss -antulp | grep :9100


            显示如下,说明启动成功:

              tcp    LISTEN     0     128    192.168.0.6:9100                  *:*                   users:(("haproxy_exporte",pid=51714,fd=3))


              通过haproxy_exporter采集haproxy组件监控指标:

              curl  192.168.0.6:9100/metrics

              可看到如下监控指标数据:

              # HELP go_gc_duration_seconds A summary of the GC invocationdurations.
              # TYPE go_gc_duration_seconds summary
              go_gc_duration_seconds{quantile="0"} 0.00011131
              go_gc_duration_seconds{quantile="0.25"} 0.000411065
              go_gc_duration_seconds{quantile="0.5"} 0.000803894
              go_gc_duration_seconds{quantile="0.75"} 0.002416707
              go_gc_duration_seconds{quantile="1"} 0.031029562
              go_gc_duration_seconds_sum 0.104676686
              go_gc_duration_seconds_count 19
              # HELP go_goroutines Number of goroutines that currently exist.
              # TYPE go_goroutines gauge
              go_goroutines 9
              # HELP go_memstats_alloc_bytes Number of bytes allocated and stillin use.
              # TYPE go_memstats_alloc_bytes gauge
              go_memstats_alloc_bytes 3.384024e+06
              # HELP go_memstats_alloc_bytes_total Total number of bytesallocated, even if freed.
              # TYPE go_memstats_alloc_bytes_total counter
              go_memstats_alloc_bytes_total 5.452464e+07
              # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by theprofiling bucket hash table.
              # TYPE go_memstats_buck_hash_sys_bytes gauge
              go_memstats_buck_hash_sys_bytes 725494
              # HELP go_memstats_frees_total Total number of frees.
              # TYPE go_memstats_frees_total counter
              go_memstats_frees_total 81339
              # HELP go_memstats_gc_sys_bytes Number of bytes used for garbagecollection system metadata.
              # TYPE go_memstats_gc_sys_bytes gauge
              go_memstats_gc_sys_bytes 2.8383232e+07
              # HELP go_memstats_heap_alloc_bytes Number of heap bytes allocatedand still in use.
              # TYPE go_memstats_heap_alloc_bytes gauge
              go_memstats_heap_alloc_bytes 3.384024e+06
              # HELP go_memstats_heap_idle_bytes Number of heap bytes waiting tobe used.
              # TYPE go_memstats_heap_idle_bytes gauge
              go_memstats_heap_idle_bytes 1.39264e+06
              ---
              ---
              ---
              ---
              ---
              ---

              配置prometheus operator的servicemonitor实现对haproxy的监控

              在k8s的master1节点编写servicemonitor,所需要的yaml文件在百度网盘地址如下:

                链接:https://pan.baidu.com/s/1zFxHftdAHob-Rtyizk10Xg
                提取码:u2lz

                建议直接从百度网盘下载资源清单文件prometheus-servicemonitor-haproxy.yaml,然后传到k8s的master1节点,这样不会出现乱码问题,

                也可参考下面内容:

                cat prometheus-servicemonitor-haproxy.yaml

                kind: Service
                apiVersion: v1
                metadata:
                 name: haproxy
                 labels:
                   app: haproxy
                spec:
                 type: ClusterIP
                 ports:
                 - name: haproxy
                   port: 9100
                   targetPort: 9100
                ---
                kind: Endpoints
                apiVersion: v1
                metadata:
                 name: haproxy
                 labels:
                   app: haproxy
                subsets:
                 - addresses:
                     - ip: 192.168.0.6
                   ports:
                     - name: haproxy
                       port: 9100
                ---
                apiVersion: monitoring.coreos.com/v1
                kind: ServiceMonitor
                metadata:
                  name: haproxy
                  namespace: monitoring
                  labels:
                    team: frontend
                spec:
                  namespaceSelector:
                    any: true
                    matchNames:
                    - default
                  selector:
                    matchLabels:
                      app: haproxy
                  endpoints:
                  - port: haproxy
                targetPort: 9100

                通过kubectl apply更新yaml:

                  kubectl apply  -f prometheus-servicemonitor-haproxy.yaml

                   

                  在prometheus的web界面查看是否监控到了haproxy数据,显示如下,说明配置正常:



                  相关实践学习
                  通过Ingress进行灰度发布
                  本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
                  容器应用与集群管理
                  欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
                  相关文章
                  |
                  1月前
                  |
                  存储 运维 Kubernetes
                  正式开源,Doris Operator 支持高效 Kubernetes 容器化部署方案
                  飞轮科技推出了 Doris 的 Kubernetes Operator 开源项目(简称:Doris Operator),并捐赠给 Apache 基金会。该工具集成了原生 Kubernetes 资源的复杂管理能力,并融合了 Doris 组件间的分布式协同、用户集群形态的按需定制等经验,为用户提供了一个更简洁、高效、易用的容器化部署方案。
                  正式开源,Doris Operator 支持高效 Kubernetes 容器化部署方案
                  |
                  2月前
                  |
                  存储 数据采集 Prometheus
                  Grafana Prometheus Altermanager 监控系统
                  Grafana、Prometheus 和 Alertmanager 是一套强大的开源监控系统组合。Prometheus 负责数据采集与存储,Alertmanager 处理告警通知,Grafana 提供可视化界面。本文简要介绍了这套系统的安装配置流程,包括各组件的下载、安装、服务配置及开机自启设置,并提供了访问地址和重启命令。适用于希望快速搭建高效监控平台的用户。
                  176 20
                  |
                  2月前
                  |
                  Prometheus 监控 Cloud Native
                  Prometheus+Grafana监控Linux主机
                  通过本文的步骤,我们成功地在 Linux 主机上使用 Prometheus 和 Grafana 进行了监控配置。具体包括安装 Prometheus 和 Node Exporter,配置 Grafana 数据源,并导入预设的仪表盘来展示监控数据。通过这种方式,可以轻松实现对 Linux 主机的系统指标监控,帮助及时发现和处理潜在问题。
                  233 7
                  |
                  2月前
                  |
                  Prometheus 运维 监控
                  Prometheus+Grafana+NodeExporter:构建出色的Linux监控解决方案,让你的运维更轻松
                  本文介绍如何使用 Prometheus + Grafana + Node Exporter 搭建 Linux 主机监控系统。Prometheus 负责收集和存储指标数据,Grafana 用于可视化展示,Node Exporter 则采集主机的性能数据。通过 Docker 容器化部署,简化安装配置过程。完成安装后,配置 Prometheus 抓取节点数据,并在 Grafana 中添加数据源及导入仪表盘模板,实现对 Linux 主机的全面监控。整个过程简单易行,帮助运维人员轻松掌握系统状态。
                  330 3
                  |
                  2月前
                  |
                  Prometheus 监控 Cloud Native
                  无痛入门Prometheus:一个强大的开源监控和告警系统,如何快速安装和使用?
                  Prometheus 是一个完全开源的系统监控和告警工具包,受 Google 内部 BorgMon 系统启发,自2012年由前 Google 工程师在 SoundCloud 开发以来,已被众多公司采用。它拥有活跃的开发者和用户社区,现为独立开源项目,并于2016年加入云原生计算基金会(CNCF)。Prometheus 的主要特点包括多维数据模型、灵活的查询语言 PromQL、不依赖分布式存储、通过 HTTP 拉取时间序列数据等。其架构简单且功能强大,支持多种图形和仪表盘展示模式。安装和使用 Prometheus 非常简便,可以通过 Docker 快速部署,并与 Grafana 等可
                  655 2
                  |
                  2月前
                  |
                  Prometheus 监控 Cloud Native
                  如何使用Prometheus监控Docker Swarm集群的资源使用情况?
                  还可以根据实际需求进行进一步的配置和优化,如设置告警规则,当资源使用超出阈值时及时发出警报。通过这些步骤,能够有效地使用 Prometheus 对 Docker Swarm 集群的资源进行监控和管理。
                  113 8
                  |
                  3月前
                  |
                  存储 Prometheus 监控
                  监控堆外第三方监控工具Prometheus
                  监控堆外第三方监控工具Prometheus
                  88 3
                  |
                  3月前
                  |
                  存储 Prometheus 运维
                  在云原生环境中,阿里云ARMS与Prometheus的集成提供了强大的应用实时监控解决方案
                  在云原生环境中,阿里云ARMS与Prometheus的集成提供了强大的应用实时监控解决方案。该集成结合了ARMS的基础设施监控能力和Prometheus的灵活配置及社区支持,实现了全面、精准的系统状态、性能和错误监控,提升了应用的稳定性和管理效率。通过统一的数据视图和高级查询功能,帮助企业有效应对云原生挑战,促进业务的持续发展。
                  110 3
                  |
                  3月前
                  |
                  Prometheus 运维 监控
                  智能运维实战:Prometheus与Grafana的监控与告警体系
                  【10月更文挑战第26天】Prometheus与Grafana是智能运维中的强大组合,前者是开源的系统监控和警报工具,后者是数据可视化平台。Prometheus具备时间序列数据库、多维数据模型、PromQL查询语言等特性,而Grafana支持多数据源、丰富的可视化选项和告警功能。两者结合可实现实时监控、灵活告警和高度定制化的仪表板,广泛应用于服务器、应用和数据库的监控。
                  481 3
                  |
                  6月前
                  |
                  Prometheus 监控 Cloud Native
                  【监控】prometheus传统环境监控告警常用配置
                  【监控】prometheus传统环境监控告警常用配置
                  【监控】prometheus传统环境监控告警常用配置

                  热门文章

                  最新文章