centos7.5prometheus2.5配置和基于consul1.2.4的服务发现(代码片段)

author author     2023-02-01     334

关键词:

一、Prometheus安装及配置

请参考:
CentOS7.5 Prometheus2.5+Grafana5.4监控部署

二 、基于Consul的服务发现

1、概述

  • Consul 是一个支持多数据中心分布式高可用的服务发现和配置共享的服务软件.
  • Consul 由 HashiCorp公司用Go语言开发, 基于Mozilla Public License 2.0的协议进行开源.?
  • Consul 支持健康检查,并允许 HTTP 和 DNS 协议调用 API 存储键值对.
  • 命令行超级好用的虚拟机管理软件 vgrant 也是 HashiCorp 公司开发的产品.
  • 一致性协议采用 Raft 算法,用来保证服务的高可用. 使用 GOSSIP 协议管理成员和广播消息, 并且支持 ACL 访问控制.

架构图

技术分享图片

2、下载及安装

wget https://releases.hashicorp.com/consul/1.2.4/consul_1.2.4_linux_amd64.zip
unzip consul_1.2.4_linux_amd64.zip -d /app/prometheus/bin/
cd /app/prometheus/bin/
chown -R prometheus.prometheus consul

3、创建Consul.service 的 systemd unit 文件

# vim /usr/lib/systemd/system/consul.service
[Unit]
Description=consul
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/app/prometheus/bin/consul agent -server -bootstrap-expect 1 -bind=0.0.0.0 -client=172.16.9.201 -data-dir=/app/prometheus/consuld/data/consul -node=172.17.9.201 -config-dir=/app/prometheus/consuld/conf -ui
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
参数说明
  • –net=host docker参数, 使得docker容器越过了net namespace的隔离,免去手动指定端口映射的步骤
  • -server consul支持以server或client的模式运行, server是服务发现模块的核心, client主要用于转发请求
  • -advertise 将本机私有IP传递到consul
  • -bootstrap-expect 指定consul将等待几个节点连通,成为一个完整的集群
  • -retry-join 指定要加入的consul节点地址,失败会重试, 可多次指定不同的地址
  • -client consul绑定在哪个client地址上,这个地址提供HTTP、DNS、RPC等服务,默认是127.0.0.1
  • -bind 该地址用来在集群内部的通讯,集群内的所有节点到地址都必须是可达的,默认是0.0.0.0
  • allow_stale 设置为true, 表明可以从consul集群的任一server节点获取dns信息, false则表明每次请求都会经过consul server leader

4、启动服务

 systemctl daemon-reload
 systemctl start consul.service 
 systemctl enable consul.service 

5、查看运行状态

# systemctl status consul.service 
● consul.service - consul
   Loaded: loaded (/usr/lib/systemd/system/consul.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2018-12-11 15:23:12 CST; 20min ago
     Docs: https://prometheus.io/
 Main PID: 5721 (consul)
   CGroup: /system.slice/consul.service
           └─5721 /app/prometheus/bin/consul agent -server -bootstrap-expect 1 -bind=0.0.0.0 -client=172.16.9.201 -data-dir=/app/prometheus/consuld/data/consul -node=172.17.9.201 -config...

12月 11 15:23:18 prometheus-node1 consul[5721]: 2018/12/11 15:23:18 [INFO] raft: Election won. Tally: 1
12月 11 15:23:18 prometheus-node1 consul[5721]: 2018/12/11 15:23:18 [INFO] raft: Node at 172.16.9.201:8300 [Leader] entering Leader state
12月 11 15:23:18 prometheus-node1 consul[5721]: 2018/12/11 15:23:18 [INFO] consul: cluster leadership acquired
12月 11 15:23:18 prometheus-node1 consul[5721]: 2018/12/11 15:23:18 [INFO] consul: New leader elected: 172.17.9.201
12月 11 15:23:18 prometheus-node1 consul[5721]: 2018/12/11 15:23:18 [INFO] consul: member ‘172.17.9.201‘ joined, marking health alive
12月 11 15:23:18 prometheus-node1 consul[5721]: 2018/12/11 15:23:18 [INFO] agent: Synced node info
12月 11 15:23:25 prometheus-node1 consul[5721]: ==> Newer Consul version available: 1.4.0 (currently running: 1.2.4)
12月 11 15:40:21 prometheus-node1 consul[5721]: 2018/12/11 15:40:21 [WARN] agent: Service name "node_exporter" will not be discoverable via DNS due to invalid characters. Val...and dashes.
12月 11 15:40:21 prometheus-node1 consul[5721]: 2018/12/11 15:40:21 [INFO] agent: Synced service "node_exporter"
12月 11 15:42:08 prometheus-node1 consul[5721]: 2018/12/11 15:42:08 [INFO] agent: Synced service "node_exporter"
Hint: Some lines were ellipsized, use -l to show in full.

http://172.16.9.201:8500/ui/
技术分享图片

6、配置Consul.service自动注册

yum -y install jq

服务查询

# curl -s http://172.16.9.201:8500/v1/catalog/services|jq

  "consul": []

使用HTTP接口服务注册:

# curl -X PUT -d ‘"ID": "node_exporter", "Name": "node_exporter", "Address": "172.16.9.201", "Port": 9100, "Tags": ["lock"], "EnableTagOverride": false‘ http://172.16.9.201:8500/v1/agent/service/register
# curl -s http://172.16.9.201:8500/v1/catalog/services|jq

  "consul": [],
  "node_exporter": [
    "lock"
  ]

7、prometheus服务配置文件

# vim prometheus.yml 

global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - 172.16.9.201:9093
      - 172.16.9.202:9093

rule_files:
   - /app/prometheus/cfg/rule.yml
scrape_configs:
  - job_name: ‘prometheus‘
    metrics_path:    /metrics
    honor_labels:    false
    static_configs:
      - targets: [‘localhost:9090‘]
        labels:
          group: ‘node‘
          service: ‘prometheus‘
  - job_name: ‘prod_discover‘
    metrics_path: /metrics
    honor_labels: false
    consul_sd_configs:
    - server: ‘172.16.9.201:8500‘
      services: [‘node_exporter‘]
      tag_separator: ‘‘
    relabel_configs:
    - source_labels: [‘__meta_consul_tags‘]
      target_label: ‘product‘
    - source_labels: [‘__meta_consul_dc‘]
      target_label: ‘idc‘
    - source_labels: [‘__meta_consul_service‘]
      target_label: ‘service‘
    - source_labels: [‘job‘]
      target_label: ‘environment‘
      regex:        ‘(.*)_discover‘
      replacement:   ‘$1‘
打开WEB界面

http://172.16.9.201:9090/targets

技术分享图片

linuxcentos7上redis3.2.5的安装与配置(代码片段)

  redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sortedset--有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集... 查看详情

2.5万字详细讲解个人网站的开发过程和项目的部署(代码片段)

...绍1.1个人博客功能1.2技术组合1.3工具与坏境2项目的环境配置2.1vue的环境配置2.2解决跨域问题2.3关于图标的获取3前端技术3.1element-ui的分页使用介绍3.2发布博客3.3点赞功能的实现3.4评论3.5获取B站用户信息3.6相册的设计3.7图片上传3.... 查看详情

myeclipse2014配置2.5版本的struts2

原创配置struts2一般来说需要以下步骤:将项目所需要的Jar包导入项目webRoot/WEB-INF/lib下(包不追求多,容易导致冲突或者其他问题,需要多少导入多少)配置struts.xml文件配置web.xml文件2.5版本的struts2 链接:https://pan.baidu.com/s/1... 查看详情

玩 2.5 剪影 4 - 带有 guice 的 DI

...一使用guice和scala-guice(net.codingwell.scalaguice.ScalaModule)编写DI配置 查看详情

java示例代码_在Spring 2.5的配置文件中连接两个字符串bean

java示例代码_在Spring 2.5的配置文件中连接两个字符串bean 查看详情

crmsh配置pacemaker集群时报错cibnotsupported:validator'pacemaker-2.5'

在使用crmsh配置集群时曾遇到过如下错误:       ERROR:CIBnotsupported:validator‘pacemaker-2.5‘,release‘3.0.10‘ERROR:YoumaytrytheupgradecommandERROR:NoCIB!    大概的意思就 查看详情

浙江中控2.5sp6使用语音报警

...是SUPER_PASSWORD_001新建一个项目,添加基本硬件和操作站,配置一个AI模板,添加两个AI变量配置一下每个AI变量的参数和报警值。接下来制作语音文件打开浏览器,到下面的网站TextToSpeech-在线文本转语音(text-to-speech.cn)输入文字,... 查看详情

一起使用 Python 3.1 和 2.5

】一起使用Python3.1和2.5【英文标题】:UsingPython3.1and2.5together【发布时间】:2011-08-2811:39:01【问题描述】:我目前正在为我的编程课做最后的项目。我们用Python3.1编写它,而我正在做GUI。我的团队负责人希望在3.1中完成整个项目... 查看详情

idea创建第一个maven项目报错:cannotresolvepluginorg.apache.maven.pluginsmaven-clean-plugin2.5

主要原因是本地maven的配置文件和仓库地址不一致。在本地新建一个文件夹和一个XML文件。然后在配置setting.xml文件,最后在idea中配置maven。具体步骤参考该博文来配置:https://www.cnblogs.com/phpdragon/p/7216626.html可以修改一下... 查看详情

cesium屏蔽掉一些默认设置(基础篇)

...们搭建一个cesium项目的时候,cesium会提供给我们一些默认配置,如下图。有时候我们想隐藏掉这些配置隐藏掉这些配置有两种方式。1.js构造viewer对象时候隐藏2.通过viewer对象来隐藏div的方式Cesium里面鼠标的操作主要在ScreenSpaceCame... 查看详情

使用lvs和keepalived搭建高可用负载均衡服务器集群(代码片段)

...LVS和Keepalived2、负载均衡服务器集群示例环境搭建及安装配置2.1、环境网络拓扑结构2.2、安装ipvsadm软件    2.3、安装keepalived2.4、配置网络相关设置2.5、配置keepalived并启动2.5、实现故障隔离3、测试LVS服务器主从配置4、最后   ... 查看详情

2.5dvisualsound:cvpr2019论文解析

...文设计了一个深卷积神经网络,通过注入有关物体和场景配置的视觉信息,学习将单声道(单声道)原声解码成双耳原声。本文称之为输出2.5D视觉声音视觉流有助于“提升”单声道音频到空间化的声音。除了声音生成之外... 查看详情

haproxy基础和配置

 简介    开源、高性能、基于TCP均衡负载器、HTTP应用反向代理器;HAproxy是均衡负载和反向代理器,ha名字源于其可以对后端进行健康检查,保证后端的可用性。    HAproxy1.2.5以上版本2.6以上内核... 查看详情

vite3.2.5配置代理proxy,打印代理转发的日志(代码片段)

...上–debug参数即可。如下所示npxvite--debug另一种是借用proxy配置中的rewrite函数手动打印,例如console.log()。自行尝试即可样例https://gitee.com/matevip/artemis 查看详情

vite3.2.5配置代理proxy,打印代理转发的日志(代码片段)

...上–debug参数即可。如下所示npxvite--debug另一种是借用proxy配置中的rewrite函数手动打印,例如console.log()。自行尝试即可样例https://gitee.com/matevip/artemis 查看详情

课后习题和问题复习题2.2~2.5节

课后习题和问题复习题2.2~2.5节R10.握手协议的作用是什么?   一个协议使用握手机制,如果两个通信实体,将数据发送到彼此之前,第一交换控制包  的数据包。SMTP使用握手在应用层,HTTP没有。R11.为什么HTTP... 查看详情

将 wamp 2.0 升级到 2.5 的最佳方法

】将wamp2.0升级到2.5的最佳方法【英文标题】:BestwaytoUpgradewamp2.0to2.5【发布时间】:2014-10-0113:32:58【问题描述】:我的wamp2.0使用了大约100多个大型数据库和很多项目。我还制作了大约50多个虚拟主机。现在我需要将wamp2.0升级到2.5... 查看详情

[知识点]2.5二分思想

...https://www.cnblogs.com/jinkun113/p/12528423.html)子目录列表 2.5二分思想1、二分与分治在前面,我们已经提过了分治思想(请参见:https://www.cnblogs.com/jinkun1 查看详情