【springCloud基础篇-12】Spring Cloud Config 配置中心之高可用
接上篇文章:https://mp.****.net/postedit/103089572
所谓高可用也是保证客户端调用服务端的时候能正常调用。解决方案就是服务端做成集群方式。
首先修改server项目
启动类添加注解: @EnableDiscoveryClient
接下来就是把服务端做成多个项目进行注册中心注册。这里我简单粗暴一点,复制项目文件夹,文件夹名称修改为:spring-cloud-config-server22
IDEA打卡该server22项目。
修改application.yml配置文件:
server: port: 9022 eureka: client: service-url: defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/,http://peer3:8002/eureka/ spring: application: name: spring-cloud-config-server profiles: active: native
修改native-mysql.properties文件内容:
native.hello=hello_i_im_mysql_update
分别启动server项目与server22项目,打开注册中心,查看:
注册中心配置成功。
接下来就是修改客户端项目。
首先client项目启动类添加注解:@EnableDiscoveryClient
修改application.yml文件:
server: port: 9021 spring: application: name: spring-cloud-config-client management: security: enabled: false #springboot 1.5.X以上默认开通了安全认证
注意这里没有了注册中心的配置。
修改bootstrap.yml文件:
spring: cloud: config: discovery: enabled: true serviceId: spring-cloud-config-server # uri: http://localhost:9020/ name: native profile: mysql lable: master eureka: client: service-url: defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/,http://peer3:8002/eureka/
注册中心迁移到这里来了,特别注意,删除了uri,修改为了
discovery:
enabled: true
serviceId: spring-cloud-config-server
这个非常重要。
接下来启动client项目。
访问:http://localhost:9021/hello
返回的是
native.hello=hello_i_im_mysql_update
然后我们手动将server项目关闭。
打开cmd命令窗口,执行:curl -X POST http://localhost:9021/refresh
已经刷新了配置文件,然后再次访问 http://localhost:9021/hello
OK完成