zoukankan      html  css  js  c++  java
  • 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/

    效果:

  • 相关阅读:
    Fedora 19安装Fcitx输入法并安装搜狗输入法资源包
    mac 功能修改。。。。
    Zend Studio / Ecliplse插件StartExplorer
    关于更改apache和mysql的路径的问题..
    解决fedora64下vim不能语法着色问题
    正则例一
    PHP中使用正则表达式详解 preg_match() preg_replace() preg_mat
    C语言正则表达式详解 regcomp() regexec() regfree()详解
    正则19-20
    正则表达式教程:30分钟让你精通正则表达式语法
  • 原文地址:https://www.cnblogs.com/cxyyh/p/10645663.html
Copyright © 2011-2022 走看看