Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Server of spring cloud eureka

Shulou Source: shulou.com Published: 2022-06-02 20:55:39 10月04日 Update

I. Dependency

org.springframework.cloud spring-cloud-starter-netflix-eureka-server 2.0.0.RC1

II. Add comments to startup class

@SpringBootApplication@EnableEurekaServerpublic class ServiceRegisterCenterDemoApplication { public static void main(String[] args) { SpringApplication.run(ServiceRegisterCenterDemoApplication.class, args); }}

III. Configuration of stand-alone registry

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/

You can access the service through http://localhost:19001/. Below:

Check health checks at http://localhost:19001/actuator.

Note:

eureka.instance.appname corresponds to the application name under instances in the web panel;eureka.client.register-with-eureka=false indicates that this instance will not be registered to the service center. Otherwise, it will be registered. This can be viewed through the instances list in the dashboard;eureka.client.fetch-registry=false indicates whether the list of services is pulled from the registry; for a stand-alone registry, whether there is no backup (replication) node. In the panel, registered-replicas, available-replicas and available-replicas under General Info are all empty. It can be seen that the registration service center can also be a client, and you can also register your own instance to the service center.

IV. Configuration of multiple peer registries

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/

Note:

For a stand-alone configuration with multiple peer nodes, the hosts file needs to be modified; different from the stand-alone configuration, eureka.client.serviceUrl.defaultZone needs to be configured with each other, and multiple (comma separated) can be configured.

V. Description of configuration parameters

eureka.instance.hostname can be left unset. By default, it will be the host name in serviceUrl, such as localhosteureka.client.serviceUrl.defaultZone. eureka.instance.hostname can be used, or IP can be set directly;eureka.instance.appname indicates the instance name. It can also be omitted, and the value of spring.application.name is used;eureka.client.register-with-eureka=false means that this instance will not be registered to the service center. Otherwise, it will be registered. This can be viewed through the instances list in the dashboard;eureka.client.fetch-registry=false indicates whether to pull the service list from the registry;

Tags: Service configuration stand-alone service center panel can pass multiple situation different health host from parameter name backup instance file annotation web page node Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB OPPO Reno Shulou Technology Shulou Tech Info