Version: Next

Actuator 微服务信息完善

当前问题


  • Eureka Server 中可以看到,具体微服务节点的 主机名ip 地址会被暴露出来,我们希望这些信息不被暴露,只暴露服务名

引入 Actuator Maven 坐标

<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

主机名称——服务名称修改

修改 payment8001payment8002application.yaml 文件

  • 添加 eureka.instance.instance-id,设置为 payment8001payment8002
  • 这样就可以隐藏 主机名
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true
register-with-eureka: true
#是否从EurekaServer抓取已有的注册消息,默认为true,单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetch-registry: true
service-url:
#集群版
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
#单机版 入驻到这个地址(就是注册中心地址)
# defaultZone: http://127.0.0.1:7001/eureka/
instance: # 用来修改服务名称,防止暴露当前服务器主机
instance-id: payment8001
  • 重启 80018002 微服务,访问 Eureka Server ,可以看到主机名已经变为了我们所设置的内容



开启 IP 地址预览

80018002 YAML 文件中,开启 eureka.instance.prefer-ip-address: true 即可



最终的 YAML 文件

server:
port: 8081
spring:
application:
name: cloud-payment-service
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/springcloud?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: true #驼峰映射
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #调试打印SQL
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true
register-with-eureka: true
#是否从EurekaServer抓取已有的注册消息,默认为true,单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetch-registry: true
service-url:
#集群版
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
#单机版 入驻到这个地址(就是注册中心地址)
# defaultZone: http://127.0.0.1:7001/eureka/
instance: # 用来修改服务名称,防止暴露当前服务器主机
instance-id: payment8001
prefer-ip-address: true # 可以预览 ip 地址