环境信息
docker canal/canal-server:v1.1.5
问题描述
当我在canal服务器上使用docker swarm时,将启动多个容器服务,每个容器有多个网络接口,在java中接口顺序是不可控的。
怎么通过这些接口获取canal IP?
当网络接口的顺序被打乱时,以下代码将获得错误的IP。
public static InetAddress getHostAddress() { InetAddress localAddress = null; try { Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); if (interfaces != null) { while (interfaces.hasMoreElements()) { try { NetworkInterface network = interfaces.nextElement(); Enumeration addresses = network.getInetAddresses(); if (addresses != null) { while (addresses.hasMoreElements()) { try { InetAddress address = addresses.nextElement(); if (isValidHostAddress(address)) { return address; } } catch (Throwable e) { logger.warn("Failed to retriving network card ip address. cause:" + e.getMessage()); } } } } catch (Throwable e) { logger.warn("Failed to retriving network card ip address. cause:" + e.getMessage()); } } } } catch (Throwable e) { logger.warn("Failed to retriving network card ip address. cause:" + e.getMessage()); } logger.error("Could not get local host ip address, will use 127.0.0.1 instead."); return localAddress; } So I want to specify the name of the network interface to ensure that the correct IP is ob
我想指定网络接口的名称,以确保获得正确的IP。
原提问者GitHub用户xiaoyao9184
参考配置:
canal.ip =
canal.register.ip =
原回答者GitHub用户agapple
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。