diff --git a/jobx-agent/src/conf/conf/conf.properties b/jobx-agent/src/conf/conf/conf.properties index 4eb80206..5476cf58 100644 --- a/jobx-agent/src/conf/conf/conf.properties +++ b/jobx-agent/src/conf/conf/conf.properties @@ -9,8 +9,12 @@ jobx.password=jobx #jobx-agent默认启动端口 jobx.port=1577 -#agent Ip,确保server可以通过此ip访问到该agent(主要实现agent自动注册) -jobx.host=127.0.0.1 +# +# agent Ip,确保server可以通过此ip访问到该agent(主要实现agent自动注册) +# 程序中做了自动探测ip的功能,如存在以下两种情况请手动设置host, +# 1)agent探测出来的ip在server端连接不上 +# 2)如果在多块网卡的情况下会选择一块,可能存在server连接不上 +#jobx.host=127.0.0.1 #zookepper注册中心 jobx.registry=zookeeper://127.0.0.1:2181 \ No newline at end of file diff --git a/jobx-agent/src/main/java/com/jobxhub/agent/bootstrap/JobXAgent.java b/jobx-agent/src/main/java/com/jobxhub/agent/bootstrap/JobXAgent.java index ee13b15f..3c566f2e 100755 --- a/jobx-agent/src/main/java/com/jobxhub/agent/bootstrap/JobXAgent.java +++ b/jobx-agent/src/main/java/com/jobxhub/agent/bootstrap/JobXAgent.java @@ -169,7 +169,16 @@ private void init() { if (isEmpty(this.host)) { this.host = PropertiesLoader.getProperty(Constants.PARAM_JOBX_HOST_KEY); } - if (notEmpty(this.host) && NetUtils.isValidAddress(this.host)) { + if (isEmpty(this.host)) { + //自动探测ip + this.host = NetUtils.getLocalHost(); + } + + if (isEmpty(this.host)) { + throw new ExceptionInInitializerError("[JobX] agent host must be not empty."); + } + + if(NetUtils.isValidAddress(this.host)){ throw new ExceptionInInitializerError("[JobX] agent host is valid"); }