涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

参考

https://devops.hc-yun.com/archives/18.html
https://www.cnblogs.com/dowi/p/10309418.html
https://www.haproxy.com/blog/haproxy-on-docker-swarm-load-balancing-and-dns-service-discovery
https://kubesphere.io/docs/v3.4/installing-on-linux/high-availability-configurations/set-up-ha-cluster-using-keepalived-haproxy
https://github.com/k911/haproxy-keepalived-docker
https://ratibor78.medium.com/ha-redis-clustering-from-scratch-ebc5e81d7a78

1. compose

# cat > haproxy.yml << EOF
version: '3.8'

services:
  haproxy01:
    image: bitnami/haproxy:2.9.4
    container_name: haproxy01
    hostname: haproxy01.local
    ports:
      - 29080:8080
      - 29443:9999
    volumes:
      - $PWD/haproxy.cfg:/bitnami/haproxy/conf/haproxy.cfg
    networks:
      haproxy-net:
        ipv4_address: 172.16.22.11
    #sysctls:
    #  net.ipv4.ip_unprivileged_port_start: 0

networks:
  haproxy-net:
    name: haproxy-net
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.16.22.0/24
          gateway: 172.16.22.1

# Reloading config (container_name)
# docker kill -s HUP haproxy01
EOF

2. config

# cat > haproxy.cfg << EOF
global
  log stdout format raw local0 info

defaults
  mode http
  timeout client 10s
  timeout connect 5s
  timeout server 10s
  timeout http-request 10s
  log global

frontend stats
  bind *:9999
  stats enable
  stats uri /
  stats refresh 30s

frontend myfrontend
  bind *:8080
  default_backend web

backend web
  server srv-1 10.132.127.8:8080 check
  server srv-2 192.168.2.12:8080 check
  server srv-3 192.168.2.13:8080 check
EOF
posted on 2024-02-02 14:57  北京涛子  阅读(37)  评论(0编辑  收藏  举报