因为项目配置往往是应用的组成部分,如果配置中心挂掉了,那么往往可能会导致整个应用给挂掉,所以这个时候,就要避免
所谓的单点问题,也就是一个服务其中一个节点挂了,还有其他的节点提供服务,从而提供高可用的目的。
https://github.com/unnunique/SpringCloundDakaLearning/tree/master/Chapter-7
https://github.com/unnunique/SpringCloundDakaLearning/tree/master/Chapter-1
注册中心的配置,参见第6章。
https://github.com/unnunique/SpringCloundDakaLearning/tree/master/Chapter-6
思路是把配置中心配置到注册中心去。
然后启动多个服务,组成一个集群。
主要是添加了如下配置:
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
dependency>
<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>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.1.4.RELEASEversion>
<relativePath/>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>Config-ServerartifactId>
<properties>
<java.version>1.8java.version>
<spring-cloud.version>Greenwich.SR1spring-cloud.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-config-serverartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>${spring-cloud.version}version>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
spring.application.name=config-server
server.port=8889
spring.cloud.config.server.git.uri=https://github.com/unnunique/SpringCloundDakaLearning
spring.cloud.config.server.git.searchPaths=Chapter-6/config-center
spring.cloud.config.label=master
spring.cloud.config.server.git.username=
spring.cloud.config.server.git.password=
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.default-zone=http://${eureka.instance.hostname}:${server.port}/eureka/
如本章的:Chapter7-Client
注意原先的是:#spring.cloud.config.uri= http://localhost:8888/
现在直接改成:spring.cloud.config.discovery.service-id=config-server
spring.application.name=app1
server.port=8881
spring.cloud.config.label=master
spring.cloud.config.profile=dev
#spring.cloud.config.uri= http://localhost:8888/
spring.cloud.config.discovery.service-id=config-server
spring.cloud.config.request-read-timeout=6000000
management.endpoints.web.exposure.include=refresh
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.default-zone=http://${eureka.instance.hostname}:${server.port}/eureka/
https://github.com/unnunique/SpringCloundDakaLearning/tree/master/Chapter-2
启动注册中心, 启动多个应用,模拟部署多个节点,使得服务组成一个集群【参见第二章:https://github.com/unnunique/SpringCloundDakaLearning/tree/master/Chapter-2】。
启动后如下:
然后启动client服务:
访问如下:
http://localhost:8881/hi
然后kill 掉其中一个节点的服务。 如下:
再次访问,还可以进行访问,如下: