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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值