測試須要三個使用服務: nacos註冊中心, spring boot admin監控服務(集成nacos client), 測試服務(集成nacos client)html
1, nacos註冊中心web
下載nacos-server.jar 啓動就能夠了,默認端口 8848 ,默認帳號密碼都是:nacosspring
2, spring boot admin監控服務app
<properties> <spring.boot.version>2.1.6.RELEASE</spring.boot.version> <spring.boot.admin.version>2.1.6</spring.boot.admin.version> <spring.cloud.alibaba.version>2.1.0.RELEASE</spring.cloud.alibaba.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring.cloud.alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>${spring.boot.admin.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> </dependencies>
spring boot admin 詳細實現參考: https://www.cnblogs.com/forezp/p/10242004.htmlspring-boot
這裏增長了spring-cloud-starter-alibaba-nacos-discovery測試
配置項變化:url
#spring.boot.admin.client.url=http://127.0.0.1 #spring.boot.admin.client.username=${spring.application.name} #spring.boot.admin.client.password=password # #spring.boot.admin.client.instance.name=${spring.application.name} #spring.boot.admin.client.instance.service-base-url=http://localhost:8081 #spring.boot.admin.client.instance.metadata.user.name=name #spring.boot.admin.client.instance.metadata.user.password=password
spring boot admin client相關配置再也不須要,經過服務註冊能夠自動發現 code
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.nacos.discovery.metadata.user.name=name spring.cloud.nacos.discovery.metadata.user.password=password spring.cloud.nacos.discovery.metadata.management.context-path=/admin/actuator
這裏須要注意的是metadata相關的配置server
spring.cloud.nacos.discovery.metadata.user.name=name
spring.cloud.nacos.discovery.metadata.user.password=passwordxml
增長這兩項,默認會使用basic auth進行登陸
spring.cloud.nacos.discovery.metadata.management.context-path=/admin/actuator
這裏指定actuator請求的前綴,要包括server.servlet.context-path 配置的前綴, 這個配置是重點, 找了很久才發現, 當你actuator端點配置不是默認的/actuator,也就是:management.endpoints.web.base-path=/admin/actuator
3, 測試服務
當沒有nacos時集成的是spring-boot-admin-starter-client
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.1.6</version> </dependency>
有了nacos, 就不須要spring-boot-admin-starter-client這個了,換成spring-cloud-starter-alibaba-nacos-discovery
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.1.0.RELEASE</version> </dependency>
這個服務用來檢測服務是否可用, 跟2配置基本一致,只是沒有spring boot admin
三個服務都啓動後,在第2個服務上能夠看到兩個服務(第1個和第2個)的監控信息,