<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>io.sort.factor</name> <value>10</value> <description>The number of streams to merge at once while sorting files. This determines the number of open file handles.</description> </property> <property> <name>dfs.name.dir</name> <value>${hadoop.tmp.dir}/dfs/name</value> <description>Determines where on the local filesystem the DFS name nodeshould store the name table(fsimage). ……</description> </property> <property> <name>dfs.web.ugi</name> <value>webuser,webgroup</value> <final>true</final> <description>The user account used by the web interface. Syntax: USERNAME,GROUP1,GROUP2, ……</description> </property> </configuration>Hadoop配置文件的根元素是configuration,一般只包含子元素property。每一个property元素就是一个配置 项,配置文件不支持分层或分级。每个配置项一般包括配置属性的名称name、值value和一个关于配置项的描述description;元素final 和Java中的关键字final类似,意味着这个配置项是“固定不变的”。final一般不出现,但在合并资源的时候,可以防止配置项的值被覆盖。
在 上面的示例文件中,配置项dfs.web.ugi的值是“webuser,webgroup”,它是一个final配置项;从description看, 这个配置项配置了Hadoop Web界面的用户账号,包括用户名和用户组信息。这些信息可以通过Configuration类提供的方法访问。
在 Configuration中,每个属性都是String类型的,但是值类型可能是以下多种类型,包括Java中的基本类型,如 boolean(getBoolean)、int(getInt)、long(getLong)、float(getFloat),也可以是其他类型,如 String(get)、java.io.File(getFile)、String数组(getStrings)等。以上面的配置文件为 例,getInt("io.sort.factor")将返回整数10;而getStrings("dfs.web.ugi")返回一个字符串数组,该数 组有两个元素,分别是webuser和webgroup。
合并资源指将多个配置文件合并,产生一个配置。如果有两个配置文件,也就是两个资源,如core-default.xml和core-site.xml,通过Configuration类的loadResources()方法,把它们合并成一个配置。代码如下:
Configurationconf = new Configuration();
conf.addResource("core-default.xml");
conf.addResource("core-site.xml");
如 果这两个配置资源都包含了相同的配置项,而且前一个资源的配置项没有标记为final,那么,后面的配置将覆盖前面的配置。上面的例子中,core- site.xml中的配置将覆盖core-default.xml中的同名配置。如果在第一个资源(core-default.xml)中某配置项被标记 为final,那么,在加载第二个资源的时候,会有警告提示。3 直接运行Configuration.java则会调用默认配置文件部分结果如下:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>io.sort.factor</name> <value>10</value> <description>The number of streams to merge at once while sorting files. This determines the number of open file handles.</description> </property> <property> <name>dfs.name.dir</name> <value>${hadoop.tmp.dir}/dfs/name</value> <description>Determines where on the local filesystem the DFS name nodeshould store the name table(fsimage). ……</description> </property> <property> <name>dfs.web.ugi</name> <value>webuser,webgroup</value> <final>true</final> <description>The user account used by the web interface. Syntax: USERNAME,GROUP1,GROUP2, ……</description> </property> </configuration><?xml version="1.0" encoding="UTF-8" standalone="no"?> <configuration> <property> <name>ipc.client.fallback-to-simple-auth-allowed</name> <value>false</value> <source>core-default.xml</source> </property> <property> <name>file.bytes-per-checksum</name> <value>512</value> <source>core-default.xml</source> </property> <property> <name>ipc.server.tcpnodelay</name> <value>false</value> <source>core-default.xml</source> </property> <property> <name>ftp.client-write-packet-size</name> <value>65536</value> <source>core-default.xml</source> </property> <property> <name>nfs3.mountd.port</name> <value>4272</value> <source>core-site.xml</source> </property> </configuration>Hadoop配置文件的根元素是configuration,一般只包含子元素property。每一个property元素就是一个配置 项,配置文件不支持分层或分级。每个配置项一般包括配置属性的名称name、值value和一个关于配置项的描述description;元素final 和Java中的关键字final类似,意味着这个配置项是“固定不变的”。final一般不出现,但在合并资源的时候,可以防止配置项的值被覆盖。
在 上面的示例文件中,配置项dfs.web.ugi的值是“webuser,webgroup”,它是一个final配置项;从description看, 这个配置项配置了Hadoop Web界面的用户账号,包括用户名和用户组信息。这些信息可以通过Configuration类提供的方法访问。
在 Configuration中,每个属性都是String类型的,但是值类型可能是以下多种类型,包括Java中的基本类型,如 boolean(getBoolean)、int(getInt)、long(getLong)、float(getFloat),也可以是其他类型,如 String(get)、java.io.File(getFile)、String数组(getStrings)等。以上面的配置文件为 例,getInt("io.sort.factor")将返回整数10;而getStrings("dfs.web.ugi")返回一个字符串数组,该数 组有两个元素,分别是webuser和webgroup。
合并资源指将多个配置文件合并,产生一个配置。如果有两个配置文件,也就是两个资源,如core-default.xml和core-site.xml,通过Configuration类的loadResources()方法,把它们合并成一个配置。代码如下:
Configurationconf = new Configuration();
conf.addResource("core-default.xml");
conf.addResource("core-site.xml");
如 果这两个配置资源都包含了相同的配置项,而且前一个资源的配置项没有标记为final,那么,后面的配置将覆盖前面的配置。上面的例子中,core- site.xml中的配置将覆盖core-default.xml中的同名配置。如果在第一个资源(core-default.xml)中某配置项被标记 为final,那么,在加载第二个资源的时候,会有警告提示。3 直接运行Configuration.java则会调用默认配置文件部分结果如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <configuration> <property> <name>ipc.client.fallback-to-simple-auth-allowed</name> <value>false</value> <source>core-default.xml</source> </property> <property> <name>file.bytes-per-checksum</name> <value>512</value> <source>core-default.xml</source> </property> <property> <name>ipc.server.tcpnodelay</name> <value>false</value> <source>core-default.xml</source> </property> <property> <name>ftp.client-write-packet-size</name> <value>65536</value> <source>core-default.xml</source> </property> <property> <name>nfs3.mountd.port</name> <value>4272</value> <source>core-site.xml</source> </property> </configuration>
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>io.sort.factor</name> <value>10</value> <description>The number of streams to merge at once while sorting files. This determines the number of open file handles.</description> </property> <property> <name>dfs.name.dir</name> <value>${hadoop.tmp.dir}/dfs/name</value> <description>
合并资源指将多个配置文件合并,产生一个配置
最新推荐文章于 2022-12-05 10:06:06 发布
Hadoop配置文件的根元素configuration包含property元素,每个property表示一个配置项。final属性用于防止合并资源时配置项被覆盖。通过Configuration类的loadResources()方法可以合并多个配置文件,后面的配置会覆盖前面的,除非前面的配置项被标记为final。直接运行Configuration.java将使用默认配置文件。
摘要由CSDN通过智能技术生成