目前zookeeper的日志配置中,只配置了一个输出到console的appender,并不具备滚动策略,所以随着时间的推移,标准输出日志中的内容越来越多,为了提升服务的稳定性,保障集群正常运行,对这部分配置需要进行修改。
这里将演示配置zookeeper日志为按每个日志文件大小1GB来切割,并保留30个切割文件的日志策略。
手动升级步骤
按照如下方式顺序进行。
- 登录ambari,找到zookeeper服务的zookeeper-log4j配置,修改三个zk节点上的配置文件中的log4j.properties为如下内容并保存,这一步可以登录到对应节点上的/etc/zookeeper/conf下查看log4j.properties文件内容是否更新来验证:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
#
# ZooKeeper Logging Configuration
#
# append to rolling log file
log4j.rootLogger=${zookeeper.root.logger}
#
# Add ROLLINGFILE to rootLogger to get log file output
# Log DEBUG level and above messages to a log file
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=WARN
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
# Max log file size of 1024MB
log4j.appender.ROLLINGFILE.MaxFileSize=1024MB
# uncomment the next line to limit number of backup files
log4j.appender.ROLLINGFILE.MaxBackupIndex=30
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
其中,log4j.appender.ROLLINGFILE.Threshold=WARN 设置日志级别为 WARN,可以根据需要设置 INFO 或者 DEBUG
2. 在ambari上重启zk服务,重启后配置生效,登录到对应节点的/mnt/bmr/log/zookeeper目录,如果新生成了zookeeper-*.log这个模式的文件,即修改成功。文章来源:https://www.toymoban.com/news/detail-736381.html
验证
为了验证日志滚动功能,在验证阶段设置日志切割阈值为1KB,日志级别为DEBUG,保留3份文件。
测试结果如下,滚动正常:
文章来源地址https://www.toymoban.com/news/detail-736381.html
到了这里,关于zookeeper 设置日志级别和日志滚动策略的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!