Version: Next
Actuator 微服务信息完善
当前问题
![]()
- 从
Eureka Server
中可以看到,具体微服务节点的主机名
或ip
地址会被暴露出来,我们希望这些信息不被暴露,只暴露服务名
引入 Actuator Maven 坐标
<!--监控--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>
主机名称——服务名称修改
修改
payment8001
和payment8002
的application.yaml
文件
- 添加
eureka.instance.instance-id
,设置为payment8001
和payment8002
- 这样就可以隐藏
主机名
eureka:client:#表示是否将自己注册进EurekaServer默认为trueregister-with-eureka: true#是否从EurekaServer抓取已有的注册消息,默认为true,单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡fetch-registry: trueservice-url:#集群版defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/#单机版 入驻到这个地址(就是注册中心地址)# defaultZone: http://127.0.0.1:7001/eureka/instance: # 用来修改服务名称,防止暴露当前服务器主机instance-id: payment8001
- 重启
8001
和8002
微服务,访问Eureka Server
,可以看到主机名已经变为了我们所设置的内容![]()
开启 IP 地址预览
在
8001
、8002
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 地址