最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解spring-cloud與netflixEureka整合(注冊(cè)中心)

 更新時(shí)間:2019年02月14日 14:17:08   作者:金一濤  
這篇文章主要介紹了詳解spring-cloud與netflixEureka整合(注冊(cè)中心),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

基礎(chǔ)依賴

compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter') 

eureka(單機(jī))

服務(wù)端:

依賴

compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server') 

application.yml 配置

spring:
 application:
  name: dev
eureka:
 client:
  service-url:
   defaultZone: http://本機(jī)ip地址:8761/eureka/ #注冊(cè)中心地址
  register-with-eureka: false #表明該實(shí)例是否應(yīng)該與尤里卡服務(wù)器登記其信息被別人發(fā)現(xiàn)。在某些情況下,您不希望您的實(shí)例被發(fā)現(xiàn)而你想發(fā)現(xiàn)其他實(shí)例。默認(rèn)為true
  fetch-registry: false #表明這個(gè)客戶是否應(yīng)該從尤里卡服務(wù)器獲取尤里卡注冊(cè)表信息。默認(rèn)為true
server:
 port: 8761

啟動(dòng)類添加 @EnableEurekaServer

客戶端:

主要依賴

compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 

application.yml 配置

eureka:
 client:
  service-url:
   defaultZone: http://eureka服務(wù)地址:8761/eureka/ 

啟動(dòng)類添加 @EnableDiscoveryClient (注冊(cè)中心通用客戶端注解)或 @EnableEurekaClient (只有eureka客戶端可用)

eureka(集群)

服務(wù)端

主要依賴

compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 

application.yml 配置

server:
 port: 8761
eureka:
 client:
  register-with-eureka: false
  fetch-registry: false
 server:
  enable-self-preservation: false #使用自我保護(hù),默認(rèn)true
  peer-node-read-timeout-ms: 5000 #節(jié)點(diǎn)讀取超時(shí)時(shí)間,默認(rèn)200毫秒
---
spring:
 application:
  name: eureka1
 profiles: eureka1
eureka:
 client:
  service-url:
   defaultZone: http://eureka2:8761/eureka/,http://eureka3:8761/eureka/
 instance:
  hostname: eureka1
---
spring:
 application:
  name: eureka2
 profiles: eureka2
eureka:
 client:
  service-url:
   defaultZone: http://eureka1:8761/eureka/,http://eureka3:8761/eureka/
 instance:
  hostname: eureka2
---
spring:
 application:
  name: eureka3
 profiles: eureka3
eureka:
 client:
  service-url:
   defaultZone: http://eureka1:8761/eureka/,http://eureka2:8761/eureka/
 instance:
  hostname: eureka3

eureka.client.service-url.defaultZone 與 eureka.instance.hostsname eureka1、eureka2、eureka3  都再本機(jī)的 hosts 文件里事先寫好,

例如 eureka1 服務(wù)器上的hosts文件
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   eureka1
xxx.xxx.x.xx eureka2
xx.xxx.xxx.xx eureka3

啟動(dòng)類同樣是添加 @EnableEurekaServer 注意:如果運(yùn)行 jar 包時(shí)需要程序接收命令行參數(shù),一定要再main方法的 SpringApplication.run() 方法 中傳入 args 參數(shù)

例如:

public static void main(String[] args) {
   SpringApplication.run(QnbbsConsumer.class,args);
}

如果不傳入的話在命令行輸入 java -jar xxx.jar --參數(shù)名=參數(shù)值 參數(shù)將不起作用從而影響你無法選擇寫好的環(huán)境配置

客戶端:

依賴跟單機(jī)的一樣

application.yml 配置

eureka:
 instance:
  prefer-ip-address: true #是否顯示ip
  ip-address: 本機(jī)ip #填寫本機(jī)ip地址
 client:
  service-url:
   defaultZone: http://eureka1:8761/eureka/,http://eureka2:8761/eureka/,http://eureka3:8761/eureka/

啟動(dòng)類注解與單機(jī)版一樣

客戶端注冊(cè)一臺(tái)注冊(cè)中心,同時(shí)注冊(cè)到其他集群中說明成功!

eureka添加 spring-security 權(quán)限認(rèn)證

依賴

compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server') 

application.yml 配置

server:
 port: 8761
spring:
 application:
  name: eureka-server
 security:
  user:
   name: zyn
   password: zyn123... 
  #用戶名與密碼若是不配置,系統(tǒng)會(huì)自動(dòng)生成并打印在控制臺(tái)日志上
  
eureka:
 client:
  register-with-eureka: false
  fetch-registry: false
 server:
  enable-self-preservation: false
  peer-node-read-timeout-ms: 5000
  
management:
 endpoints:
  web:
   base-path: /
   exposure:
    include: '*'
 endpoint:
  health:
   show-details: always
  restart:
   enabled: true
 server:
  port: 8761
---
spring:
 profiles: eureka-jy
eureka:
 client:
  service-url:
   defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@eureka-B:8761/eureka/,http://${spring.security.user.name}:${spring.security.user.password}@eureka-C:8761/eureka/
 instance:
  hostname: eureka-A
---
spring:
 profiles: eureka-lhn
eureka:
 client:
  service-url:
   defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@eureka-A:8761/eureka/,http://${spring.security.user.name}:${spring.security.user.password}@eureka-C:8761/eureka/ 
 instance:
  hostname: eureka-B
---
spring:
 profiles: eureka-zsm
eureka:
 client:
  service-url:
   defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@eureka-A:8761/eureka/,http://${spring.security.user.name}:${spring.security.user.password}@eureka-B:8761/eureka/
 instance:
  hostname: eureka-C

創(chuàng)建一個(gè)類并繼承 WebSecurityConfigurerAdapter 類,并在此類上添加 @EnableWebSecurity和@Configuration 注解,重寫 configure 方法

package com.iteng.eureka.security;​
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
​
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
​
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable(); // 關(guān)閉csrf
    http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); // 開啟認(rèn)證
  }
}

啟動(dòng)類添加注解

@EnableEurekaServer
@EnableWebSecurity

下線服務(wù)

http://eureka地址:端口/eureka/apps/服務(wù)名/服務(wù)地址:服務(wù)端口號(hào)

實(shí)例如下:

erueka注冊(cè)中心ip: 10.100.1.100

端口: 12000

服務(wù)名: CPS-RISK-SERVER

實(shí)例id: 192.168.10.54:18883

則向下面的url通過http發(fā)送delete命令,可將指定的服務(wù)實(shí)例刪除:
http://10.100.1.100:12000/eureka/apps/CPS-RISK-SERVER/192.168.10.54:18883

變更服務(wù)狀態(tài)

http://eureka地址:端口/eureka/apps/服務(wù)名/服務(wù)地址/status?value=${value}

其中${value}的取值為:OUT_OF_SERVICE , DOWN , UP

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Springboot項(xiàng)目編寫測(cè)試單元完整步驟記錄

    Springboot項(xiàng)目編寫測(cè)試單元完整步驟記錄

    這篇文章主要介紹了如何使用JUnit編寫Spring?Boot項(xiàng)目中的測(cè)試單元,包括引入依賴、配置文件設(shè)置、啟動(dòng)文件創(chuàng)建以及編寫測(cè)試類的步驟,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-03-03
  • SpringBoot配置Spring?Security的實(shí)現(xiàn)示例

    SpringBoot配置Spring?Security的實(shí)現(xiàn)示例

    本文主要介紹了SpringBoot配置Spring?Security的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-10-10
  • Mybatis增刪改查mapper文件寫法詳解

    Mybatis增刪改查mapper文件寫法詳解

    這篇文章主要介紹了Mybatis增刪改查mapper文件寫法的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • 詳解spring mvc4使用及json 日期轉(zhuǎn)換解決方案

    詳解spring mvc4使用及json 日期轉(zhuǎn)換解決方案

    本篇文章主要介紹了spring mvc4使用及json 日期轉(zhuǎn)換解決方案,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • eclipse報(bào)錯(cuò) eclipse啟動(dòng)報(bào)錯(cuò)解決方法

    eclipse報(bào)錯(cuò) eclipse啟動(dòng)報(bào)錯(cuò)解決方法

    本文將介紹eclipse啟動(dòng)報(bào)錯(cuò)解決方法,需要了解的朋友可以參考下
    2012-11-11
  • SpringBoot配置綁定方法詳解

    SpringBoot配置綁定方法詳解

    配置綁定是SpringBoot其中一個(gè)底層功能,SpringBoot把配置綁定的過程變得更加簡(jiǎn)單,傳統(tǒng)java將常用的配置放到配置文件properties中,之后將這些配置綁定到j(luò)avabean中
    2022-10-10
  • Gradle的使用教程詳解

    Gradle的使用教程詳解

    Gradle它使用一種基于Groovy的特定領(lǐng)域語(yǔ)言(DSL)來聲明項(xiàng)目設(shè)置,目前也增加了基于Kotlin語(yǔ)言的kotlin-based DSL,拋棄了基于XML的各種繁瑣配置,下面通過本文給大家介紹Gradle的使用教程,感興趣的朋友一起看看吧
    2020-09-09
  • Java將對(duì)象保存到文件中/從文件中讀取對(duì)象的方法

    Java將對(duì)象保存到文件中/從文件中讀取對(duì)象的方法

    下面小編就為大家?guī)硪黄狫ava將對(duì)象保存到文件中/從文件中讀取對(duì)象的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-12-12
  • Java split()方法中的特殊符號(hào)舉例詳解

    Java split()方法中的特殊符號(hào)舉例詳解

    Java中的split方法可以將一個(gè)字符串按照指定的分隔符進(jìn)行分割,返回一個(gè)字符串?dāng)?shù)組,這篇文章主要給大家介紹了關(guān)于Java split()方法中的特殊符號(hào)的相關(guān)資料,需要的朋友可以參考下
    2023-07-07
  • Spring?Data?JPA命名約定查詢實(shí)現(xiàn)方法

    Spring?Data?JPA命名約定查詢實(shí)現(xiàn)方法

    這篇文章主要為大家介紹了Spring?Data?JPA命名約定查詢實(shí)現(xiàn)方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12

最新評(píng)論

岳池县| 桐城市| 江北区| 阜城县| 昌平区| 金溪县| 塔城市| 惠东县| 滦平县| 澜沧| 临沂市| 收藏| 永年县| 阜康市| 温州市| 尉犁县| 阿图什市| 杭州市| 木兰县| 隆昌县| 伊金霍洛旗| 垫江县| 瓮安县| 德安县| 宣化县| 安西县| 泽库县| 天长市| 金坛市| 读书| 洛扎县| 东丰县| 兴业县| 九龙县| 晋中市| 昆山市| 长垣县| 龙川县| 涞源县| 盘锦市| 象州县|