修改打包环境

This commit is contained in:
2023-10-20 16:43:06 +08:00
parent e990133b64
commit 3f79124393
6 changed files with 53 additions and 7 deletions

View File

@@ -19,7 +19,10 @@ import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.List;
@Slf4j
@@ -60,15 +63,43 @@ public class StarterServer implements ApplicationRunner {
private void registerZK(BootstrapConfig config) throws UnknownHostException {
String hostAddress = InetAddress.getLocalHost().getHostAddress();
private void registerZK(BootstrapConfig config) throws Exception {
String hostAddress = this.getIpAdd();
//TODO 后面优化
String ip = System.getenv("IM_HOST");
ZkClient zkClient = new ZkClient(config.getLim().getZkConfig().getZkAddr(),
config.getLim().getZkConfig().getZkConnectTimeOut());
ZKit zKit = new ZKit(zkClient);
RegistryZK registryZK = new RegistryZK(zKit, hostAddress, config.getLim());
RegistryZK registryZK = new RegistryZK(zKit, ip, config.getLim());
Thread thread = new Thread(registryZK);
thread.start();
}
public String getIpAdd() throws SocketException, UnknownHostException{
String ip="";
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
String name = intf.getName();
if (!name.contains("docker") && !name.contains("lo")) {
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
//获得IP
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress = inetAddress.getHostAddress().toString();
if (!ipaddress.contains("::") && !ipaddress.contains("0:0:") && !ipaddress.contains("fe80")) {
System.out.println(ipaddress);
if(!"127.0.0.1".equals(ip)){
ip = ipaddress;
}
}
}
}
}
}
return ip;
}
}

View File

@@ -1,4 +1,5 @@
lim:
host: 119.45.242.222
tcpPort: 29000
webSocketPort: 29001
bossThreadSize: 1
@@ -25,9 +26,9 @@ lim:
rabbitmq:
host: 119.45.242.222
port: 5672
addresses: 119.45.242.222
username: guest
password: guest
virtualHost: /
userName: guest
passWord: guest
zkConfig:
zkAddr: 119.45.242.222:2181