SpringCloud service discovery -Eureka

1, Eureka server cluster development

  1, first create a parent project

    If not an ordinary demo, there are other configuration, you need to pay attention if the service is probably not open up dependent parent may be required <dependencyManagement> label.

  2, create two sub-projects

    1, import-dependent

     <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>

  2, the configuration file application.yml

# Built-in tomcat service start listening port number
server:
  port: 6002

#EurekaServer Configuration
eureka:
  instance:
    hostname: eureka6002 #EurekaServer name
  client:
    the Register the -with-Eureka: false # This EurekaServer not registered to other registries
    FETCH -registry: false        # server is not pulling information from other centers Center
    service-url:
      defaultzone: HTTP: // eureka6001.com:6001/eureka # registry access address 

-------------------------------- -------
# Built-in tomcat service start listening port number 
Server:
Port: 6001
#EurekaServer configuration
Eureka:
instance:
hostname: eureka6001
Client:
the Register-with-Eureka: false # This EurekaServer not registered to other registries
fetch-registry: false # is not pulls information from other central server center
Service-url:
defaultzone: http://eureka6002.com:6002/eureka # registry access address
 

  3, the master boot class

@SpringBootApplication // This is the main startup class mark
@EnableEurekaServer // mark which is EurekaServer
public class AppStart2 {

    public static void main(String[] args) {
        SpringApplication.run(AppStart2.class, args);
    }
}

2, micro-service configuration

  1, introducing dependent, dependent on the above

  2, the configuration added application.yml

eureka:
  client:
    the Register the -with-Eureka: to true # allowed to register to EurekaServer
    FETCH -registry: to true        # server pulls information from other centers Center
    service-url:
      defaultzone: HTTP: // eureka6002.com:6002/eureka, http://eureka6001.com : 6001 / Eureka # to access the registry

  3, the master boot class

@SpringBootApplication
@EnableEurekaClient // mark this is a Euerka client, you must write
public class ProductProvider_8001 {
    public static void main(String[] args) {
        SpringApplication.run(ProductProvider_8001.class,args);
    }
}

3, start the project

  Visit http: // localhost: 6001 / and http: // localhost: 6002 / 

 

 

  This is a demo, a lot of shortcomings, such as: when the status hover below, in the lower left corner to see the IP.

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/xueziyeya/p/11816404.html