Client Boot.kt:
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableDiscoveryClient
@RefreshScope
class Boot
fun main(args: Array<String>) {
SpringApplication.run(Boot::class.java, *args)
}
客户端application.yml:
eureka:
instance:
non-secure-port-enabled: false
secure-port-enabled: true
secure-port: ${server.port}
hostname: ${this.hostname}
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
服务器Boot.kt
@SpringBootApplication
@EnableEurekaServer
class Boot
fun main(args: Array<String>) {
SpringApplication.run(Boot::class.java, *args)
}
服务器application.yml:
eureka:
instance:
hostname: $(this.hostname)
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: ${alternate.registry}
我们使用docker swarm运行微服务。我们有两个注册表对等端知道的实例。一个带有端口8301的外部8761内部,另一个带有8351的外部,8762内部。首先,将备用注册表设置为http://registry-2:8762/eureka。第二,将备用注册表设置为http://registry:8761/eureka。
我们的客户端会根据需要动态扩展和缩小。通常在60-80个副本之间。全部在端口30000外部,8081内部。使用docker service scale
命令完成缩放。我们的集群有150多个服务器。
我们在注册表Web界面中注意到,客户端仅注册为单个应用程序。我们还注意到,如果将规模减少1个副本,则拆分下来的副本将注销该服务,将其从注册表中删除,然后另一个实例在几秒钟内重新注册。
尽管有时我们会启动并准备好很多服务,但注册表有时还是会将该服务报告为“ DOWN”。其他服务找不到停机服务,最终导致错误。
我们发现的唯一解决方法是在发生这种情况时重新启动所有副本。
但是为什么会这样呢?客户端不会崩溃或以任何方式出错。