<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          SpringCloud微服務(wù)框架Eureka注冊中心

          共 4069字,需瀏覽 9分鐘

           ·

          2021-04-02 23:50

          Eureka注冊中心

          采用了Client+service的設(shè)計架構(gòu),它作為服務(wù)注冊功能的服務(wù)器,它是服務(wù)中心 加載pom依賴

          ?
          ????<dependencies>
          ????????<!--eureka-server服務(wù)端?-->
          ????????<dependency>
          ????????????<groupId>org.springframework.cloud</groupId>
          ????????????<artifactId>spring-cloud-starter-eureka-server</artifactId>
          ????????</dependency>
          ????????<!--?修改后立即生效,熱部署?-->
          ????????<dependency>
          ????????????<groupId>org.springframework</groupId>
          ????????????<artifactId>springloaded</artifactId>
          ????????</dependency>
          ????????<dependency>
          ????????????<groupId>org.springframework.boot</groupId>
          ????????????<artifactId>spring-boot-devtools</artifactId>
          ????????</dependency>
          ????</dependencies>

          創(chuàng)建配置application.yml文件

          server:
          ??port:?7001

          eureka:
          ??instance:
          ????hostname:?localhost?#eureka服務(wù)端的實(shí)例名稱
          ??client:
          ????register-with-eureka:?false?#false表示不向注冊中心注冊自己。
          ????fetch-registry:?false?#false表示自己端就是注冊中心,我的職責(zé)就是維護(hù)服務(wù)實(shí)例,并不需要去檢索服務(wù)
          ????service-url:
          ??????defaultZone:?http://${eureka.instance.hostname}:${server.port}/eureka/????????#設(shè)置與Eureka Server交互的地址查詢服務(wù)和注冊服務(wù)都需要依賴這個地址。

          創(chuàng)建啟動類

          package?com.yang.eureka;

          import?org.springframework.boot.SpringApplication;
          import?org.springframework.boot.autoconfigure.SpringBootApplication;
          import?org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

          @EnableEurekaServer
          @SpringBootApplication
          public?class?EurekaServer7001_App?{
          ????public?static?void?main(String[]?args)?{
          ????????SpringApplication.run(EurekaServer7001_App.class,?args);
          ????}
          }
          將已經(jīng)有的部門微服務(wù)注冊Eureka

          修改microservicecloud-provider-dept-8001的pom依賴倉庫

          ?<!--?將微服務(wù)provider側(cè)注冊進(jìn)eureka?-->
          ????????<dependency>
          ????????????<groupId>org.springframework.cloud</groupId>
          ????????????<artifactId>spring-cloud-starter-eureka</artifactId>
          ????????</dependency>
          ????????<dependency>
          ????????????<groupId>org.springframework.cloud</groupId>
          ????????????<artifactId>spring-cloud-starter-config</artifactId>
          ????????</dependency>

          修改application.yml配置文件

          eureka:
          ??client:?#客戶端注冊進(jìn)eureka服務(wù)列表內(nèi)
          ????service-url:?
          ??????defaultZone:?http://localhost:7001/eureka

          在啟動類上添加注解

          @EnableEurekaClient?//本服務(wù)啟動后會自動注冊進(jìn)eureka服務(wù)中

          查看端口進(jìn)程

          netstat?-aon|findstr?"9000"?

          殺死進(jìn)程

          taskkill?/F?/pid?2448

          修改microservicecloud-provider-dept-8001的pom

          <dependency>
          ???????<groupId>org.springframework.boot</groupId>
          ???????<artifactId>spring-boot-starter-actuator</artifactId>
          ???</dependency>

          修改父工程pom依賴

          <build>
          ???<finalName>microservicecloud</finalName>
          ???<resources>
          ?????<resource>
          ???????<directory>src/main/resources</directory>
          ???????<filtering>true</filtering>
          ?????</resource>
          ???</resources>
          ???<plugins>
          ?????<plugin>
          ???????<groupId>org.apache.maven.plugins</groupId>
          ???????<artifactId>maven-resources-plugin</artifactId>
          ???????<configuration>
          ?????????<delimiters>
          ??????????<delimit>$</delimit>
          ?????????</delimiters>
          ???????</configuration>
          ?????</plugin>
          ???</plugins>
          ??</build>

          集群配置

          找到C:\Windows\System32\drivers\etc路徑下的hosts文件

          127.0.0.1 ?eureka7001.com 127.0.0.1 ?eureka7002.com 127.0.0.1 ?eureka7003.com

          修改microservicecloud-provider-dept-8001的application.yml配置文件

          eureka:
          ??client:?#客戶端注冊進(jìn)eureka服務(wù)列表內(nèi)
          ????service-url:?
          #??????defaultZone:?http://localhost:7001/eureka
          ???????defaultZone:?http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/

          ??修改microservicecloud-eureka-7001的application.yml配置文件

          ?
          ?server:?
          ??port:?7001
          ?
          eureka:?
          ??instance:
          ????hostname:?eureka7001.com?#eureka服務(wù)端的實(shí)例名稱
          ??client:?
          ????register-with-eureka:?false?????#false表示不向注冊中心注冊自己。
          ????fetch-registry:?false?????#false表示自己端就是注冊中心,我的職責(zé)就是維護(hù)服務(wù)實(shí)例,并不需要去檢索服務(wù)
          ????service-url:?
          ??????#單機(jī)?defaultZone:?http://${eureka.instance.hostname}:${server.port}/eureka/???????#設(shè)置與Eureka?Server交互的地址查詢服務(wù)和注冊服務(wù)都需要依賴這個地址(單機(jī))。
          ??????defaultZone:?http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/


          瀏覽 60
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  xx在线视频 | 在线观看黄片 | 日本在线一区 | 天天爽夜夜爽精品成人免费 | 一级Aa视频免费看 |