自动删除已旋转的gc.log文件

时间:2018-06-05 09:50:20

标签: java hadoop garbage-collection metrics ambari

我们有一个hadoop集群版本2.6.4,而我们的一个Linux服务器上安装了metrics collector

root@master02 ambari-metrics-collector]#  rpm -qa | grep metrics-collector
ambari-metrics-collector-2.6.1.0-143.x86_64

/ var / log / ambari-metrics-collector 下,我们去年有 7月的gc.log文件,我们想要自动删除旋转的gc .log文件

[root@master02 ambari-metrics-collector]# ls -ltr | grep gc.log | grep -v collector| more
-rw-r--r--. 1 ams  hadoop      1430 Jul 13  2017 gc.log-201707131628
-rw-r--r--  1 ams  hadoop 178518767 Aug 28  2017 gc.log-201707160637
-rw-r--r--  1 ams  hadoop 128748829 Sep 17  2017 gc.log-201708280731
-rw-r--r--  1 ams  hadoop     60849 Sep 18  2017 gc.log-201709181421
-rw-r--r--  1 ams  hadoop     82562 Sep 18  2017 gc.log-201709181424
-rw-r--r--  1 ams  hadoop 164381669 Oct 19  2017 gc.log-201709181508
-rw-r--r--  1 ams  hadoop     46149 Oct 19  2017 gc.log-201710191738
-rw-r--r--  1 ams  hadoop  13763796 Oct 23  2017 gc.log-201710200633
-rw-r--r--  1 ams  hadoop   1048289 Oct 23  2017 gc.log-201710231021
-rw-r--r--  1 ams  hadoop   3473874 Oct 24  2017 gc.log-201710231649
-rw-r--r--  1 ams  hadoop 137289030 Nov 15  2017 gc.log-201710241352
-rw-r--r--  1 ams  hadoop   8037548 Nov 16  2017 gc.log-201711151355
-rw-r--r--  1 ams  hadoop  23919164 Nov 19  2017 gc.log-201711161246
-rw-r--r--  1 ams  hadoop 139759594 Dec  6 16:35 gc.log-201711191241
-rw-r--r--  1 ams  hadoop 184118442 Dec 25 16:13 gc.log-201712061635
-rw-r--r--  1 ams  hadoop      1440 Jan  1 04:38 gc.log-201712251613
-rw-r--r--  1 ams  hadoop      1437 Jan 10 00:03 gc.log-201801021532
-rw-r--r--  1 ams  hadoop      1439 Jan 10 01:04 gc.log-201801100004
-rw-r--r--  1 ams  hadoop      3637 Jan 10 01:11 gc.log-201801100105
-rw-r--r--  1 ams  hadoop      1437 Jan 10 01:16 gc.log-201801100113
-rw-r--r--  1 ams  hadoop      3636 Jan 10 01:24 gc.log-201801100118
-rw-r--r--  1 ams  hadoop      1438 Jan 10 01:35 gc.log-201801100126
-rw-r--r--  1 ams  hadoop      1438 Jan 10 01:42 gc.log-201801100137
-rw-r--r--  1 ams  hadoop      1436 Jan 10 02:14 gc.log-201801100144
-rw-r--r--  1 ams  hadoop      8353 Jan 10 02:19 gc.log-201801100216
-rw-r--r--  1 ams  hadoop      1437 Jan 11 09:08 gc.log-201801110730
-rw-r--r--  1 ams  hadoop      1436 Jan 11 09:19 gc.log-201801110909
-rw-r--r--  1 ams  hadoop       766 Jan 11 09:20 gc.log-201801110920
-rw-r--r--  1 ams  hadoop       765 Jan 11 09:26 gc.log-201801110926

来自ambari gui的高级ams-hbase-env,我们看到以下内容:

{% if java_version < 8 %}
export HBASE_MASTER_OPTS=" -XX:PermSize=64m -XX:MaxPermSize={{hbase_master_maxperm_size}} -Xms{{hbase_heapsize}} -Xmx{{hbase_heapsize}} -Xmn{{hbase_master_xmn_size}} -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_REGIONSERVER_OPTS="-XX:MaxPermSize=128m -Xmn{{regionserver_xmn_size}} -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -Xms{{regionserver_heapsize}} -Xmx{{regionserver_heapsize}}"
{% else %}
export HBASE_MASTER_OPTS=" -Xms{{hbase_heapsize}} -Xmx{{hbase_heapsize}} -Xmn{{hbase_master_xmn_size}} -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_REGIONSERVER_OPTS=" -Xmn{{regionserver_xmn_size}} -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -Xms{{regionserver_heapsize}} -Xmx{{regionserver_heapsize}}"
{% endif %}

我们尝试设置HBASE_MASTER_OPTS或HBASE_REGIONSERVER_OPTS
-XX:NumberOfGClogFiles = 10 以便只获取10个gc.log文件,但是指标收集器无法启动,似乎是因为语法不正确

推荐 - http://www.oracle.com/technetwork/java/vmoptions-jsp-140102.html

export HBASE_MASTER_OPTS=" -XX:PermSize=64m -XX:MaxPermSize={{hbase_master_maxperm_size}} -Xms{{hbase_heapsize}} -Xmx{{hbase_heapsize}} -Xmn{{hbase_master_xmn_size}} -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:NumberOfGClogFiles=1"

请建议如何自动删除旋转的gc.log文件

1 个答案:

答案 0 :(得分:0)

当我们想要进行GC日志轮换时,那么在这种情况下,我们必须一起定义几个属性以使其正常工作,如下面的“-Xloggc”选项。

-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M

需要定义NumberOfGClogFiles选项会导致JVM选项不一致而JVM将无法启动如下:

所以我试试这个:

HBASE_MASTER_OPTS=" -XX:PermSize=64m -XX:MaxPermSize={{hbase_master_maxperm_size}} -Xms{{hbase_heapsize}} -Xmx{{hbase_heapsize}} -Xmn{{hbase_master_xmn_size}} -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=3 -XX:GCLogFileSize=20M" 
.

注意:同样在我的情况下,JVM没有启动,因为我的情况"-XX:NumberOfGClogFiles"中有一个错误(这里我使用小写日志),因为正确的选项在{{1}这样的选项中有大写字母L }