Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log of nacos optimization #1510

Closed
Comven opened this issue Jul 9, 2019 · 2 comments
Closed

log of nacos optimization #1510

Comven opened this issue Jul 9, 2019 · 2 comments

Comments

@Comven
Copy link

Comven commented Jul 9, 2019

nacos从第一个版本发布以来,个人觉得在日志输出和启动脚本参数配置上有不少吐槽点,特别是日志输出部分,以下是个人罗列的,仅代表个人看法。

  • 1、日志输出

nacos的日志输出非常之多,而且不支持在配置文件application.properties中做精细化的开关或者级别配置。唯一可以在应用配置文件中配置的是nacos.logs.path来配置日志输出路劲(但这个配置并不能完全限定所有日志),默认是获取nacos.home变量的路劲,并在路劲下创建logs文件夹来存储,而nacos.home是在startup.sh脚本中传入的,最终获取的是程序所在目录下。而早期版本甚至会在系统用户目录下创建logsnacos两个目录来保存日志,1.1.0版本默认会在当前程序的根目录下创建logs来目录来保存日志。

其次,我配置了nacos.logs.path参数启动后,仍旧有日志会打印到${nacos.home}/logs目录下主要是cmdb-main.log,nacos_gc.log,start.out等。其次在linux用户根目录下还会创建一个nacos/logs的目录保存config.log以及naming.log日志。

而我们自定义的日志输出路劲日志也非常之多,特别是tomcatweb访问日志access_log,客户端越多日志越多,我写了10个客户端左右,不跑业务每天的日志量也是在80M300M左右不等,建议在配置文件中默认false关闭。

另外,nacoslogback配置文件nacos-logback.xml中对各类日志的块大小分割保存并未设置压缩,当客户端太多的时候日志量非常之大,并且各个日志的分割标准也不相同,最大的2G分割,最小的20M分割。

  • 2、JVM内存大小

nacosJVM参数大小是写死在了shell脚本中,而且集群情况下,为了避免频繁GC,设置的最小和最大内存为2G,相当于说只要启动一份nacos-server程序,就会占用掉2G的内存空间,即时可能它自身根本用不到(当然这里本人并未测试过nacos-server程序使用内存的需求量,大内存可以直接忽略),之前我使用eureka-server做注册中心时512M跑几十个客户端程序,没有任何问题。建议在application.properties中增加上调整JVM内存大小的参数。这样更方便配置修改,而不是直接修改shell脚本

  • 3、shutdown.sh脚本

默认的shutdown.sh脚本脚本在集群情况下执行会将同一台机子上的所有节点都关闭掉,因为shell命令查找的是有nacos.nacos标记的pid,当搭建伪集群的情况,这种情况就非常危险了。一旦执行脚本所有nacos节点全部关闭了。个人觉得即使不考虑采用伪集群方案,为了避免风险shutdown.sh脚本都应该默认关闭当前目录下的节点更为安全,例如将原脚本更改为

#!/bin/sh

# Copyright 1999-2018 Alibaba Group Holding Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
BIN_DIR=$(cd `dirname $0`;pwd)
#获取项目根目录
DEPLOY_DIR=$(cd ${BIN_DIR};cd ..;pwd)

pid=`ps ax | grep -i $DEPLOY_DIR |grep java | grep -v grep | awk '{print $1}'`
if [ -z "$pid" ] ; then
        echo "No nacosServer running."
        exit -1;
fi

echo "The nacosServer(${pid}) is running..."

kill ${pid}

echo "Send shutdown request to nacosServer(${pid}) OK"

@nacos-bot
Copy link
Collaborator

Hi @Comven, we detect non-English characters in the issue. This comment is an auto translation from @nacos-bot to help other users to understand this issue.
We encourage you to describe your issue in English which is more friendly to other users.

log of nacos optimization

Since the release of the first version of nacos, I personally feel that there are a lot of spit points on the log output and startup script parameter configuration, especially the log output part. The following are personal lists, which only represent personal opinions.

  • 1, log output

The log output of nacos is very large, and it does not support fine-grained switch or level configuration in the configuration file application.properties. The only thing that can be configured in the application configuration file is nacos.logs.path to configure the log output path strength (but this configuration does not fully limit all logs). The default is to get the road strength of the nacos.home variable, and The road creates a logs folder to store, and nacos.home is passed in the startup.sh script, and finally gets the directory where the program is located. The earlier version will even create two directories logs and nacos in the system user directory to save the log. The 1.1.0 version will create a logs directory to save the log by default in the root directory of the current program.

Secondly, after I configured the nacos.logs.path parameter, the logs will still be printed to the ${nacos.home}/logs directory, mainly cmdb-main.log, nacos_gc.log, start.out and so on. Secondly, in the linux user root directory, a nacos/logs directory will be created to save the config.log and naming.log logs.

And our custom log output road log is also very much, especially tomcat web access log access_log, the more the client the more logs, I wrote about 10 clients, do not run the business The daily log volume is also in the range of 80M to 300M. It is recommended to turn off the default by default in the configuration file.

In addition, nacos's logback configuration file nacos-logback.xml does not set compression for block size partitioning of various types of logs. When there are too many clients, the amount of logs is very large, and each log is The segmentation criteria are also different, with the largest 2G segmentation and the smallest 20M segmentation.

  • 2, JVM memory size

The JVM parameter size of nacos is written in the shell script, and in the case of clustering, in order to avoid frequent GC, the minimum and maximum memory set is 2G, which is equivalent to just starting a copy. The nacos-server program will take up 2G of memory space, which may not be used by itself. (Of course, I have not tested the demand for memory used by the nacos-server program. Large memory can be ignored directly.) Before, I used eureka-server to do the registration center. The 512Mran dozens of client programs without any problems. It is recommended to add a parameter to adjustJVMmemory size inapplication.properties. This makes it easier to configure changes instead of directly modifying the shell` script.

  • 3, shutdown.sh script

The default shutdown.sh script script will shut down all nodes on the same machine in the cluster case, because the shell command looks for the pid with the nacos.nacos tag. In the case of clusters, this situation is very dangerous. Once the script is executed, all the nacos nodes are closed. Personally feel that even if you do not consider the use of pseudo-cluster scheme, in order to avoid the risk shutdown.sh script should be more secure by default to close the node in the current directory, such as changing the original script to

#!/bin/sh

# Copyright 1999-2018 Alibaba Group Holding Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
BIN_DIR=$(cd `dirname $0`;pwd)
#Get the project root directory
DEPLOY_DIR=$(cd ${BIN_DIR};cd ..;pwd)

pid=`ps ax | grep -i $DEPLOY_DIR |grep java | grep -v grep | awk '{print $1}'`
if [ -z "$pid" ] ; then
        echo "No nacosServer running."
        exit -1;
fi

echo "The nacosServer(${pid}) is running..."

kill ${pid}

echo "Send shutdown request to nacosServer(${pid}) OK"

@nkorange
Copy link
Collaborator

  1. The log issue is fixed and tracked in What is the meaning of each log file? Do Nacos need so many log files? #290
  2. The JVM options cannot be edited in application.properties, they can be modified in the startup.sh.
  3. The shutdown.sh problem is fixed and tracked in It is recommended that the shutdown.sh script close only the nodes in the current directory, not all nodes. #1507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants