Hadoop(十):本地IDEA链接远程Hadoop
-
配置本地的Hadoop库(不需完整安装,但是要有环境支持)
下载文件
-
解压到任意路径,没有中文字符和空格
-
把解压包的bin替换到解压路径
-
把bin中的Hadoop.dll复制到C:\Windows\System32
-
配置环境变量
HADOOP_HOME D:\Environment\hadoop-2.7.7 HADOOP_CONF_DIR D:\Environment\hadoop-2.7.7\etc\hadoop YARN_CONF_DIR %HADOOP_CONF_DIR% PATH %HADOOP_HOME%\bin
-
IDEA设置本地Hadoop路径
-
导入依赖(注意版本一致)
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.7.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-mapreduce-client-core --> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-jobclient</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.19</version> </dependency> <!--工具类,可以复制对象--> <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils --> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.4</version> </dependency> </dependencies>
-
把集群的core-site.xml和hdfs-site.xml文件放到项目resource路径下。修改对应IP地址
-
core-site.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://192.168.98.129:9000</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/usr/hop/hadoop-2.7.7/data/hopdata</value> </property> </configuration>
-
hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. --> <!-- Put site-specific property overrides in this file. --> <configuration> <property> <name>dfs.namenode.secondary.http-address</name> <value>192.168.98.130:50090</value> </property> <property> <name>dfs.replication</name> <value>2</value> </property> </configuration>
-
运行的Main方法里首行添加
System.setProperty("HADOOP_USER_NAME","root");
System.setProperty("HADOOP_USER_PASSWORD","PASSWORD");