以编程方式启动的Consul代理无法打开HTTP端口

I try to start a Consul agent using their Golang package. The server itself comes up but I can't interact with it because it does not start to listen for incoming HTTP requests.

My code to start the agent:

//create the logwriter
writer := bytes.NewBuffer(server.log)

agentConfig := agent.DefaultConfig()
agentConfig.BindAddr = "127.0.0.1"
agentConfig.DevMode = true
agentConfig.Bootstrap = true
agentConfig.Server = true
agentConfig.DataDir = "/tmp"
agentConfig.Ports.HTTP = 8500
agentConfig.Ports.HTTPS = -1
//agentConfig.AdvertiseAddr = "127.0.0.1"
//agentConfig.EnableUi = true
agentConfig.Addresses.HTTP = "127.0.0.1"

glog.Infof("Agent config: %+v", agentConfig)

agent, err := agent.Create(agentConfig, writer)
if err != nil {
    t.Fatalf("Error starting consul agent: %v", err)
}

The resulting configuration on start looks like:

Agent config: &{DevMode:true Bootstrap:true BootstrapExpect:0
Server:true Datacenter:dc1 DataDir:/tmp DNSRecursor: DNSRecursors:[]  DNSConfig:{NodeTTL:0 NodeTTLRaw: ServiceTTL:map[] ServiceTTLRaw:map[] 
AllowStale:false EnableTruncate:false UDPAnswerLimit:3 MaxStale:5s 
MaxStaleRaw: OnlyPassing:false} Domain:consul. EncryptKey: 
LogLevel:INFO NodeName: ClientAddr:127.0.0.1 BindAddr:127.0.0.1 
AdvertiseAddr: AdvertiseAddrs:{SerfLan:<nil> SerfLanRaw: SerfWan:<nil> 
SerfWanRaw: RPC:<nil> RPCRaw:} AdvertiseAddrWan: 
TranslateWanAddrs:false Ports:{DNS:8600 HTTP:8500 HTTPS:-1 RPC:8400 
SerfLan:8301 SerfWan:8302 Server:8300} Addresses:{DNS: HTTP:127.0.0.1 
HTTPS: RPC:} TaggedAddresses:map[] LeaveOnTerm:false SkipLeaveOnInt:
<nil> Telemetry:{StatsiteAddr: StatsdAddr: StatsitePrefix:consul 
DisableHostname:false DogStatsdAddr: DogStatsdTags:[]} Protocol:2 
EnableDebug:false VerifyIncoming:false VerifyOutgoing:false VerifyServerHostname:false CAFile: CertFile: KeyFile: ServerName: 
StartJoin:[] StartJoinWan:[] RetryJoin:[] RetryMaxAttempts:0 
RetryInterval:30s RetryIntervalRaw: RetryJoinWan:[] 
RetryMaxAttemptsWan:0 RetryIntervalWan:30s RetryIntervalWanRaw: 
ReconnectTimeoutLan:0 ReconnectTimeoutLanRaw: ReconnectTimeoutWan:0 
ReconnectTimeoutWanRaw: EnableUi:false UiDir: PidFile: 
EnableSyslog:false SyslogFacility:LOCAL0 RejoinAfterLeave:false 
CheckUpdateInterval:5m0s CheckUpdateIntervalRaw: ACLToken: 
ACLMasterToken: ACLDatacenter: ACLTTL:30s ACLTTLRaw: 
ACLDefaultPolicy:allow ACLDownPolicy:extend-cache Watches:[] 
DisableRemoteExec:false DisableUpdateCheck:false 
DisableAnonymousSignature:false HTTPAPIResponseHeaders:map[] 
AtlasInfrastructure: AtlasToken: AtlasACLToken: AtlasJoin:false 
AtlasEndpoint: AEInterval:1m0s DisableCoordinates:false 
SyncCoordinateRateTarget:64 SyncCoordinateIntervalMin:15s Checks:[] 
Services:[] ConsulConfig:<nil> Revision: Version: VersionPrerelease: 
WatchPlans:[] UnixSockets:{UnixSocketPermissions:{Usr: Grp: Perms:}} 
SessionTTLMin:0 SessionTTLMinRaw: Reap:<nil>}

Checking my open ports I can see that the agent is up but not listening for HTTP

storage.t 16820  felix    5u  IPv4 469866      0t0  TCP localhost:8300 (LISTEN)
storage.t 16820  felix    6u  IPv4 469867      0t0  TCP localhost:8301 (LISTEN)
storage.t 16820  felix    7u  IPv4 469868      0t0  UDP localhost:8301
storage.t 16820  felix    8u  IPv4 469869      0t0  TCP localhost:8302 (LISTEN)
storage.t 16820  felix    9u  IPv4 469870      0t0  UDP localhost:8302

Every tip to get that running is appreciated :)

dphfwzn8269
dphfwzn8269 您无法收听0.0.0.0。结果是:无法获得广告地址:找到多个私有IP。请配置一个。
大约 4 年之前 回复
dtnrsmi824877
dtnrsmi824877 您是否尝试过听0.0.0.0?
大约 4 年之前 回复

1个回答



确保所有必需的端口也都打开:</ p>

展开原文

原文

Make sure all the required ports are open too:

  • Server RPC (Default 8300)
  • Serf LAN (Default 8301)
  • Serf WAN (Default 8302)
  • HTTP API (Default 8500)
  • DNS Interface (Default 8600)

From Consul docs: https://www.consul.io/docs/agent/options.html#ports-used

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问