1. 程式人生 > 其它 >本地IDEA連結遠端Hadoop

本地IDEA連結遠端Hadoop

本文使用的Hadoop為2.7.7,版本如果不同要下載相應版本的檔案

  1. 配置本地的Hadoop庫(不需完整安裝,但是要有環境支援)

下載檔案

https://github.com/speedAngel/hadoop2.7.7

  1. 解壓到任意路徑,沒有中文字元和空格

  1. 把解壓包的bin替換到解壓路徑

  2. 把bin中的Hadoop.dll複製到C:\Windows\System32

  3. 配置環境變數

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
  1. IDEA設定本地Hadoop路徑

  1. 匯入依賴(注意版本一致)

    <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>
​
  1. 把叢集的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");

轉自:http://www.pingtaimeng.com/article/detail/id/1067178