我的健康检测始终是失败的,服务器也可以ping通本地,这是什么原因呢?
func Register(address string, port int, name string, tags []string, id string) error {
cfg := api.DefaultConfig()
cfg.Address = "192.168.1.8:8500"
client, err := api.NewClient(cfg)
if err != nil {
panic(err)
}
//生成对应的检查对象
check := &api.AgentServiceCheck{
HTTP: "http://192.168.1.6:8021/health",
Timeout: "5s",
Interval: "5s",
DeregisterCriticalServiceAfter: "10s",
}
//生成注册对象,
registration := new(api.AgentServiceRegistration)
registration.Name = name
registration.ID = id
registration.Port = port
registration.Tags = tags
registration.Address = address
registration.Check = check
err = client.Agent().ServiceRegister(registration)
if err != nil {
panic(err)
}
return nil
}
func main() {
_ = Register("192.168.1.6", 8021, "user-web", []string{"mxshop", "duhf"}, "user-web")
}
59
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星