日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

服务注册中心 eureka 搭建

發布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 服务注册中心 eureka 搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

服務注冊中心,netfix公司的,出道即巔峰,可惜沒人維護了。
1.x 可用,2.x 使用后果自負。本文講eureka服務中心的搭建,分為單機版本和eureka集群版本。以及服務消費者,服務提供者如何入駐注冊中心。

eureka

    • eureka pom
    • eureka 服務server端的注冊中心, single
    • eureka的集群搭建
    • 客戶端如何入駐eureka集群
    • eureka的自我保護機制

eureka pom

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>cloud2020</artifactId><groupId>top.bitqian</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><!-- 127.0.0.1 eureka7001.com --><artifactId>cloud-eureka-server7001</artifactId><dependencies><!-- eureka server~ --><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency><dependency><groupId>top.bitqian</groupId><artifactId>cloud-api-commons</artifactId><version>${project.version}</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --><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></project>

eureka 服務server端的注冊中心, single

server:port: 7001# 單機版eureka eureka:instance:hostname: localhost #eureka服務端的實例名字client:register-with-eureka: false #表識不向注冊中心注冊自己fetch-registry: false #表示自己就是注冊中心,職責是維護服務實例,并不需要去檢索服務service-url:defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/#設置與eureka server交互的地址查詢服務和注冊服務都需要依賴這個地址

eureka的集群搭建

  • 更改host文件
  • 127.0.0.1 http://eureka7001.com 127.0.0.1 http://eureka7002.com
  • yaml 相互注冊,相互守望
  • server:port: 7001# 服務注冊集群 eureka服務注冊中心地址7001 eureka:instance:hostname: eureka7001.com #eureka服務端的實例名字client:register-with-eureka: false #表識不向注冊中心注冊自己fetch-registry: false #表示自己就是注冊中心,職責是維護服務實例,并不需要去檢索服務service-url:defaultZone: http://eureka7002.com:7002/eureka/ #設置與eureka server交互的地址查詢服務和注冊服務都需要依賴這個地址 server:port: 7002# 服務注冊集群 eureka服務注冊中心地址7002 eureka:instance:hostname: eureka7002.com #eureka服務端的實例名字client:register-with-eureka: false #表識不向注冊中心注冊自己fetch-registry: false #表示自己就是注冊中心,職責是維護服務實例,并不需要去檢索服務service-url:defaultZone: http://eureka7001.com:7001/eureka/ #設置與eureka server交互的地址查詢服務和注冊服務都需要依賴這個地址

    客戶端如何入駐eureka集群

  • 消費者
  • # 暴露80端口,消費者調用8001 支付接口 server:port: 80# 服務消費者 client spring:application:name: cloud-order-serviceeureka:client:register-with-eureka: true # 是否注冊到服務中心~fetchRegistry: trueservice-url:# 將80消費者服務 發布到7001, 7002端口的eureka集群服務里面defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版
  • 兩個服務提供者
  • eureka:client:register-with-eureka: truefetchRegistry: trueservice-url:# 將支付服務8001發布到7001, 7002 兩臺eureka集群配置中defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版 # eureka客戶端 可以又多個 eureka:client:register-with-eureka: truefetchRegistry: trueservice-url:# 將支付服務8001發布到7001, 7002 兩臺eureka集群配置中defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版

    eureka的自我保護機制

    eureak 不會刪掉,干掉已經掛掉的服務。

    # 自我保護機制出現現象: 服務客戶端和eureka server之間在網絡分區下進行的保護# 一旦進入保護模式,eureka server將會嘗試保護其注冊表中的信息, 不會注銷掉任何微服務# 某個時刻某一個微服務不可用了, eureka不會進行服務清理, 會對微服務信息進行保存。# 為什么進行保護: 網絡是不穩定的, 可能某個服務可能因為短暫的網絡擁堵, 導致服務暫停了, 但是服務是健康的。 cap --> ap

    總結

    以上是生活随笔為你收集整理的服务注册中心 eureka 搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。