1. Build a project with idea:
use spring initializr:
and then create a server or client as shown in the figure. One thing to note : Eureka Server integrates web dependencies, but the client does not, so if you create a client, you must add web dependencies, otherwise it will not start!
Server:
1. After the construction project is completed: In the startup class, add a comment: @EnableEurekaServer to
write the configuration file:
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: false #不要把自己也注册进来
server:
enable-self-preservation: false #这里不要自我保护,client下线就直接反映出来。
spring:
application:
name: eureka
server:
port: 8761
Client:
Startup class with annotation: @EnableDiscoveryClient
configuration file plus:
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
# instance:
# hostname: client #这个可以指定client实例对应的url
Here is to register him to the server side just started:
High availability
Two eurekas should be registered like this:
three eurekas:
multiple registrations:
direct comma separated