65 lines
2.0 KiB
Java
65 lines
2.0 KiB
Java
package org.kne.cloud.network.klalb;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.PrintStream;
|
|
import java.net.BindException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
import org.kne.cloud.network.mport.ServiceElement;
|
|
|
|
public class KLALBCM {
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
if(args.length==0){
|
|
System.out.println("命令行参数输入服务器任意一条线路的地址:端口可以下载服务器线路列表");
|
|
System.out.println("命令行参数输入服务器名称即可启动负载均衡");
|
|
}else if(args.length==1) {
|
|
if(args[0].equals("-gui")) {
|
|
KLALBClientGUI.main(args);
|
|
}else
|
|
if(args[0].contains(":")) {
|
|
KLALBIPList.createIPList(args[0]);
|
|
}else {
|
|
File pdis=KLALBIPList.getSLdir(args[0]);
|
|
File f=new File(pdis,"iplist.json");
|
|
if(f.exists()) {
|
|
System.out.println("加载线路列表:"+f);
|
|
byte[] bytes;
|
|
try {
|
|
KLALBIPList.updateIPList(args[0]);
|
|
bytes = Files.readAllBytes(Paths.get(f.toURI()));
|
|
STJson stj=new STJson(new String(bytes));
|
|
KLALBClient kc= new KLALBClient();
|
|
kc.getTls().addAll(stj.getTunnels());
|
|
kc.connectTunnel();
|
|
List<ServiceElement> lse=stj.getServices();
|
|
for (Iterator<ServiceElement> iterator = lse.iterator(); iterator.hasNext();) {
|
|
ServiceElement serviceElement = (ServiceElement) iterator.next();
|
|
ProxyIPPortProperties pippp=new ProxyIPPortProperties(pdis, serviceElement.name, "127.0.0.1", serviceElement.ipport.getPort());
|
|
try {
|
|
kc.open(pippp.getBindPort(),serviceElement, pippp.getBindIP());
|
|
}catch(BindException e) {
|
|
System.out.println("打开端口失败:"+pippp.getBindIP()+" "+pippp.getBindPort());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}else {
|
|
System.out.println("线路列表不存在");
|
|
}
|
|
}
|
|
}else {
|
|
|
|
}
|
|
|
|
}
|
|
}
|