Eureka集群搭建——学习笔记

  1. 创建三个model:cloud-eureka-server7001,cloud-eureka-server7002,cloud-eureka-server7003

  2. 改pom文件

  3. 修改系统映射配置

  4. 改yml文件

  5. 主启动

 

一、创建三个Eureka server的model,cloud-eureka-server7001,cloud-eureka-server7002,cloud-eureka-server7003,

二、修改pom文件,

    <dependencies>
        <!-- Eureka server-->
        <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-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!-- 引入自己定义的api通用包,可以使用Payment支付entity -->
        <dependency>
            <groupId>com.niucheng.springcloud</groupId>
            <artifactId>cloud-api-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>



    </dependencies>

三、修改系统映射配置

 在host文件中加入以下配置,注意:IP地址后面的域名要与appliaction.yml中的hostname对应

127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
127.0.0.1 eureka7003.com

四、改yml文件

cloud-eureka-server7001的appliaction.yml

  注意:多个Eureka集群时,defaultZone的需要用逗号隔开

server:
  port: 7001
eureka:
  instance:
    hostname: eureka7001.com #Eureka服务端的实例名称
  client:
    register-with-eureka: false #flase 表示不向注册中心注册自己
    fetch-registry: false #false 表示自己端就是注册中心,我的职责就是维护服务实例,并不需要检索服务
    service-url:
      #设置与Eureka server交互的地址查询服务和注册服务都需要依赖的地址
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/

cloud-eureka-server7002的appliaction.yml         

server:
  port: 7002
eureka:
  instance:
    hostname: eureka7002.com #Eureka服务端的实例名称
  client:
    register-with-eureka: false #flase 表示不向注册中心注册自己
    fetch-registry: false #false 表示自己端就是注册中心,我的职责就是维护服务实例,并不需要检索服务
    service-url:
      #设置与Eureka server交互的地址查询服务和注册服务都需要依赖的地址
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/

cloud-eureka-server7003的appliaction.yml         

server:
  port: 7003
eureka:
  instance:
    hostname: eureka7003.com #Eureka服务端的实例名称
  client:
    register-with-eureka: false #flase 表示不向注册中心注册自己
    fetch-registry: false #false 表示自己端就是注册中心,我的职责就是维护服务实例,并不需要检索服务
    service-url:
      #设置与Eureka server交互的地址查询服务和注册服务都需要依赖的地址
      #defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7001.com:7001/eureka/

五、主启动

注意:主启动需要加上@EnableEurekaServer 注解

package com.niucheng.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7001 {

    /**
     * http://localhost:7001/
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(EurekaMain7001.class,args);
    }
}

六、测试

 在浏览器中输入 

http://eureka7001.com:7001/

http://eureka7002.com:7002/

http://eureka7003.com:7003/

都可以访问页面,不同之处是 DS Replicas指向的服务不同。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值