eureka记录
eureka如何设置注册中心?
第一步
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
第二步
//使用注解,设置为euruka的服务端
@EnableEurekaServer
@SpringBootApplication
public class MyEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(MyEurekaServerApplication.class, args);
}
}
第三步
eureka:
instance:
prefer-ip-address: true
ip-address: 172.30.3.108
instance-id: 172.30.3.108:${spring.application.name}:${server.port}
client:
#是否将自己注册到Eureka Server,默认为true,由于当前就是server,
#故而设置成false,表明该服务不会向eureka注册自己的信息
register-with-eureka: false
#是否从eureka server获取注册信息,由于单节点,不需要同步其他节点数据,用false
fetch-registry: false
#设置服务注册中心的URL,用于client和server端交流,不能写localhost否则注册不上去
service-url:
defaultZone: http://172.30.3.108:7901/eureka
server:
port: 7901
spring:
application:
name: "base_server"
eureka注册服务,也就是客户端
第一步
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
第二步
eureka:
#默认使用主机名称,这么设置可以使用IP地址进行注册服务
instance:
prefer-ip-address: true
ip-address: 172.30.3.108
instance-id: 172.30.3.108:${spring.application.name}:${server.port}
client:
register-with-eureka: true
fetch-registry: true
enabled: true
service-url:
defaultZone: http://172.30.3.108:7901/eureka
server:
port: 9901
#name要写,否则Application都是默认值
spring:
application:
name: "base"
以上是 eureka记录 的全部内容, 来源链接: utcz.com/z/518935.html