job "consul-cluster" { datacenters = ["dc1"] type = "service" # 在三个节点上运行:bj-warden, master, ash3c constraint { attribute = "${node.unique.name}" operator = "regexp" value = "(bj-warden|master|ash3c)" } group "consul" { count = 3 # 确保每个节点只运行一个实例 constraint { operator = "distinct_hosts" value = "true" } network { port "http" { static = 8500 } port "rpc" { static = 8400 } port "serf_lan" { static = 8301 } port "serf_wan" { static = 8302 } port "server" { static = 8300 } port "dns" { static = 8600 } } task "consul" { driver = "exec" config { command = "consul" args = [ "agent", "-server", "-bootstrap-expect=3", "-data-dir=/tmp/consul-cluster-data", "-bind=${NOMAD_IP_serf_lan}", "-client=0.0.0.0", "-retry-join=100.122.197.112", # bj-warden Tailscale IP "-retry-join=100.117.106.136", # master Tailscale IP "-retry-join=100.116.80.94", # ash3c Tailscale IP "-ui-config-enabled=true", "-log-level=INFO", "-node=${node.unique.name}-consul", "-datacenter=dc1" ] } artifact { source = "https://releases.hashicorp.com/consul/1.17.0/consul_1.17.0_linux_arm64.zip" destination = "local/" } resources { cpu = 200 memory = 256 } service { name = "consul-cluster" port = "http" check { type = "http" path = "/v1/status/leader" port = "http" interval = "10s" timeout = "3s" } } } } }