第一步:
public class CopyToHDFS {
public static void main(String[] args) throws IOException {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://mycluster");
FileSystem fs = FileSystem.get(conf);
fs.copyFromLocalFile(new Path("/home/lance/log.txt"), new Path("/log"));
}
}
第二步:
把下面文件复制到一种是直接把hadoop的配置文件放到工程目录下或则在代码里,设置下面属性
core-site.xml
- <configuration>
- <property>
- <name>fs.defaultFS</name>
- <value>hdfs://mycluster</value>
- </property>
- </configuration>
复制代码
hdfs-site.xml
- <configuration>
- <property>
- <name>dfs.nameservices</name>
- <value>mycluster</value>
- </property>
- <property>
- <name>dfs.ha.namenodes.mycluster</name>
- <value>nn1, nn2</value>
- </property>
- <property>
- <name>dfs.namenode.rpc-address.mycluster.nn1</name>
- <value>192.168.11.2:9000</value>
- </property>
- <property>
- <name>dfs.namenode.rpc-address.mycluster.nn2</name>
- <value>192.168.11.7:9000</value>
- </property>
- <property>
- <name>dfs.client.failover.proxy.provider.mycluster</name>
- <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
- </property>
- </configuration>
复制代码
|