【发布时间】:2016-08-16 09:19:17
【问题描述】:
我尝试使用他们的 Golang package 启动 Consul 代理。 服务器本身启动,但我无法与之交互,因为它没有开始侦听传入的 HTTP 请求。
我启动代理的代码:
//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)
}
启动时生成的配置如下所示:
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>}
检查我的开放端口,我可以看到代理已启动但未侦听 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
感谢您提供的每个提示:)
【问题讨论】:
-
你试过在 0.0.0.0 上收听吗?
-
您无法在
0.0.0.0上收听。这导致:Failed to get advertise address: Multiple private IPs found. Please configure one.