Construcción de proyectos mano a mano
- Seleccionar espejo
- Escribir la configuración de mvn
- Elija Eureka Server
Construcción de un solo nodo
- Agregue la anotación @EnableEurekaServer a la clase de inicio
package com.bl.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* @autor BarryLee
*/
@SpringBootApplication
@EnableEurekaServer
public class LearnEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(LearnEurekaApplication.class, args);
}
}
- Escribe el archivo de configuración application.properties, yo uso propiedades, lo mismo con yml
#这个和service-url一致,否则会发现unavailable
server.port=7900
#是否将自己注册到Eureka Server,默认为true,由于当前就是server,故而设置成false,表明该服务不会向eureka注册自己的信息
eureka.client.register-with-eureka=false
#是否从eureka server获取注册信息,由于单节点,不需要同步其他节点数据,用false
eureka.client.fetch-registry=false
#设置服务注册中心的URL,用于client和server端交流
eureka.client.service-url.defaultZone=http://localhost:7900/eureka/
3. Inicie, luego abra http: // localhost: 7900 /
Construcción de clústeres de alta disponibilidad
- Modifique el archivo de host, la ubicación de win10 es: C: \ Windows \ System32 \ drivers \ etc
host文件末尾加上
127.0.0.1 eureka-7900
127.0.0.1 eureka-7901
127.0.0.1 eureka-7902
- Sobre la base de las operaciones anteriores, agregue un archivo application-eureka-7900.properties
#web端口,服务是由这个端口处理rest请求的
server.port=7900
#是否将自己注册到其他Eureka Server,默认为true 需要
eureka.client.register-with-eureka=true
#是否从eureka server获取注册信息, 需要
eureka.client.fetch-registry=true
#设置服务注册中心的URL,用于client和server端交流
#此节点应向其他节点发起请求
eureka.client.serviceUrl.defaultZone=http://eureka-7901:7901/eureka/,http://eureka-7902:7902/eureka/
#主机名,必填
eureka.instance.hostname=eureka-7900
management.endpoint.shutdown.enabled=true
- application-eureka-7901.properties
#web端口,服务是由这个端口处理rest请求的
server.port=7901
#是否将自己注册到其他Eureka Server,默认为true 需要
eureka.client.register-with-eureka=true
#是否从eureka server获取注册信息, 需要
eureka.client.fetch-registry=true
#设置服务注册中心的URL,用于client和server端交流
#此节点应向其他节点发起请求
eureka.client.serviceUrl.defaultZone=http://eureka-7900:7900/eureka/,http://eureka-7902:7902/eureka/
#主机名,必填
eureka.instance.hostname=eureka-7901
management.endpoint.shutdown.enabled=true
- application-eureka-7902.properties
#web端口,服务是由这个端口处理rest请求的
server.port=7902
#是否将自己注册到其他Eureka Server,默认为true 需要
eureka.client.register-with-eureka=true
#是否从eureka server获取注册信息, 需要
eureka.client.fetch-registry=true
#设置服务注册中心的URL,用于client和server端交流
#此节点应向其他节点发起请求
eureka.client.serviceUrl.defaultZone=http://eureka-7900:7900/eureka/,http://eureka-7901:7901/eureka/
#主机名,必填
eureka.instance.hostname=eureka-7902
management.endpoint.shutdown.enabled=true
- En este punto, está construido y luego está en funcionamiento.
Copia tres
Perfil especificado
Los otros dos son iguales
Luego confirme, inicie estos tres servicios, habrá errores en el medio, porque se están registrando entre sí, y otros servicios no han estado activos, abra después de levantarse: http: // localhost: 7900 /, debe estar seguro , no disponible debe estar vacío