version: '3.8'
services:
  haproxy:
    image: haproxy:latest
    ports:
      - "53:53/udp"
    restart: always
    command: >
      bash -c "echo '
      global
          maxconn 5000
          tune.ssl.default-dh-param 2048

      defaults
          mode tcp
          timeout connect 5s
          timeout client 30s
          timeout server 30s
          timeout check 5s

      frontend my_frontend
          bind *:53 udp
          default_backend my_backend

      backend my_backend
          balance source
          server server1 172.18.19.41:53 check
          server server2 172.18.19.51:53 check
      ' > /usr/local/etc/haproxy/haproxy.cfg && haproxy -f /usr/local/etc/haproxy/haproxy.cfg"
    networks:
      haproxy-network:
        ipv4_address: 172.18.19.31


  dnsmasq1:
    image: andyshinn/dnsmasq:latest
    ports:
      - "53:53/udp"
    restart: always
    command: >
      bash -c "echo '
      user=dnsmasq
      listen-address=0.0.0.0
      cache-size=10000
      domain-needed
      bogus-priv
      no-resolv
      server=211.136.112.50
      server=211.136.150.66
      ' > /etc/dnsmasq.conf && dnsmasq -d -C /etc/dnsmasq.conf"
    extra_hosts:
      - "example.com:192.168.1.100"
      - "test.example.com:192.168.1.101"
    networks:
      haproxy-network:
        ipv4_address: 172.18.19.41


  dnsmasq2:
    image: andyshinn/dnsmasq:latest
    ports:
      - "53:53/udp"
    restart: always
    command: >
      bash -c "echo '
      user=dnsmasq
      listen-address=0.0.0.0
      cache-size=10000
      domain-needed
      bogus-priv
      no-resolv
      server=219.146.1.66
      ' > /etc/dnsmasq.conf && dnsmasq -d -C /etc/dnsmasq.conf"
    extra_hosts:
      - "example.com:192.168.1.100"
      - "test.example.com:192.168.1.101"
    networks:
      haproxy-network:
        ipv4_address: 172.18.19.42

networks:
  haproxy-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.18.19.0/24
    name: haproxy-network
最后修改:2023 年 11 月 02 日
如果觉得我的文章对你有用,请随意赞赏