签约网站做PPT,广州市外贸网站建设服务机构,wordpress 与现有sso,平面设计线上培训机构推荐微服务框架中最为重要的就是注册中心#xff0c;如果只是单注册中心#xff0c;一旦出现问题#xff0c;容易导致整个微服务环境不可用#xff0c;所以建议注册中心集群。
目前SpringCloud框架中使用Eureka作为注册中心#xff0c;本文简单介绍一下Eureka的集群配置…微服务框架中最为重要的就是注册中心如果只是单注册中心一旦出现问题容易导致整个微服务环境不可用所以建议注册中心集群。
目前SpringCloud框架中使用Eureka作为注册中心本文简单介绍一下Eureka的集群配置主要的思路就是相互注册形成一组相互注册的注册中心达到高可用的效果。
一般来说集群配置至少需要2台以上的服务器这里是采用本机测试道理是一样的。
集群配置
依赖配置
parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.3.RELEASE/versionrelativePath/ !-- lookup parent from repository --
/parent!-- 管理依赖 --
dependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversionFinchley.RELEASE/versiontypepom/typescopeimport/scope/dependency/dependencies
/dependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependency
/dependenciesrepositoriesrepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/milestone/urlsnapshotsenabledfalse/enabled/snapshots/repository
/repositories注册中心配置
第一个注册中心配置
# 服务端口号
server:port: 8100
# 服务名称必须一样
springapplicationname: app-eureka
eureka:instance:# 注册中心ip地址(本机地址)hostname: 127.0.0.1client:service-url:# 注册地址注册到9100的注册中心如果是三台以上一样可以在这边添加# 主要是实现相互注册defaultZone: http://127.0.0.1:9100/eureka/ # 将自己注册给自己的注册中心register-with-eureka: true# 检索自己服务信息fetch-registry: false第二个注册中心配置
# 服务端口号
server:port: 9100
# 服务名称必须一样
springapplicationname: app-eurekaeureka:instance:# 注册中心ip地址(本机地址)hostname: 127.0.0.1client:service-url:# 注册地址注册到8100的注册中心如果是三台以上一样可以在这边添加# 主要是实现相互注册defaultZone: http://127.0.0.1:8100/eureka/ # 将自己注册给自己的注册中心register-with-eureka: true# 检索自己服务信息fetch-registry: false启动
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;SpringBootApplication
EnableEurekaServer //开启EurekaServer服务 开启注册中心
public class AppEureka {public static void main(String[] args) {SpringApplication.run(AppEureka.class, args);}
}客户端配置
# 订单服务的端口号
server:port: 8001# 服务别名 -- 服务注册到注册中心名称
spring:application:name: app-ordereureka:client:service-url:# 当前订单服务注册到eureka服务地址,两个注册中心都注册defaultZone: http://localhost:8100/eureka,http://localhost:9100/eureka# 需要将服务注册到eurekaregister-with-eureka: true# 需要检索服务fetch-registry: true客户端启动
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;SpringBootApplication
EnableEurekaClient
public class AppOrder {public static void main(String[] args) {SpringApplication.run(AppOrder.class, args); }
}总结
以上即是Eureka的集群配置还是比较简单易懂的。