我们有hadoop集群版本2.6.4,而指标收集器安装在我们的一台Linux服务器上
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 下,去年我们有 Jul 的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中的Advanced 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文件
最佳答案
当我们要进行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没有启动,因为在我的情况下有一个Typo
"-XX:NumberOfGClogFiles"
(在这里我使用小写日志),其中正确的选项在大写L中是类似"-XX:NumberOfGCLogFiles"
的选项