cortex 支持多实例运行,可以灵活实际大规模的部署,以下demo,运行了三个cortex 实例,没有配置副本数(主要是ha )
同时对于三个cortex 使用haproxy 做为push 以及查询接口的lb,同时基于prometheus 对于haproxy 进行监控(基于haproxy 2.0 提供的promettheus
支持),基于docker-compose 运行系统依赖的组件,详细配置参考 github

环境准备

  • docker-compose文件
 
version: "3"
services:
    haproxy:
      image: haproxy:2.0.5-alpine
      volumes:
      - "./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
      ports:
      - "8404:8404"
      - "9009:9009"
    consul:
      image: consul
      ports:
      - "8500:8500"
    cortex1:
      image: cortexproject/cortex:master-7d13c2f0
      command: -config.file=/etc/single-process-config.yaml -ring.store=consul -consul.hostname=consul:8500
      ports:
      - "9001:9009"
      volumes:
      - "./single-process-config.yaml:/etc/single-process-config.yaml"
    cortex2:
      image: cortexproject/cortex:master-7d13c2f0
      command: -config.file=/etc/single-process-config.yaml -ring.store=consul -consul.hostname=consul:8500
      ports:
      - "9002:9009"
      volumes:
      - "./single-process-config.yaml:/etc/single-process-config.yaml"
    cortex3:
      image: cortexproject/cortex:master-7d13c2f0
      command: -config.file=/etc/single-process-config.yaml -ring.store=consul -consul.hostname=consul:8500
      ports:
      - "9003:9009"
      volumes:
      - "./single-process-config.yaml:/etc/single-process-config.yaml"
    granfan:
      image: grafana/grafana
      ports:
      - "3000:3000"
    node-exporter:
      image: basi/node-exporter
      ports:
      - "9100:9100"
    prometheus:
      image: prom/prometheus
      ports:
      - "9090:9090"
      volumes:
      - "./prometheus.yml:/etc/prometheus/prometheus.yml"
  • cortex 配置
    single-process-config.yaml 文件
 
# Configuration for running Cortex in single-process mode.
# This should not be used in production. It is only for getting started
# and development.
# Disable the requirement that every request to Cortex has a
# X-Scope-OrgID header. `fake` will be substituted in instead.
auth_enabled: false
server:
  http_listen_port: 9009
  # Configure the server to allow messages up to 100MB.
  grpc_server_max_recv_msg_size: 104857600
  grpc_server_max_send_msg_size: 104857600
  grpc_server_max_concurrent_streams: 1000
distributor:
  shard_by_all_labels: true
  pool:
    health_check_ingesters: true
ingester_client:
  grpc_client_config:
    # Configure the client to allow messages up to 100MB.
    max_recv_msg_size: 104857600
    max_send_msg_size: 104857600
    use_gzip_compression: true
ingester:
  #chunk_idle_period: 15m
  lifecycler:
    # The address to advertise for this ingester. Will be autodiscovered by
    # looking up address on eth0 or en0; can be specified if this fails.
    # address: 127.0.0.1
    # We want to start immediately and flush on shutdown.
    join_after: 0
    claim_on_rollout: false
    final_sleep: 0s
    num_tokens: 512
    # Use an in memory ring store, so we don't need to launch a Consul.
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
# Use local storage - BoltDB for the index, and the filesystem
# for the chunks.
schema:
  configs:
  - from: 2019-03-25
    store: boltdb
    object_store: filesystem
    schema: v10
    index:
      prefix: index_
      period: 168h
storage:
  boltdb:
    directory: /tmp/cortex/index
  filesystem:
    directory: /tmp/cortex/chunks
  • prometheus 配置
    prometheus.yml 文件,主要远端write 地址配置,同时配置了几个监控metrics
 
# my global config
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.
  # scrape_timeout is set to the global default (10s).
remote_write:
- url: http://haproxy:9009/api/prom/push
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'node-exporter'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['node-exporter:9100']
  - job_name: 'haproxy-exporter'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['haproxy:8404']
  • haproxy 配置
    主要是lb 后端cortex 服务9009 端口
 
global
    # master-worker required for `program` section
    # enable here or start with -Ws
    master-worker
    mworker-max-reloads 3
    # enable core dumps
    set-dumpable
    user root
    stats socket /run/haproxy.sock mode 600 level admin
    group root
    log stdout local0
defaults
    mode http
    log global
    timeout client 5s
    timeout server 5s
    timeout connect 5s
    option redispatch
    option httplog
resolvers dns
    parse-resolv-conf
    resolve_retries 3
    timeout resolve 1s
    timeout retry 1s
    hold other 30s
    hold refused 30s
    hold nx 30s
    hold timeout 30s
    hold valid 10s
    hold obsolete 30s
userlist api 
  user admin password $5$aVnIFECJ$2QYP64eTTXZ1grSjwwdoQxK/AP8kcOflEO1Q5fc.5aA
frontend stats
    bind *:8404
    # Enable Prometheus Exporter
    http-request use-service prometheus-exporter if { path /metrics }
    stats enable
    stats uri /stats
    stats refresh 10s
frontend fe_main
    bind :9009 
    log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r cpu_calls:%[cpu_calls] cpu_ns_tot:%[cpu_ns_tot] cpu_ns_avg:%[cpu_ns_avg] lat_ns_tot:%[lat_ns_tot] lat_ns_avg:%[lat_ns_avg]"
    default_backend be_main
backend be_main
     # Enable Power of Two Random Choices Algorithm
    balance random(2)
    # Enable Layer 7 retries
    retry-on all-retryable-errors
    retries 3 
    server cortex1 cortex1:9009 check inter 2s
    server cortex2 cortex2:9009 check inter 2s
    server cortex3 cortex3:9009 check inter 2s
backend be_503
    errorfile 503 /usr/local/etc/haproxy/errors/503.http

启动&&效果

  • 启动
docker-compose up -d
  • prometheus 效果

  • haproxy 监控

  • 配置grafana

主要是prometheus datasource 以及dashboard 的添加
datasource ,注意datasource 地址为cortex 通过haproxy lb 的地址

dashboard, 可以参考项目,直接导入node exporter以及haproxy 的metrics dashboard

  • granfan 效果

  • cortex ring 效果

独立

haproxy

说明

以上是一个简单的配置,实际上我们可以通过在cortex启动的时候指定-distributor.replication-factor=3 保证cortex 的ha,同时上边是比较简单的
实践,实际我们还需要其他后端存储做为数据的存储

参考资料

https://github.com/cortexproject/cortex/blob/master/docs/getting_started.md
https://github.com/rongfengliang/cortex-docker-compose-running

cortex 水平扩展试用的更多相关文章

  1. 理解水平扩展和垂直扩展 (转载 http://yunjiechao-163-com.iteye.com/blog/2126981)

      当一个开发人员提升计算机系统负荷时,通常会考虑两种方式垂直扩展和水平扩展.选用哪种策略主要依赖于要解决的问题 以及系统资源的限制.在这篇文章中我们将讲述这两种策略并讨论每种策越的优缺点.如果你已经 ...

  2. Web 站点的水平扩展和垂直扩展 (译文)

    当一个开发人员提升计算机系统负荷时,通常会考虑两种方式垂直扩展和水平扩展.选 用哪种策略主要依赖于要解决的问题以及系统资源的限制.在这篇文章中我们将讲述这两种策略并讨论每种策越的优缺点.如果你已经有一 ...

  3. 使用Spring Session实现Spring Boot水平扩展

    小编说:本文使用Spring Session实现了Spring Boot水平扩展,每个Spring Boot应用与其他水平扩展的Spring Boot一样,都能处理用户请求.如果宕机,Nginx会将请 ...

  4. Kubernetes — 作业副本与水平扩展

    Deployment 看似简单,但实际上,它实现了 Kubernetes 项目中一个非常重要的功能:Pod 的“水平扩展 / 收缩”(horizontal scaling out/in). 这个功能, ...

  5. Mysql 调优和水平扩展思路

    系统调优参数 一些比较重要的参数: back_log:back_log值指出在MySQL暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中.如果MySql的连接数据达到max_connecti ...

  6. redis水平扩展实践,完全配置,无需代码改动

    设计思路 思路很简单,就是基于用户ID进行分库,将用户的ID字符串按照byte逐个计算ID对应的hash原值(一个数字,取绝对值,因为原始值可能过大溢出,变成负数),然后,再用这个hash原值对库的个 ...

  7. Redis系列(三):Redis集群的水平扩展与伸缩

    一.Redis集群的水平扩展 Redis3.0版本以后,有了集群的功能,提供了比之前版本的哨兵模式更高的性能与可用性,但是集群的水平扩展却比较麻烦,接下来介绍下Redis高可用集群如何做水平扩展,在原 ...

  8. RocketMQ之八:水平扩展及负载均衡详解

    RocketMQ是一个分布式具有高度可扩展性的消息中间件.本文旨在探索在broker端,生产端,以及消费端是如何做到横向扩展以及负载均衡的. NameServer集群 提供轻量级的服务发现和路由.每个 ...

  9. 十万同时在线用户,需要多少内存?——Newbe.Claptrap 框架水平扩展实验

    Newbe.Claptrap 项目是笔者正在构建以反应式.Actor模式和事件溯源为理论基础的一套服务端开发框架.本篇我们将来了解一下框架在水平扩展方面的能力. 前情提要 时隔许久,今日我们再次见面. ...

随机推荐

  1. 爬虫基础 之 urllib

    一.urllib 1. 访问 urllib.request.urlopen() 参数: url:需要爬取的URL地址 timeout:设置等待时间,指定时间内未得到相应时抛出异常 # 导入模块 imp ...

  2. 谷歌浏览器安装Elasticsearch-head 插件

    下载该插件,地址:https://github.com/liufengji/es-head/blob/master/elasticsearch-head.crx 下载后的文件名是:elasticsea ...

  3. 一,python编程100例

    1.有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? #有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? number = (1 ,2,3,4) ...

  4. javaScript 一些小技巧

    日历 创建过去七天的数组,如果将代码中的减号换成加号,你将得到未来7天的数组集合 // 创建过去七天的数组 [...Array(7).keys()].map(days => new Date(D ...

  5. hadoop中HDFS的NameNode原理

    1. hadoop中HDFS的NameNode原理 1.1. 组成 包括HDFS(分布式文件系统),YARN(分布式资源调度系统),MapReduce(分布式计算系统),等等. 1.2. HDFS架构 ...

  6. [TensorFlow 2.0] Keras 简介

    Keras 是一个用于构建和训练深度学习模型的高阶 API.它可用于快速设计原型.高级研究和生产. keras的3个优点: 方便用户使用.模块化和可组合.易于扩展 简单点说就是,简单.好用.快(构建) ...

  7. Samba + DLAN 实现电视机播放电脑文件

    用SMB功能——简单二步让电视访问电脑文件http://tieba.baidu.com/p/5330683066 DLNA怎么用?简单三步实现电脑电视DLNA互联!https://news.znds. ...

  8. jwt揭秘(含源码示例)

      JSON Web Tokens,是一种开发的行业标准 RFC 7519 ,用于安全的表示双方之间的声明.目前,jwt广泛应用在系统的用户认证方面,特别是现在前后端分离项目. 1. jwt认证流程 ...

  9. shell脚本返回值问题

    如果学习过高级语言比如java和c语言等,此时你要是获取一个函数的返回值,直接在函数里面写上return即可,然后在函数执行时将返回结果赋值给某个变量即可.但是在shell脚本中限制较多,因此如果我们 ...

  10. virsh console 登录CentOS7系统

    一.在kvm虚拟机中执行如下命令 systemctl start serial-getty@ttyS0.service systemctl enable serial-getty@ttyS0.serv ...