国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 詳解spring-cloud與netflixEureka整合(注冊中心)

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

2021-07-15 14:43金一濤 Java教程

這篇文章主要介紹了詳解spring-cloud與netflixEureka整合(注冊中心),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

基礎依賴

?
1
2
3
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter')

eureka(單機)

服務端:

依賴

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

application.yml 配置

?
1
2
3
4
5
6
7
8
9
10
11
spring:
 application:
  name: dev
eureka:
 client:
  service-url:
   defaultZone: http://本機ip地址:8761/eureka/ #注冊中心地址
  register-with-eureka: false #表明該實例是否應該與尤里卡服務器登記其信息被別人發(fā)現(xiàn)。在某些情況下,您不希望您的實例被發(fā)現(xiàn)而你想發(fā)現(xiàn)其他實例。默認為true
  fetch-registry: false #表明這個客戶是否應該從尤里卡服務器獲取尤里卡注冊表信息。默認為true
server:
 port: 8761

啟動類添加 @EnableEurekaServer

客戶端:

主要依賴

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

application.yml 配置

?
1
2
3
4
eureka:
 client:
  service-url:
   defaultZone: http://eureka服務地址:8761/eureka/

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

eureka(集群)

服務端

主要依賴

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

application.yml 配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
server:
 port: 8761
eureka:
 client:
  register-with-eureka: false
  fetch-registry: false
 server:
  enable-self-preservation: false #使用自我保護,默認true
  peer-node-read-timeout-ms: 5000 #節(jié)點讀取超時時間,默認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  都再本機的 hosts 文件里事先寫好,

例如 eureka1 服務器上的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

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

例如:

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

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

客戶端:

依賴跟單機的一樣

application.yml 配置

?
1
2
3
4
5
6
7
eureka:
 instance:
  prefer-ip-address: true #是否顯示ip
  ip-address: 本機ip #填寫本機ip地址
 client:
  service-url:
   defaultZone: http://eureka1:8761/eureka/,http://eureka2:8761/eureka/,http://eureka3:8761/eureka/

啟動類注解與單機版一樣

客戶端注冊一臺注冊中心,同時注冊到其他集群中說明成功!

eureka添加 spring-security 權限認證

依賴

?
1
2
3
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 配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
server:
 port: 8761
spring:
 application:
  name: eureka-server
 security:
  user:
   name: zyn
   password: zyn123...
  #用戶名與密碼若是不配置,系統(tǒng)會自動生成并打印在控制臺日志上
  
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)建一個類并繼承 WebSecurityConfigurerAdapter 類,并在此類上添加 @EnableWebSecurity和@Configuration 注解,重寫 configure 方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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(); // 關閉csrf
    http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); // 開啟認證
  }
}

啟動類添加注解

?
1
2
@EnableEurekaServer
@EnableWebSecurity

下線服務

http://eureka地址:端口/eureka/apps/服務名/服務地址:服務端口號

實例如下:

erueka注冊中心ip: 10.100.1.100

端口: 12000

服務名: CPS-RISK-SERVER

實例id: 192.168.10.54:18883

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

變更服務狀態(tài)

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

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.cnblogs.com/bqzz/p/10294326.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美一级二级三级 | 精品久久久久一区二区国产 | 久热免费视频 | 北条麻妃99精品青青久久主播 | 韩日精品一区 | 九九热九九 | 国产精品成人免费视频 | 美日韩成人 | 欧美成在线观看 | 狠狠艹av| 国产精品久久久久久久免费大片 | 97视频在线| 亚洲五码中文字幕 | 日韩欧美精品一区二区三区 | 午夜精品网站 | 亚洲免费视频观看 | 亚洲精品久久久久久久久久久 | 中文日韩在线 | 国产综合精品 | 日韩一级免费观看 | 艹逼短视频 | 成人涩涩日本国产一区 | 一区二区 在线视频 | 麻豆av在线播放 | 国产婷婷精品av在线 | 亚洲国产一区在线 | 日韩欧美在线免费观看 | 日本三级中文在线电影 | av影音| 久久综合一| 一本大道香蕉大a√在线 | 国产一区二区三区欧美 | 在线中文字幕视频 | 青青草久久久 | 精品国产一区二区三区久久久蜜月 | 成人精品国产免费网站 | 欧美日韩成人在线 | 日韩免费网站 | 成人乱人乱一区二区三区 | 日韩三级电影网 | 中外毛片 |