Service registration and discovery -Eureka

A: Eureka Introduction

  Eureka mean (because I found something, especially answers to your questions and happy) I found, I found , as the name of a service registration and discovery center is indeed very appropriate ah.

  Eureka consists of two components, Eureka Server and Eureka Client, Eureka Server provides the ability to service discovery, in fact, be understood as registered more suitable, because Eureka Server will not take the initiative to seek discovery, but each micro service startup, to register with the Eureka Server own information, such as IP address, port number, service name, and so on, information services micro Eureka Server will be stored. After the micro service starts, it will periodically (default 30s) sends a heartbeat to the Eureka Server to renew their lease. If Eureka Server within a certain time (default 90s) did not receive a heartbeat micro services will cancel the micro service instance.

  By default, Eureka Server is also the Eureka Client, by way of replication, to achieve synchronization between multiple micro-services data service registry, Eureka Client will cache service information in the registry, so that the benefits, not every request query Eureka Server, reducing the pressure Eureka Server, but also reduces the delay request. Second, even if Eureka Server is down, consumers are still able to rely on its own cache information, find the service providers to improve system availability. But then there is still Eureka Server downtime, some micro-services appear unavailable situation is not monitored, Eureka Client cache can not be updated, the availability of the system. So to allow the use of cluster Eureka Server high availability.

Two: Eureka Server

  1, rely on the introduction of Eureka: spring-cloud-starter-eureka-server

  2, the startup class add annotations: EnableEurekaServer

  3, the configuration file:

# Stand-alone configuration 
Server: 
    Port: 8761 
Eureka: 
    Client: 
# whether to register themselves on the Server, default true, because the current application is Server, it is set to false 
        registerWihEureka: false  
# whether to obtain registration information from Server, default true, because the current Server is a single node, synchronization is not required registration information, is set to false 
        fetchRegistry: false  
        serviceUrl: 
# Server to interact with the Eureka address, registration and inquiry services are dependent on this address, the address is the default HTTP: // localhost: 8761 / eureka /, you can use multiple addresses, separated by number 
            defaultZong: HTTP: // localhost: 8761 / Eureka / 

# cluster configuration 
# is registered to the Server and whether to obtain registration information from the Server are using the default to true 
the Spring: 
    the Application: 
        name: MicroServer -discovery-eureka- HA 
Server:
    Port:8761 
Eureka: 
    instance: 
        hostname: peer1 
    Client: 
        serviceUrl: 
# registered address of another center of 
            defaultZong: HTTP: // localhost: 8762 / Eureka /  
Server Configuration

Third, the service registration

  1, rely on the introduction of Eureka: spring-cloud-starter-eureka

  2, the startup class add annotations: @EnableDiscoveryClient or @EnableEurekaClient

  3, the configuration file:

# Server is registered and whether to obtain registration information from the Server are using the default to true 
the Spring: 
    the Application: 
# specify the name registered with the Server application 
        name: MicroServer -provider- the User 
Eureka: 
    instance: 
# to register their address to the ip Server, if not configured or set to false, identity hostname registration where the micro-services to the Server 
        the prefer -ip-address: to true 
    Client: 
        serviceUrl: 
address # registry, multiple addresses separated by commas 
            defaultZong: HTTP: / / localhost: 8762 / Eureka /  
Client Configuration

Four: Adding user authentication to Eureka Server

  1, add spring-boot-starter-security-dependent

  2, the configuration file:

#Server configuration 
# If you do not set this content, the default account is the user, the password is a random value, will be printed at startup 
Security: 
    Basic: 
        enable: to true #-based HTTP basic authentication turned on 
    the User: 
        name: the User 
        password: password12 

# Client configuration 
Eureka: 
    Client: 
        serviceUrl: 
            defaultZong: HTTP: // the User: password12 @ localhost: 8761 / Eureka /
Profiles

Fives:

Guess you like

Origin www.cnblogs.com/yanghanwen/p/12081237.html