Eureka 有兩大件 server 和 client
注冊中心就是server 微服務提供這就是client
1.創建注冊中心模塊

2.導入eureka server依賴
<!--eureka-server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.注冊中心的配置文件
server:
port: 7001
eureka:
instance:
hostname: localhost #服務端的實例名稱
client:
#false表示不向服務器注冊自己
register-with-eureka: false
#false表示自己就是注冊中心 去維護服務實例 不需要去檢索服務
fetch-register: false
#設置與Enreka server交互的地址查詢服務和注冊服務都需要這個地址
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
3.開啟eureka注冊中心服務

4.訪問7001端口 創建成功

5.讓微服務-支付模塊在注冊中心注冊 成為一個eurekaclient 導入依賴 注意是client
<!--eureka-client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
6.在application.yml配置eurekaclient 這里的application-name就會是eureka實例的名稱
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/db2019?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
username: root
password: 1234
mybatis:
mapper-locations: classpath:mapper/*.xml #配置文件
type-aliases-package: com.lyx.cloud.entities #所有entity別名所在包
eureka:
client:
register-with-eureka: true #自己注冊到eureka 默認true
#是否從eureka抓取已有的注冊信息 默認為true 單節點無所謂 集群必須為true 才能配合ribbon使用負載均衡
fetch-registry: true
service-url:
defaultZone: http://localhost:7001/eureka #注冊中心地址
7.開啟功能

8.運行支付模塊 在瀏覽器查看是否增加了一個實例 注冊成功
