haproxy 2.0 dataplaneapi docker 镜像

为了方便测试dataplaneapi 基于官方的docker镜像,制作了一个简单的包含dataplaneapi 的镜像

下载dataplaneapi

https://github.com/haproxytech/dataplaneapi/releases

Dockerfile

FROM haproxy:2.0.5
COPY dataplaneapi /usr/local/sbin/dataplaneapi
RUN chmod +x /usr/local/sbin/dataplaneapi

简单参考配置文件

通过processmanager 管理

#
# This is the ultimate HAProxy 2.0 "Getting Started" config
# It demonstrates many of the features available which are now available 
# While you may not need all of these things, this can serve
# as a reference for your own configurations.
#
# Have questions? Check out our community Slack:
# https://slack.haproxy.org/
#
?
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
    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
program dataplane-api
    command /usr/local/sbin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/local/sbin/haproxy --config-file /usr/local/etc/haproxy/haproxy.cfg --reload-cmd "kill -SIGUSR2 1" --reload-delay 5 --userlist api
    no option start-on-reload
userlist api 
   # user admin password $5$aVnIFECJ$2QYP64eTTXZ1grSjwwdoQxK/AP8kcOflEO1Q5fc.5aA
    user admin insecure-password dalong
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 *:8080
    # Enable log sampling
    # One out of 10 requests would be logged to this source
    log 127.0.0.1:10001 sample 1:10 local0
    # For every 11 requests, log requests 2, 3, and 8-11
    log 127.0.0.1:10002 sample 2-3,8-11:11 local0
?
    # Log profiling data
    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]"
?
    # gRPC path matching
    acl is_grpc_codename path /CodenameCreator/KeepGettingCodenames 
    # Dynamic ‘do-resolve‘ trusted hosts
    acl dynamic_hosts req.hdr(Host) api.local admin.local haproxy.com
?
    # Activate Traffic Mirror
    # Redirect if not SSL
    # http-request redirect scheme https unless { ssl_fc }
?
    # Enable src tracking
    # http-request track-sc0 src table mypeers/src_tracking
?
    # Enable rate limiting
    # Return 429 Too Many Requests if client averages more than
    # 10 requests in 10 seconds.
    # (duration defined in stick table in peers section)
    http-request deny deny_status 429 if { sc_http_req_rate(0) gt 10 }
?
    # Enable local resolving of Host if within dynamic_hosts ACL
    # Allows connecting to dynamic IP address specified in Host header
    # Useful for DNS split view or split horizon
    http-request do-resolve(txn.dstip,dns) hdr(Host),lower if dynamic_hosts
    http-request capture var(txn.dstip) len 40 if dynamic_hosts
?
    # return 503 when dynamic_hosts matches but the variable 
    # txn.dstip is not set which mean DNS resolution error
    # otherwise route to be_dynamic
    use_backend be_503 if dynamic_hosts !{ var(txn.dstip) -m found }
    use_backend be_dynamic if dynamic_hosts
?
    # route to gRPC path
    use_backend be_grpc if is_grpc_codename 
?
    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 
    # retrying POST requests can be dangerous
    # make sure you understand the implications before removing
    http-request disable-l7-retry if METH_POST
    server server1 nginx1:80 check inter 3s
    server server2 nginx2:80 check inter 3s
backend be_grpc
    default-server ssl verify none alpn h2 check maxconn 50
    server grpc1 10.1.0.11:3000 
    server grpc2 10.1.0.12:3000 
?
backend be_dynamic
    default-server ssl verify none check maxconn 50
?
    # rule to prevent HAProxy from reconnecting to services
    # on the local network (forged DNS name used to scan the network)
    http-request deny if { var(txn.dstip) -m ip 127.0.0.0/8 10.0.0.0/8 }
    http-request set-dst var(txn.dstip)
    server dynamic 0.0.0.0:0
?
backend spoe-traffic-mirror
    mode tcp
    balance roundrobin
    timeout connect 5s
    timeout server 1m
    server spoa1 127.0.0.1:12345
    server spoa2 10.1.0.20:12345
?
backend be_503
    # dummy backend used to return 503.
    # You can use the ‘errorfile‘ directive to send a nice
    # 503 error page to end users.
    errorfile 503 /usr/local/etc/haproxy/errors/503.http 

一个测试效果

  • docker-compose 文件
version: "3"
services:
    grafana:
     image: grafana/grafana
     ports:
     - "3000:3000"
    prometheus:
     image: prom/prometheus
     volumes:
     - "./prometheus.yml:/etc/prometheus/prometheus.yml"
     ports:
     - "9090:9090"
    haproxy:
     image: dalongrong/haproxy-dataplan:2.0.5
     build: ./
     volumes:
     - "./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
     ports:
     - "80:80"
     - "5555:5555"
     - "8404:8404"
     - "8080:8080"
     - "9000:9000"
     - "9001:9001"
     - "9002:9002"
     - "1000-1005:1000-1005"
     - "10080:10080"
    nginx1:
     image: nginx
     ports:
     - "8090:80"
    nginx2:
     image: nginx
     ports:
     - "8091:80"

启动效果

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

http://localhost:5555 用户密码 admin dalong

参考资料

https://www.haproxy.com/documentation/hapee/1-9r1/configuration/dataplaneapi/
https://github.com/haproxytech/dataplaneapi/releases
https://github.com/rongfengliang/haproxy2.0-prometheus

原文地址:https://www.cnblogs.com/rongfengliang/p/11441038.html

时间: 2024-10-11 23:42:45

haproxy 2.0 dataplaneapi docker 镜像的相关文章

haproxy 2.0 dataplaneapi rest api 试用

我们可以基于haproxy 提供的dataplaneapi 动态进行haproxy 配置的修改,增强haproxy的可编程能力,以下是一个简单 的测试,基于docker-compose运行 环境准备 docker-compose文件 version: "3" services: grafana: image: grafana/grafana ports: - "3000:3000" prometheus: image: prom/prometheus volumes

构建Docker镜像实战之构建Tomcat9.0镜像(RPM一键安装Java环境)

构建Docker镜像实战之构建Tomcat9.0镜像(RPM一键安装Java环境) tomcat是一个免费开源的轻量级web服务器,在中小型企和并发访问量不高的场合普遍使用,是开发和调试JSP程序的首选.下面使用Dockerfile文件的方式来创建带有tomcat服务的Dockerfile镜像.(注:这里的Java环境是使用rpm一键式安装的且小编创建的是tomcat9.0的镜像) 下面直接开始实验 关闭防火墙及SELinux systemctl stop firewalld.service s

利用docker镜像配置mysql集群+nextcloud集群+haproxy负载均衡

测试环境: docker xampp 9.1.1 ubuntu 16.0.4 hadoop 2.7 jdk 1.8 一.配置mysql集群 通过docker拉取mysql集群镜像创建容器,包括ndb_mgm(管理节点).ndb_mgmd01.ndbd01(数据节点1).ndbd02(数据节点2).mysqld01(sql节点1).mysqld02(sql节点2) docker run -itd --name ndb_mgmd01 --net=scg --ip 192.166.0.2 -v /ro

在已经安装好spark的docker镜像里安装cassandra2.0.7

1. 通过docker run命令的-v/–volume参数将主机文件拷贝到docker容器 [[email protected] ~]# docker run -v /data:/mnt -i -t -P -h sandbox sequenceiq/spark:1.2.0 /etc/bootstrap.sh -bash / Starting sshd: [ OK ] Starting namenodes on [sandbox] sandbox: starting namenode, logg

Docker + SpringBoot2.0快速构建镜像

博文链接 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何接口.(引用官方概念,本文注重docker+springboot2.0快速构建镜像,对docker更细节的知识不在做赘述) Docker 本文使用的是CentOs7 docker 安装: yum install docker systemctl start docker 开

管理2000+Docker镜像,Kolla是如何做到的

根据 DockerHub 上的数据,整个 Kolla 项目管理的 镜像有 2000 多个,这么多的镜像,是怎么定义,又是如何构建的呢? 简介 我们一直在说的 Kolla,通常情况下泛指,包括了 Kolla 和 Kolla-Ansible 两个项目. 实际上,根据 OpenStack Wiki,还有个 Kayobe 项目也是相关的.但是这个用的比较少,而且我试用后觉得不是特别符合我的需求,就不过多介绍了. 此外还有一个项目 Kolla-kubernetes 致力于和 Kubernetes 结合,但

oracle2c-r2(12.2.0.1) 的镜像

docker- 构建 oracle2c-r2(12.2.0.1) 的镜像 需求 由于公司的数据库需要使用新的oracle版本(12c-r2 -->12.2.0.1),从之前的oracle11g迁移到12c.所以,便有了我们今天的内容. 首先,我们就先来介绍一下如何构建oracle12c的镜像(docker image). 如果大家有使用的需求而又不是正式的项目,可以直接到docker hub 上面 pull 一个别人家的.在这里附上链接:https://hub.docker.com/r/mrit

从零开始构建一个centos+jdk7+tomcat7的docker镜像文件

从零开始构建一个centos+jdk7+tomcat7的镜像文件 centos7系统下docker运行环境的搭建 准备centos基础镜像 docker pull centos 或者直接下载我准备好的镜像 docker pull registry.cn-hangzhou.aliyuncs.com/repos_zyl/centos:0.0.1 准备jdk7和tomcat7安装包 创建工作目录, mkdir -p /z/docker 准备下载jdk7的tar.gz包http://download.o

创建属于自己的docker镜像

docker镜像是容器的基础,当每次执行docker run时就是在对docker说现在我需要哪个镜像.如果在你的docker主机上没有这个镜像,docker会自动从一个registry上下载这个镜像(默认为docker hub) 在这一节,我们将会探讨更多的关于docker镜像的内容: 管理和使用本地镜像 创建基础镜像 使用docker images命令列出本地的docker镜像 [[email protected] ~]# docker images  REPOSITORY