spring cloud之 EurekaServer

只是为了整理代码
(1) pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>TDGiscloud</artifactId>
        <groupId>com.dzjy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>tdcloud-server</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(2) 配置

server:
  port: 8761
  # Redis数据库索引(默认为0)
eureka:
  instance:
    hostname: eureka-server
    prefer-ip-address: true
  client:
    registerWithEureka: false
    fetchRegistry: false
    service-url:
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    name: tdcloudserver

(3) Application

@EnableEurekaServer
@SpringBootApplication
public class TDGISEurakaServer {
    public static void main(String[] args) {
        SpringApplication.run(TDGISEurakaServer.class, args);
    }
}

(4) 高可用Eureka Server 集群 处理体量比较大的微服务集群
4.1 需要修改application.yml 配置,在配置中采用profile的格式

 ---
 server:
      port: 8761
      # Redis数据库索引(默认为0)
    eureka:
      instance:
        hostname:peer1
      client:
        service-url:
          defaultZone: http://peer1:8761/eureka/
    spring:
      profiles:peer1
      ----
    server:
  			port: 8762
 	eureka:
  		instance:
    		hostname: peer2
 	client:
		service-url:
      		defaultZone: http://peer2:8762/eureka/
  	spring:
      	profiles:peer2

4.2 修改hosts 文件 添加 127.0.0.1 peer1 127.0.0.1 peer2
4.3 启动jar 配置 spring.profiles.active=peer1 spring.profiles.active=peer2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值