赞
踩
创建一个标准的springboot项目
- <dependency>
- <groupId>de.codecentric</groupId>
- <artifactId>spring-boot-admin-starter-server</artifactId>
- <version>版本号</version>
- </dependency>
bootstrap/application.yml配置SpringBoot Admin Server属性:端口号,服务名,用户登录信息等
# 端口 server: port: 90040 spring: application: name: monitor-server # config client 配置中心config profiles: active: prod cloud: config: fail-fast: true username: config password: cofing label: trunk profile: ${spring.profiles.active} #prod # 取哪個版本的配置文件 #uri: http://localhost:9090/ # Config Server URI, 无Eureka Server才需要配置 discovery: enabled: true service-id: cdp-config-server inetutils: ignored-interfaces: # 配置Eureka Client註冊到Eureka服務器時,需要忽略的網卡清單。僅針對運行環境(主機)存在多網卡的情景。 - "docker.*" # 忽略并避免使用docker網卡IP註冊 - "veth.*" # 忽略并避免使用docker環境下容器的虛擬網卡 - "virbr0" # 忽略并避免使用 KVM創建的提供NAT模式網卡IP註冊 - "kbr0" # 忽略并避免使用自定義的基於OpenvSwitch技術構建的docker物理主機通信虛擬網IP註冊 - "VMware.*" # 忽略并避免使用vmware網卡IP註冊 main: allow-bean-definition-overriding: true management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS # 和Eureka instance进行集成 eureka: instance: prefer-ip-address: true instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} # 注意:如果应用存在上下文,则必须设置health-check-url-path和status-page-url-path #health-check-url: http://${spring.cloud.client.ip-address}:${server.port}${server.servlet.context-path}/actuator/health health-check-url-path: /actuator/health #status-page-url: http://${spring.cloud.client.ip-address}:${server.port}${server.servlet.context-path}/actuator/info status-page-url-path: /actuator/info home-page-url-path: / metadata-map: management: context-path: /actuator # spring boot admin获取客户端的默认端点路径前缀为"/actuator":因为客户端有上下文路径,故需要通过eureka client告知admin server user: # 如果不配置则无法获取 /actuator/health信息,提示401 name: monitor #SpringBootAdmin本身作为一个Eureka客户端被发现,这里由于SpringBootAdmin需要进行登录,因此,此处配置SpringBootAdmin登录时使用的用户名 password: monitor2024. --- # prod为正式Docker配置环境,使用"---"间隔不同环境 spring: profiles: prod eureka: client: serviceUrl: defaultZone: http://admin:admin.@peer1:8761/eureka/,http://admin:admin.@peer2:8762/eureka/ # 高可用地址
- spring:
- # 安全配置
- security:
- user:
- name: monitor
- # password: ENC(YTz0WOWB8fm4wvHNRsjKoHxFNo3T64D1)
- password: monitor2024.
-
- #jasypt 正式环境需要加密,对应ENC(YTz0WOWB8fm4wvHNRsjKoHxFNo3T64D1)
- #jasypt:
- #encryptor:
- #password: monitor2024 # 密钥盐/passsword salt
- package com.monitor;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
- import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
- import de.codecentric.boot.admin.server.config.EnableAdminServer;
-
- /**
- *
- * @ClassName: MonitorApplication
- * @Description: 应用监控服务端启动类
- * @author test
- *
- */
- @SpringBootApplication
- @EnableAutoConfiguration
- @EnableAdminServer
- @EnableDiscoveryClient
- @EnableEncryptableProperties
- public class MonitorApplication {
- public static void main( String[] args ){
- SpringApplication.run(MonitorApplication.class, args);
- }
- }
Spring Boot Admin Server启动后,通过http:localhost(或者部署的服务器IP):90040/,随后输入正确登录用户信息(monitor/monitor2024),验证通过后我们就可以查看已经正常启动的服务以及对应的运行状态等信息~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。