Hadoop的配置

package xxx.bigdata.common;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.hadoop.conf.Configuration;


/**
 * Hadoop连接配置
 * 
 * @author Ethan
 * @version 1.0 2017-03-12
 */
public class ConfigurationHadoop {

private static final String PROPERTY_FILE = "hadoop.properties";

/**
* 获取默认连接

* @return
*/
public static Configuration getConfigurationHadoop() {

return getConfigurationHadoop(PROPERTY_FILE);
}

/**
* 获取指定的Hadoop连接

* @param propertiesFile
* @return
*/
public static Configuration getConfigurationHadoop(String propertiesFile) {
Properties pro = getProperties(propertiesFile);

Configuration conf = new Configuration();
conf.set("fs.default.name", pro.getProperty("fs.default.name"));


conf.set("hbase.master", pro.getProperty("hbase.master"));
conf.set("hbase.zookeeper.quorum", pro.getProperty("hbase.zookeeper.quorum"));
conf.set("hbase.zookeeper.property.clientPort", pro.getProperty("hbase.zookeeper.property.clientPort"));

System.setProperty("HADOOP_USER_NAME", pro.getProperty("user.name"));


return conf;
}
/**
* 加载对应连接的资源文件
* @param propertiesFile
* @return
*/
private static Properties getProperties(String propertiesFile) {
Properties pro = new Properties();
try {
pro.load(ConfigurationHadoop.class.getResourceAsStream(propertiesFile));
} catch (FileNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return pro;
}

public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf = getConfigurationHadoop();
System.out.println(conf.get("fs.default.name"));
}

}


hadoop.properties文件:

fs.default.name=hdfs://cmaster1.cn:8020
user.name=oozie
hbase.master=cmaster1.cn:16000
hbase.zookeeper.quorum=cmaster1.cn,cmaster0.cn,cslave0.cn
hbase.zookeeper.property.clientPort=2181

猜你喜欢

转载自blog.csdn.net/zyc_996/article/details/65936606