springcloud环境下eureka配置
一、eureka配置
二、spring cloud config配置中心
纯属个人学习笔记记录,加深理解
1.引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.启动类上配置
@EnableEurekaServer
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer/*主要是加这个配置注解*/
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
3.创建application.yml配置文件
spring:
profiles:
active: eureka1
4.实现负载均衡,创建application-eureka1.yml,ps:如需三个eureka,则在defaultZone后添加
eureka:
client:
service-url:
#连接另一个eureka,实现负载均衡
defaultZone: http://localhost:8762/eureka/
server:
enable-self-preservation: false
spring:
application:
name: eureka
server:
port: 8761
5.访问http://localhost:8761/ 出现以下界面,则表示配置成功
6.这时控制台一直报错,是因为找不到eureka2,这时我们只需要idea 启动多一个eureka2,如下图所示
7.两个eureka都启动之后,会相当于负载均衡配好了,访问http://localhost:8762/ 效果如下图
代码地址:https://gitee.com/suxijiang/springcloud_practice
选择eureka模块下载即可