1.建立module
2.引入依赖
<dependencies>
<!--eureka server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--引入自己定义的api通用包,可以使用payment支付Entity-->
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
<!--boot web actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--一般通用配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
3.创建application.yml
server:
port: 7001
eureka:
instance:
hostname: localhost #eureka服务端的实例名称
client:
#false表示不向注册中心注册自己
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
defaultZ4 one: http://${eureka.instance.hostname}:${server.port}/eureka/
4.主启动
5.单机Eureka构建:支付微服务8001入驻进eurekaServer
将 Eureka-client 依赖引入,便于使用注解@EnableEurekaClient标注这是个Eureka Client端
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
6.改写8001的yml
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true
register-with-eureka: true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetch-registry: true
service-url:
defaultZone: http://localhost:7001/eureka
7.增加8001主启动的注解
@EnableEurekaClient
eureka集群原理说明
集群环境构造
已经有7001,现在在建个7002
1.建Module
2.粘pom
3.创建yml
互相注册,相互守望就体现在yml这步
改7001的yml
server:
port: 7001
eureka:
instance:
hostname: eureka7001.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
#集群指向其它eureka
defaultZone: http://eureka7002.com:7002/eureka/
一样的配置改7002的yml
4.主启动,和7001一样
5.增加微服务
改8001和80的yml
http://eureka7001.com:7001/eureka, http://eureka7002.com:7002/eureka
支付微服务集群配置
1.将8001的配置,类全部拿到8002中
2.改controller
3.发现没有实现负载均衡
要去把ordercontroller的url改变
这样之后会出现whitelabel
因为没有开启负载均衡,有很多端口不知该选择哪个端口
actuator微服务信息完善
1.去掉主机名称,不暴露主机名2.ip显示
实现功能1做法:
增加instance
实现功能2做法
服务发现discovery
加主启动的注解@EnableDiscoveryClient
自我保护理论
怎么禁止自我保护