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. 带着canvas去流浪系列之八 碰撞【华为云技术分享】

    [摘要] canvas动画-碰撞仿真 示例代码托管在:http://www.github.com/dashnowords/blogs 经过前面章节相对枯燥的练习,相信你已经能够上手canvas的原生A ...

  2. intellij idea 修改背景保护色&&修改字体&&快捷键大全

    intellij idea 修改背景保护色&&修改字体&&快捷键大全 原创 2013年11月22日 18:00:07 90176 最近Idea比较流行,Eclipse因 ...

  3. Linux学习笔记之详解linux软连接和硬链接

    0x00 链接文件 Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [软连接] 另外一种连接称之为符 ...

  4. 我的第一个netcore2.2 api项目搭建(三)

    上一章快速添加了swagger文档管理功能,我的第一个netcore2.2 api项目搭建(二) 这一章实现目标三:api添加身份验证功能 在实现该目标之前,先得理解netcore运行机制. 这是微软 ...

  5. Jwt身份验证

    转载自博友(TerryTon)  1.因为json是通用的,所以jwt可以在绝大部分平台可以通用,如java,python,php,.net等  2.基于jwt是无状态的,jwt可以用于分布式等现在比 ...

  6. JVM故障分析系列之四:jstack生成的Thread Dump日志线程状态

    JVM故障分析系列之四:jstack生成的Thread Dump日志线程状态  2017年10月25日  Jet Ma  JavaPlatform JVM故障分析系列系列文章 JVM故障分析系列之一: ...

  7. flyway.setBaselineOnMigrate(true);

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayWrappe ...

  8. Git 解决合并分支时的冲突

    参考链接:https://www.liaoxuefeng.com/wiki/896043488029600/900004111093344 创建分支时,新分支的文件内容建立在原分支的基础上,我们称这时 ...

  9. Spring Security 解析(七) —— Spring Security Oauth2 源码解析

    Spring Security 解析(七) -- Spring Security Oauth2 源码解析   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因 ...

  10. kylin Build过程问题排查:17 Step Name: Build Cube In-Mem

    Kylin Build执行到底17步时报错:17 Step Name: Build Cube In-Mem  ,错误截图如下: 点左下角的MRJob图标,打开查看错误信息: 从MRJob中的描述中可见 ...