zoukankan      html  css  js  c++  java
  • Eureka Server 的 Instance Status 一直显示主机名问题

    Eureka Server 的 Instance Status 一直显示主机名问题

    注册中心启动后,访问 http://localhost:8761/ 后:

    image

    如何调整为具体所在的服务器 IP 呢?

    解决方案:
    application.yml 文件新增:

    eureka:
      instance:
        instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
        prefer-ip-address:  true
        
    

    配置说明:
    (1)eureka.instance.instance-id 指明了status名字命名; eureka.instance.prefer-ip-address 解决了下图中2位置的问题:
    image
    (2) spring.cloud.client.ip-address 属性是来自于 spring-cloud-commons 包的 org.springframework.cloud.client.HostInfoEnvironmentPostProcessor # postProcessEnvironment()方法:

    	public void postProcessEnvironment(ConfigurableEnvironment environment,
    			SpringApplication application) {
    		InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
    		LinkedHashMap<String, Object> map = new LinkedHashMap<>();
    		map.put("spring.cloud.client.hostname", hostInfo.getHostname());
    		map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress());
    		MapPropertySource propertySource = new MapPropertySource(
    				"springCloudClientHostInfo", map);
    		environment.getPropertySources().addLast(propertySource);
    	}
    
    

    验证

    image

  • 相关阅读:
    cookie会话技术
    Vue实现任务列表效果
    Vue实现选项卡效果
    数组API(2)
    数组常用API(1)
    sticky,粘性定位
    了解HTTP协议和TCP协议
    快速排序
    冒泡排序
    【译】x86程序员手册21-6.3.5为操作系统保留的指令
  • 原文地址:https://www.cnblogs.com/lihw-study/p/15426029.html
Copyright © 2011-2022 走看看