SpringCloud集群(三)

一、构造步骤

1、进行其他的服务中心的域名映射

127.0.0.1 eureka7001.com

127.0.0.1 eureka7002.com

127.0.0.1 eureka7003.com

2、修改microservicecloud-eureka-7001 yml文件

server:
  port: 7001
  ###eureka 基本信息配置
eureka:
  instance:
        ###注册到eurekaip地址
    hostname: eureka7001.com #eureka服务端的实例名称
  client:
    service-url:
      defaultZone:  http://localhost:7002/eureka/,http://localhost:7003/eureka/
        ###因为自己是为注册中心,不需要自己注册自己
    register-with-eureka: false #表示不像注册中心注册自己
    ###因为自己是为注册中心,不需要检索服务
    fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务

3、microservicecloud-eureka-7002 eureka服务注册中心Module 

新建工程microservicecloud-eureka-7002,创建完成后请回到父工程查看pom文件变化

pom文件

<dependencies>
<!--eureka-server服务端-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>
</dependencies>

yml文件

server:
  port: 7002
  ###eureka 基本信息配置
eureka:
  instance:
        ###注册到eurekaip地址
    hostname: eureka7002.com #eureka服务端的实例名称
  client:
    service-url:
      defaultZone:  http://localhost:7001/eureka/,http://localhost:7003/eureka/  #单机  设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址(单机)。
        ###因为自己是为注册中心,不需要自己注册自己
    register-with-eureka: false #表示不像注册中心注册自己
    ###因为自己是为注册中心,不需要检索服务
    fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务

主启动类

@SpringBootApplication
@EnableEurekaServer // EurekaServer服务器端启动类,接受其它微服务注册进来
public class SpringCloudService7002_APP {

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

4、microservicecloud-eureka-7003 eureka服务注册中心Module 

新建工程microservicecloud-eureka-7003,创建完成后请回到父工程查看pom文件变化

 pom文件

<dependencies>
        <!--eureka-server服务端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

yml文件

server:
  port: 7003
  ###eureka 基本信息配置
eureka:
  instance:
        ###注册到eurekaip地址
    hostname: eureka7003.com #eureka服务端的实例名称
  client:
    service-url:
      defaultZone:  http://localhost:7002/eureka/,http://localhost:7003/eureka/
        ###因为自己是为注册中心,不需要自己注册自己
    register-with-eureka: false #表示不像注册中心注册自己
    ###因为自己是为注册中心,不需要检索服务
    fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务

 启动主启动类

@SpringBootApplication
@EnableEurekaServer // EurekaServer服务器端启动类,接受其它微服务注册进来
public class SpringCloudService7003_APP {

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

 5、启动测试

http://eureka7002.com:7002/,

http://eureka7001.com:7001/,

http://eureka7003.com:7003/

效果:

 

posted @ 2019-04-02 21:51  吊儿郎当小少年  阅读(300)  评论(0编辑  收藏  举报