默认情况下,Flume中的PollingPropertiesFileConfigurationProvider会每隔30秒去重新加载Flume agent的配置文件,如果监听到配置文件变化了,Flume会试图重新加载变化的配置文件。判断配置文件是否变化主要是基于文件的最后修改时间来的,代码片段如下:
/////////////////////////////////////////////////////////////////////
User: 过往记忆
Date: 2015-08-19
Time: 23:59
bolg:
本文地址:/archives/1467
过往记忆博客,专注于hadoop、hive、spark、shark、flume的技术博客,大量的干货
过往记忆博客微信公共帐号:iteblog_hadoop
/////////////////////////////////////////////////////////////////////
@Override
public void run() {
LOGGER.debug("Checking file:{} for changes", file);
counterGroup.incrementAndGet("file.checks");
long lastModified = file.lastModified();
if (lastModified > lastChange) {
LOGGER.info("Reloading configuration file:{}", file);
counterGroup.incrementAndGet("file.loads");
lastChange = lastModified;
try {
eventBus.post(getConfiguration());
} catch (Exception e) {
LOGGER.error("Failed to load configuration data. Exception follows.",
e);
} catch (NoClassDefFoundError e) {
LOGGER.error("Failed to start agent because dependencies were not " +
"found in classpath. Error follows.", e);
} catch (Throwable t) {
// caught because the caller does not handle or log Throwables
LOGGER.error("Unhandled error", t);
}
}
}
然而,通常情况下,用户修改了配置文件之后就不会再去修改,而且让Flume自动去加载配置文件有时还会出现问题。不过值得高兴的是,我们可以在启动Flume的时候通过加上--no-reload-conf配置来禁止Flume自动加载配置文件。这个属性在Flume的官方文档并没有介绍;而且只有Apache的Flume存在这个参数,如果你使用的是Cloudera的Flume发行版,这个参数是不支持的,不过有人在https://issues.cloudera.org/browse/DISTRO-648里面提到这个参数,如果你感兴趣可以去看下。
下面附上Apache的Flume发行版如何自动检测配置文件的变化的。
boolean reload = !commandLine.hasOption("no-reload-conf");
..........
List<lifecycleaware> components = Lists.newArrayList();
Application application;
if(reload) {
EventBus eventBus = new EventBus(agentName + "-event-bus");
PollingPropertiesFileConfigurationProvider configurationProvider =
new PollingPropertiesFileConfigurationProvider(agentName,
configurationFile, eventBus, 30);
components.add(configurationProvider);
application = new Application(components);
eventBus.register(application);
} else {
PropertiesFileConfigurationProvider configurationProvider =
new PropertiesFileConfigurationProvider(agentName,
configurationFile);
application = new Application();
application.handleConfigurationEvent(configurationProvider.getConfiguration());
}
application.start();
如果你使用的是Flume 1.6.0版本,那么上述的代码和它有点不一样,因为Flume 1.6.0还可以通过Zookeeper来配置文件,所以Flume还可以自动地检测Zookeeper里面的配置变化,并重新加载,不过这里就不贴出代码了,感兴趣的同学可以自己去看。
本博客文章除特别声明,全部都是原创!原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【Flume-ng禁用自动加载配置文件功能】(https://www.iteblog.com/archives/1467.html)

