服务中心【单机版】
pom文件:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
启动类:
@SpringBootApplication
@EnableEurekaServer //启用 eureka server 相关默认配置
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
配置文件:
server:
port: 8080
spring:
application:
name: eureka-server
eureka:
instance:
hostname: localhost
client:
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
register-with-eureka: false #仅作为服务中心,不作为服务客户端
fetch-registry: false #不从服务中心检索注册的服务
server:
eviction-interval-timer-in-ms: 5000 # 清理间隔(ms)
enable-self-preservation: true # 自我保护
renewal-percent-threshold: 0.1 # 默认0.85, 在运行期间会去统计心跳失败比例在 15 分钟之内是否低于 85%
启动服务,访问 服务中心,地址:http://localhost:8080
单机版结束!
但是,单点服务哪里够用啊,必须集群化,才稳定
来干吧,兄弟!!!
服务中心【集群版】
三个工程,idea工具只需要生成三分配置文件即可;
application-server1.yml
server:
port: 8081
spring:
application:
name: eureka-server
eureka:
instance:
hostname: localhost
client:
service-url:
defaultZone: http://${eureka.instance.hostname}:8081/eureka/,http://${eureka.instance.hostname}:8082/eureka/,http://${eureka.instance.hostname}:8083/eureka/
register-with-eureka: false #仅作为服务中心,不作为服务客户端
fetch-registry: false #不从服务中心检索注册的服务
server:
eviction-interval-timer-in-ms: 5000 # 清理间隔(ms)
enable-self-preservation: true # 自我保护
renewal-percent-threshold: 0.49 # 心跳失败比例
application-server2.yml
application-server3.yml
记得改端口,兄弟!!!
配置三套服务:
然后依次启动
成功启动后,访问http://localhost:8081/,http://localhost:8082/,http://localhost:8083/
网友评论