From 1a79df14785cbb50ba2b8aecfc6bb06f026bc297 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Thu, 5 May 2022 13:28:26 +0800 Subject: [PATCH] update docker configs --- build.gradle | 3 +- script/log4j2.properties | 40 ++++++++++++++++++ script/ncstart.sh | 2 +- .../org/bdware/server/NodeCenterServer.java | 34 +++++++++++---- src/main/resources/log4j2.properties | 41 +++++++++++++++---- 5 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 script/log4j2.properties diff --git a/build.gradle b/build.gradle index fa32020..c70334b 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,7 @@ task copyScript(type: Copy) { include 'ncstop.sh' include 'ncconfig.json.template' include 'updateCluster.sh' + include 'log4j2.properties' } into "./build/output" println("copyScript done !") @@ -101,7 +102,7 @@ task copyWebContent(type: Copy) { task buildBDServerClusterZip(type: Zip, dependsOn: ["copyWebContent", "copyScript", "copyJar"]) { from './build/output/' duplicatesStrategy = DuplicatesStrategy.INCLUDE - archiveFileName = 'bdserver-cluster.zip' + archiveFileName = 'bdcluster-all.zip' destinationDirectory = file('build/') } diff --git a/script/log4j2.properties b/script/log4j2.properties new file mode 100644 index 0000000..c7e74a5 --- /dev/null +++ b/script/log4j2.properties @@ -0,0 +1,40 @@ +filter.threshold.type=ThresholdFilter +filter.threshold.level=debug +appender.console.type=Console +appender.console.name=STDOUT +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White} + +appender.logrolling.type=RollingFile +appender.logrolling.name=infoLogFile +appender.logrolling.append=true +appender.logrolling.fileName=./log/cm.log +appender.logrolling.filePattern=./log/cm-%i.log +appender.logrolling.layout.type=PatternLayout +appender.logrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.logrolling.policies.type = Policies +appender.logrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.logrolling.policies.size.size = 100MB +appender.logrolling.strategy.type = DefaultRolloverStrategy +appender.logrolling.strategy.max = 5 + +appender.errrolling.type=RollingFile +appender.errrolling.name=errorLogFile +appender.errrolling.append=true +appender.errrolling.fileName=./log/cm.err +appender.errrolling.filePattern=./log/cm-%i.err +appender.errrolling.layout.type=PatternLayout +appender.errrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.errrolling.policies.type = Policies +appender.errrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.errrolling.policies.size.size = 100MB +appender.errrolling.strategy.type = DefaultRolloverStrategy +appender.errrolling.strategy.max = 5 + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT +rootLogger.appenderRef.errorFile.ref=errorLogFile +rootLogger.appenderRef.errorFile.level=error +rootLogger.appenderRef.infoFile.ref=infoLogFile +rootLogger.appenderRef.infoFile.level=info +rootLogger.appenderRef.log.ref=log diff --git a/script/ncstart.sh b/script/ncstart.sh index 2d236f5..317d201 100644 --- a/script/ncstart.sh +++ b/script/ncstart.sh @@ -20,7 +20,7 @@ fi # ps -ef | grep java | grep bdcluster | grep NodeCenterServer | awk '{print $2}' |xargs kill -9 #-Dlog4j.configuration=file: -java -Dfile.encoding=UTF-8 -Dlog4j.configuration=file:./log4j.properties -cp "./libs/*:bdcluster.jar" org.bdware.server.NodeCenterServer 1 >./log/nc.log 2>./log/nc.err & +java -Dfile.encoding=UTF-8 -Dlog4j.configurationFile=./log4j2.properties -cp "./libs/*:bdcluster.jar" org.bdware.server.NodeCenterServer 1 >./log/nc.log 2>./log/nc.err & #以下可启用https/wss,其中,./ssl/xxx.pfx为ssl证书的路径,:后面的123456是密码。 #java -Dfile.encoding=UTF-8 -cp "./libs/*:bdcluster.jar" org.bdware.server.NodeCenterServer -service-port=18002 -enable-ssl=./ssl/xxx.pfx:123456 -do-repo-ip=127.0.0.1 -do-repo-port=18098 1 > ./log/cm.log 2> ./log/cm.err & diff --git a/src/main/java/org/bdware/server/NodeCenterServer.java b/src/main/java/org/bdware/server/NodeCenterServer.java index 6966dd0..81c1a18 100644 --- a/src/main/java/org/bdware/server/NodeCenterServer.java +++ b/src/main/java/org/bdware/server/NodeCenterServer.java @@ -29,10 +29,14 @@ import org.bdware.server.irp.LocalLHSProxy; import org.bdware.server.nodecenter.*; import org.bdware.server.ws.DelimiterCodec; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.Date; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -125,18 +129,30 @@ public class NodeCenterServer { CMDConf cmf = CMDConf.parseFile(CONFIG_PATH).parseArgs(args); configServer(cmf); - - if (LocalLHSProxy.enabled) { - threadPool = Executors.newSingleThreadExecutor(); - threadPool.execute(() -> { - try { - LocalLHSProxy.start(); - } catch (Exception e) { - LOGGER.error("local LHS proxy failed: " + e.getMessage()); + File keyFile = new File("manager.key"); + if (keyFile.exists()) { + try { + BufferedReader br = new BufferedReader(new FileReader(keyFile)); + String pubKey = br.readLine(); + String nowManager = + KeyValueDBUtil.instance.getValue( + NCTables.ConfigDB.toString(), NCManagerAction.centerManger); + // manager.key is used when node manager isn' set + if (null == nowManager || nowManager.isEmpty()) { + KeyValueDBUtil.instance.setValue( + NCTables.ConfigDB.toString(), NCManagerAction.centerManger, pubKey); + KeyValueDBUtil.instance.setValue( + NCTables.ConfigDB.toString(), NCManagerAction.clusterName, "clusterName_" + pubKey.substring(0, 5)); + KeyValueDBUtil.instance.setValue(NCTables.NodeUser.toString(), pubKey, "NodeManager"); + KeyValueDBUtil.instance.setValue( + NCTables.NodeTime.toString(), pubKey, Long.toString(new Date().getTime())); + LOGGER.info("set node manager from manager.key"); } - }); + } catch (IOException ignored) { + } } + listenSocket(cmf.servicePort + 1); OtherNCProxy.instance.init(); diff --git a/src/main/resources/log4j2.properties b/src/main/resources/log4j2.properties index 7ad16fb..c7e74a5 100644 --- a/src/main/resources/log4j2.properties +++ b/src/main/resources/log4j2.properties @@ -4,12 +4,37 @@ appender.console.type=Console appender.console.name=STDOUT appender.console.layout.type=PatternLayout appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White} -appender.rolling.type=File -appender.rolling.name=log -appender.rolling.append=true -appender.rolling.fileName=./log/nc.log -appender.rolling.layout.type=PatternLayout -appender.rolling.layout.pattern=%d-%m%n -rootLogger.level=debug + +appender.logrolling.type=RollingFile +appender.logrolling.name=infoLogFile +appender.logrolling.append=true +appender.logrolling.fileName=./log/cm.log +appender.logrolling.filePattern=./log/cm-%i.log +appender.logrolling.layout.type=PatternLayout +appender.logrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.logrolling.policies.type = Policies +appender.logrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.logrolling.policies.size.size = 100MB +appender.logrolling.strategy.type = DefaultRolloverStrategy +appender.logrolling.strategy.max = 5 + +appender.errrolling.type=RollingFile +appender.errrolling.name=errorLogFile +appender.errrolling.append=true +appender.errrolling.fileName=./log/cm.err +appender.errrolling.filePattern=./log/cm-%i.err +appender.errrolling.layout.type=PatternLayout +appender.errrolling.layout.pattern=[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n +appender.errrolling.policies.type = Policies +appender.errrolling.policies.size.type = SizeBasedTriggeringPolicy +appender.errrolling.policies.size.size = 100MB +appender.errrolling.strategy.type = DefaultRolloverStrategy +appender.errrolling.strategy.max = 5 + +rootLogger.level=info rootLogger.appenderRef.stdout.ref=STDOUT -rootLogger.appenderRef.log.ref=log \ No newline at end of file +rootLogger.appenderRef.errorFile.ref=errorLogFile +rootLogger.appenderRef.errorFile.level=error +rootLogger.appenderRef.infoFile.ref=infoLogFile +rootLogger.appenderRef.infoFile.level=info +rootLogger.appenderRef.log.ref=log