One, dependence
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <version>2.0.0.RC1</version> </dependency>
Second, the start-up class added annotations
@SpringBootApplication@EnableEurekaServerpublic class ServiceRegisterCenterDemoApplication { public static void main(String[] args) { SpringApplication.run(ServiceRegisterCenterDemoApplication.class, args); }}
Three, single-Machine registration center Configuration
spring.application.name=service-register-center-demoserver.port=19001eureka.instance.hostname=localhosteureka.instance.app-group-name=test_groupeureka.instance.appname=register_centereureka.instance.health-check-url-path=/healtheureka.instance.status-page-url-path=/statuseureka.client.enabled=trueeureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
The situation of the service can be accessed through http://localhost:19001/, as shown below:
Check your health check by Http://localhost:19001/actuator.
Attention:
- eureka.instance.appname corresponding to the page panel, instaces under the application name;
- Eureka.client.register-with-eureka=false Indicates that the instance is not registered with the service center. Instead, it is registered. Can be viewed through the Instances list in the Panel;
- Eureka.client.fetch-registry=false Indicates whether the list of services is pulled from the registry;
- For a stand-alone registry, there are no backup (copy) nodes. In the panel, the Registered-replicas, Unavailable-replicas, Available-replicas three items under General info are empty.
- As you can see, the Registration Service center can also be a client, you can also register their own instances to the service center.
Iv. multiple peer Registration center configurations
Instance 1
spring.application.name=service-register-center-demoserver.port=19001eureka.instance.hostname=peer1eureka.instance.app-group-name=test_groupeureka.instance.appname=register_center1eureka.instance.health-check-url-path=/healtheureka.instance.status-page-url-path=/status#eureka.client.enabled=trueeureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://peer2:19001/eureka/
Instance 2
spring.application.name=service-register-center-1-demoserver.port=19002eureka.instance.hostname=peer2eureka.instance.app-group-name=test_groupeureka.instance.appname=register_center2eureka.instance.health-check-url-path=/healtheureka.instance.status-page-url-path=/status#eureka.client.enabled=trueeureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://peer1:19002/eureka/
Attention:
- For single-machine configuration multi-peer node, need to modify the Hosts file;
- Unlike a stand-alone configuration,Eureka.client.serviceUrl.defaultZone needs to be configured and can be configured with multiple (comma separated)
Five, configuration parameter description
- Eureka.instance.hostname can not be set. The default is the hostname in serviceurl, such as: localhost
- Eureka.client.serviceUrl.defaultZone can use eureka.instance.hostname, can also set the IP directly;
- Eureka.instance.appname represents the instance name. Also can not set, then use the value of spring.application.name;
- Eureka.client.register-with-eureka=false Indicates that the instance is not registered with the service center. Instead, it is registered. Can be viewed through the Instances list in the Panel;
- Eureka.client.fetch-registry=false Indicates whether the list of services is pulled from the registry;
The service side of Spring Cloud Eureka