Springcloud Eureka Server server configuration

Eureka as a component of service registration and discovery, Eureka2.0 already closed source, but this tutorial is to Eureka as the core expansion.

1, three modules

       Spring Cloud Eureka is one of a suite of services Netflix micro Spring Cloud, based Netflix Eureka made a second package, is responsible for completion of the service management function micro-service architecture.

       three important modules eueka's, Eureka-Server, Service-Provider, Service-Consumer
       Eureka-Server: server, service registration and discovery;
       Eureka-Client-Service-Provider: server, service provider, via http rest informed server registration, update, cancel the service;
       Eureka-client-service-consumer: client, service consumers, need to get the address of a list of services from the server via http rest, and then with some of the load balancing policy (ribbon) to invoke server service. 

2、eureka-server

        Eureka Server service registration data storage layer is double ConcurrentHashMap (thread-safe and efficient Map collection).
        The first layer key = spring.application.name application name is registered client instance; value is nested ConcurrentHashMap.
        Unique instance ID key of the second layer = instanceId i.e. services, value of the object Lease, Lease object store registration information of all of this example, including IP, port, and other properties.
        Declare statement is as follows: 
        Private of ConcurrentHashMap Final <String, the Map <String, Lease <InstanceInfo >>> Registry of ConcurrentHashMap new new = <String, the Map <String, Lease <InstanceInfo >>> ();

 

        Service Registry is not persisted to the database, I think it is right for performance reasons. After all, the registry information is need to regularly get updated.

3. Create a service registry --demo

3.1, dependent on the introduction pom.xml

<dependencies>
          <!--www.1b23.com-->
          <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
        <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
          </dependency>
     </dependencies>

3.2, eureka server startup code    

       //www.1b23.com
       @SpringBootApplication
       @EnableEurekaServer
       public class EurekaServerApplication {             public static void main(String[] args) {                   SpringApplication.run(EurekaServerApplication.class, args);
            }
       }

@EnableEurekaServer main role is to initiate EurekaServer operating environment and context.

3.3, application configuration files

       application configuration file can be xml or yml structure, I prefer xml structure, yml is indented format, I think the easier wrong.

        server.port=8080

        spring.application.name: eureka-server 

        Hostname # service registry instance
       eureka.instance.hostname: localhost

        # Indicates whether to register themselves on EurekaServer, the default is true. Due to the current application is EurekaServer, it is set to false
        eureka.client.register-with-Eureka: false

       #表示表示是否从EurekaServer获取注册信息,默认为true。单节点不需要同步其他的EurekaServer节点的数据


       eureka.client.fetch-registry: false       

       #设置Eureka的地址
       eureka.client.service-url.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

3.4、查看eureka server

       访问http://localhost:8080/地址。如图上部分

        Environment: 环境,默认为test,生产环境建议改下,看着顺眼
        Data center: 数据中心,生产环境建议改下
        Current time:当前的系统时间
        Uptime:已经运行了多少时间
        Lease expiration enabled:是否启用租约过期 ,自我保护机制关闭时,该值默认是true, 自我保护机制开启之后为false。
        Renews threshold: 每分钟最少续约数,Eureka Server 期望每分钟收到客户端实例续约的总数。
        Renews (last min): 最后一分钟的续约数量(不含当前,1分钟更新一次),Eureka Server 最后 1 分钟收到客户端实例续约的总数。

        

        页面下部分:

 

 

    total-avail-memory : 总共可用的内存
    environment : 环境名称,默认test 
    num-of-cpus : CPU的个数
    current-memory-usage : 当前已经使用内存的百分比
    server-uptime : 服务启动时间
    registered-replicas : 相邻集群复制节点
   unavailable-replicas :不可用的集群复制节点,   

    available-replicas :可用的相邻集群复制节点

    ipAddr:eureka服务端IP
    status:eureka服务端状态


Guess you like

Origin blog.51cto.com/14622073/2470235