这里写目录标题
一级目录
二级目录
三级目录
一修改本机host,用于在单机情况下构建伪集群
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 eurekaserver1
127.0.0.1 eurekaserver2
127.0.0.1 eurekaserver3
三个host对应着三个eurekaserver Module
二 集群中各个eurekaserver的配置文件bootstrap.properties
1eureka-server-1
#应用名
spring.application.name=eurekaserver1
#服务端口号
server.port=9001
#eureka服务端实例URL
eureka.instance.hostname=eurekaserver1
#不向服务注册中心注册自己,如果是erueka集群的话,因为自我保护模式,就需要开启自注册了
eureka.client.register-with-eureka=true
#表示自己就是服务注册中心,职责就是维护服务,不去检索服务
eureka.client.fetch-registry=false
#服务中心地址
eureka.client.service-url.defaultZone=http://eurekaserver2:9002/eureka/,http://eurekaserver3:9003/eureka/
#调整保护机制生效的renews 和renews threshold百分比,此配置的百分比会减少 renews threshold的次数
eureka.server.renewal-percent-threshold=0.85
#安全模式访问服务中心,如果服务中心开启安全机制,则客户端的微服务注册请求和心跳机制将会被拦截
#spring.security.user.name=fengbo
#spring.security.user.password=fengbo
2eureka-server-2
#应用名
spring.application.name=eurekaserver2
#服务端口号
server.port=9002
#eureka服务端实例URL
eureka.instance.hostname=eurekaserver2
#不向服务注册中心注册自己,如果是erueka集群的话,因为自我保护模式,就需要开启自注册了
eureka.client.register-with-eureka=true
#表示自己就是服务注册中心,职责就是维护服务,不去检索服务
eureka.client.fetch-registry=false
#服务中心地址
eureka.client.service-url.defaultZone=http://eurekaserver3:9003/eureka/,http://eurekaserver1:9001/eureka/
#调整保护机制生效的renews 和renews threshold百分比,此配置的百分比会减少 renews threshold的次数
eureka.server.renewal-percent-threshold=0.85
#安全模式访问服务中心,如果服务中心开启安全机制,则客户端的微服务注册请求和心跳机制将会被拦截
#spring.security.user.name=fengbo
#spring.security.user.password=fengbo
3eureka-server-3
#应用名
spring.application.name=eurekaserver3
#服务端口号
server.port=9003
#eureka服务端实例URL
eureka.instance.hostname=eurekaserver3
#不向服务注册中心注册自己,如果是erueka集群的话,因为自我保护模式,就需要开启自注册了
eureka.client.register-with-eureka=true
#表示自己就是服务注册中心,职责就是维护服务,不去检索服务
eureka.client.fetch-registry=false
#服务中心地址
eureka.client.service-url.defaultZone=http://eurekaserver2:9002/eureka/,http://eurekaserver1:9001/eureka/
#调整保护机制生效的renews 和renews threshold百分比,此配置的百分比会减少 renews threshold的次数
eureka.server.renewal-percent-threshold=0.85
#安全模式访问服务中心,如果服务中心开启安全机制,则客户端的微服务注册请求和心跳机制将会被拦截
#spring.security.user.name=fengbo
#spring.security.user.password=fengbo
三依赖(三个server都一样)
1eureka-server-1
<?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>FengboSoft</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureka-server-1</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--eureka服务中心依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--cloud分布式配置中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <!– 安全模式依赖 –>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>-->
</dependencies>
</project>
2eureka-server-2
<?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>FengboSoft</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureka-server-2</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--eureka服务中心依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--cloud分布式配置中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <!– 安全模式依赖 –>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>-->
</dependencies>
</project>
3eureka-server-3
<?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>FengboSoft</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureka-server-3</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--eureka服务中心依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--cloud分布式配置中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <!– 安全模式依赖 –>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>-->
</dependencies>
</project>
四集群间通信测试
参数变化:
Renews threshold 1
Renews (last min) 6
五 微服务提供者和集群之间通信测试
1修改配置文件,将交互地址改写成三个集群服务器的地址
#注意不要忘了/eureka/后缀,设置与eureka-server的交互地址
eureka.client.service-url.defaultZone= http://eurekaserver1:9001/eureka/,http://eurekaserver2:9002/eureka/,http://eurekaserver3:9003/eureka/
#应用名
spring.application.name=AccountProvider
#服务器端口
server.port=8001
#配置Mybatis
mybatis.config-location=classpath:mybatisConfig.xml
mybatis.mapper-locations=classpath:mapper/*.xml
#配置数据源bean
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=shuang666
spring.datasource.url=jdbc:mysql://49.235.16.100:3306/springcloud1
spring.datasource.dbcp2.min-idle=5
spring.datasource.dbcp2.initial-size=5
spring.datasource.dbcp2.max-idle=5
spring.datasource.dbcp2.max-wait-millis=200
#配置内置日志logback
logging.config=classpath:logback.xml
#配置单文件上传最大值,#配置多文件请求上传最大值
spring.servlet.multipart.max-file-size=6MB
spring.servlet.multipart.max-request-size=66MB
#分页插件配置,#指定数据库,#分页合理化参数,默认值为false。当该参数设置为 true 时,pageNum<=0 时会查询第一页,#支持通过 Mapper 接口参数来传递分页参数,默认值false
#pagehelper.helper-dialect=mysql
#pagehelper.reasonable=true
#pagehelper.support-methods-arguments=true
#注意不要忘了/eureka/后缀,设置与eureka-server的交互地址,服务注册到集群只需要注册一个即可,因为eureka之间互相注册了
eureka.client.service-url.defaultZone= http://eurekaserver1:9001/eureka/,http://eurekaserver2:9002/eureka/,http://eurekaserver3:9003/eureka/
#eureka的健康检查机制开关
eureka.client.healthcheck.enabled=true
#自我保护机制
#eureka.server.enable-self-preservation=false
#自我保护机制关闭之后的配置,告诉服务端,如果你N秒之后还没有接受到我发送的心跳,就代表我"死"了,将我的服务踢出掉。
#eureka.instance.lease-expiration-duration-in-seconds=36
#设置每隔多少秒给服务中心发送一次心跳,证明自己还活着
#eureka.instance.lease-renewal-interval-in-seconds=6
#springcloud的配置中心开关,SpringCloud默认启动的时候是会先加载bootstrap.properties或bootstrap.yml配置文件,如果没有的话,则会远程从http://localhost:8888获取配置,然后才会加载到application.yml,properties文件。
spring.cloud.config.enabled=false
2服务注册集群测试
参数变化:
Renews threshold 3
Renews (last min) 8