test-node-discovery-dns.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. ## Test two nodes-cluster discover each other using DNS A records lookup result.
  3. set -euo pipefail
  4. cd -P -- "$(dirname -- "$0")/.."
  5. IMAGE="${1}"
  6. NET='test_node_discovery_dns'
  7. NODE1='emqx1'
  8. NODE2='emqx2'
  9. COOKIE='this-is-a-secret'
  10. # cleanup
  11. docker rm -f dnsmasq >/dev/null 2>&1 || true
  12. docker rm -f "$NODE1" >/dev/null 2>&1 || true
  13. docker rm -f "$NODE2" >/dev/null 2>&1 || true
  14. docker network rm "$NET" >/dev/null 2>&1 || true
  15. docker network create --subnet=172.18.0.0/16 $NET
  16. IP0="172.18.0.100"
  17. IP1="172.18.0.101"
  18. IP2="172.18.0.102"
  19. DOMAIN="dnstest.mynet"
  20. # create configs for dnsmasq
  21. cat <<-EOF > "/tmp/dnsmasq.conf"
  22. conf-dir=/etc/dnsmasq,*.conf
  23. addn-hosts=/etc/hosts.$DOMAIN
  24. EOF
  25. cat <<-EOF > "/tmp/hosts.$DOMAIN"
  26. $IP1 $DOMAIN
  27. $IP2 $DOMAIN
  28. EOF
  29. cat <<-EOF > /tmp/dnsmasq.base.conf
  30. domain-needed
  31. bogus-priv
  32. no-hosts
  33. keep-in-foreground
  34. no-resolv
  35. expand-hosts
  36. server=8.8.8.8
  37. EOF
  38. docker run -d -t --name dnsmasq \
  39. --net "$NET" \
  40. --ip "$IP0" \
  41. -v /tmp/dnsmasq.conf:/etc/dnsmasq.conf \
  42. -v "/tmp/hosts.$DOMAIN:/etc/hosts.$DOMAIN" \
  43. -v "/tmp/dnsmasq.base.conf:/etc/dnsmasq/0.base.conf" \
  44. --cap-add=NET_ADMIN \
  45. storytel/dnsmasq dnsmasq --no-daemon --log-queries
  46. start_emqx() {
  47. NAME="$1"
  48. IP="$2"
  49. DASHBOARD_PORT="$3"
  50. docker run -d -t \
  51. --name "$NAME" \
  52. --net "$NET" \
  53. --ip "$IP" \
  54. --dns "$IP0" \
  55. -p "$DASHBOARD_PORT:18083" \
  56. -e EMQX_LOG__CONSOLE_HANDLER__LEVEL=debug \
  57. -e EMQX_NODE_COOKIE="$COOKIE" \
  58. -e EMQX_cluster__discovery_strategy='dns' \
  59. -e EMQX_cluster__dns__name="$DOMAIN" \
  60. "$IMAGE"
  61. }
  62. start_emqx "$NODE1" "$IP1" 18083
  63. start_emqx "$NODE2" "$IP2" 18084