1,概念:尤里卡-云端服务发现,一个基于剩下的服务,用于定位服务,以实现云端中间层服务发现和故障转移。
2,,搭建:,首先讲下单机搭建,先新建一个maven项目,在pom里面导入尤里卡的坐标:
,,,,,,,,,,,,,,,,,,& lt; dependencies>
,,,,,,,,,,,,,,,,,,,, & lt; parent>
,,,,,,,,,,,,,,,,,,,,,,& lt; groupId> org.springframework.boot
,,,,,,,,,,,,,,,,,,,,,,& lt; artifactId> spring-boot-starter-parent
,,,,,,,,,,,,,,,,,,,,,,& lt; version> 1.4.0.RELEASE
,,,,,,,,,,,,,,,,,,,,,& lt;/parent>
,,,,,,,,,,,,,,,,,,& lt; dependency>
,,,,,,,,,,,,,,,,,,,& lt; groupId> org.springframework.cloud
,,,,,,,,,,,,,,,,,,,& lt; artifactId> spring-cloud-starter-eureka-server
,,,,,,,,,,,,,,,,,,& lt;/dependency>
,,,,,,,,,,,,,,,,,,& lt;/dependencies>
,,,,,,,,b,新建类EurekaApplication
,,,,,,,,,,,,,,,,,,,,,,,, @SpringBootApplication
,,,,,,,,,,,,,,,,,,,,,,,, @EnableEurekaServer
,,,,,,,,,,,,,,,,,,,,,,,,公开课EurekaApplication {
,,,,,,,,,,,,,,,,,,,,,,,,,公共静态void main (String [] args) {
,,,,,,,,,,,,,,,,,,,,,,,,,,SpringApplication.run (EurekaApplication.class, args);
,,,,,,,,,,,,,,,,,,,,,,,,,}
,,,,,,,,,,,,,,,,,,,,,,,,}
,,,,,,,,,,其中@EnableEurekaServer,启动一个服务注册中心提供给其他应用进行对话
,,,,,,,,c, application.properties的配置项
,,,,,,,,,,#默认的端口server.port=8761,
,,,,,,,,,,eureka.client.register-with-eureka=false
,,,,,,,,,,eureka.client.fetch-registry=false
,,,,,,,,,,eureka.client.serviceUrl.defaultZone=http://localhost: $ {server.port}/尤里卡/
,,,,,,,d,启动springboot,并访问http://localhost: 8761/
3,上面只是单机模式环境,商用环境往往是要高可用(HA)的环境,这个时候就要考虑集群,一个节点挂了,还有另外一个节点,集群我们只要改下配置文件就可以了
eureka.client.serviceUrl.defaultZone=http://localhost: 8762/尤里卡;http://localhost: 8763/尤里卡;如果ip不同,配置三个节点,则需要三台机器