您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關怎么配置hadoop,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
一、配置hadoop
首先去github上面下載源碼:http://hadoop.apache.org/releases.html#News
在linux中安裝jdk和配置ssh免密碼登陸,其實最開始我并沒有區配置免密碼的,后來發現免密碼登陸真方便。免密碼登陸就是在控制臺上面輸入:ssh -keygen 然后一路回車就可以了。
我是把hadoop解壓后放在/home/admin1/下載/hadoop-2.5.2。我們主要是在etc/hadoop 中配置文件。
1、core-site.xml
<pre name="code" class="java"><configuration> <property> <name>fs.defaultFS</name> <value>hdfs://ubuntu2:9000</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/admin1/hadoop/hadoop-2.5.2/tmp/hadoop</value> </property> </configuration>
2、hdfs-site.xml
<configuration> <property> <name>dfs.replication</name> <value>1</value> </property> </configuration>
3、mapred-site.xml
<pre name="code" class="java"> <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration>
4、在yarn-site.xml中
<configuration> <property> <name>yarn.resourcemanager.hostname</name> <value>ubuntu2</value> </property> <!-- reducer獲取數據的方式 --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration>
5、在hadoop-env.sh中添加
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 # The jsvc implementation to use. Jsvc is required to run secure datanodes. #export JSVC_HOME=${JSVC_HOME} export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/home/admin1/hadoop/hadoop-2.5.2 "}
6、記得把salver改成你主機的名字,我這里就是把localhost改成了ubuntu2.因為我主機名就是ubuntu2
還需要配置一下java_home:在hadoop-env.sh中:(就是改成你的絕對路徑就可以了,不要用相對路徑)。
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
如果你運行報錯的話,那應該就是java_home沒有配置了
用命令行輸入: sudo gedit /etc/profile
在最末尾加上:
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME export PATH export CLASSPATH
這樣基本上應該是可以運行了:
啟動方式: 在/home/admin1/下載/hadoop-2.5.2 中 使用:
bin/hadoop namenode -format
sbin/start-all.sh
訪問地址是:
http://localhost:50070/
http://localhost:8088/cluster
如果想要關閉則:sbin/stop-all.sh
問題:
若hadoop報錯,則配置hadoop命令:
export HADOOP_HOME=/home/admin1/下載/hadoop-2.5.2
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
若datanode未啟動
rm -rf /usr/hadoop/tmp/*
rm -rf /tmp/hadoop*
在1之前進行以上兩步操作。
二、配置eclipse
因為我是是直接把eclipse安裝在linux中的,同時我用的還是4.5版本的,然后出現了各種各樣奇奇怪怪的問題。我最開始以為是hadoop-eclipse-plugin-2.5.2.jar有問題,然后我就去下了應該ant和hadoop2x-eclipse-plugin-master來重新編譯,編譯的方法大致是這樣:
1、先去下載hadoop2x-eclipse-plugin-master,https://github.com/winghc/hadoop2x-eclipse-plugin
2、下載ant:http://ant.apache.org/bindownload.cgi
3、分別解壓出來,如果你的是在win下面就需要配置一下環境變量,在linux下面不要配置其實也是可以運行的。進入你剛才解壓下來的 /hadoop2x-eclipse-plugin-master/src/contrib/eclipse-plugin中。
4、在上面哪個目錄下,對以下文件進行修改:
在vxy中:libraries.properties
里面的 版本記得要和你直接版本相對應,如果你不找到你的版本的話可以去你哪個hadoop文件的share/hadoop中找,其實有個很簡單的辦法,你可以直接把我這段代碼復制過去,等下編譯的時候匯報哪個jar包的版本不對,然后你可以根據報錯提示來改就可以了。
# 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. #This properties file lists the versions of the various artifacts used by hadoop and components. #It drives ivy and the generation of a maven POM # This is the version of hadoop we are generating hadoop.version=2.5.2 hadoop-gpl-compression.version=0.1.0 #These are the versions of our dependencies (in alphabetical order) apacheant.version=1.7.0 ant-task.version=2.0.10 asm.version=3.2 aspectj.version=1.6.5 aspectj.version=1.6.11 checkstyle.version=4.2 commons-cli.version=1.2 commons-codec.version=1.4 commons-collections.version=3.2.1 commons-configuration.version=1.6 commons-daemon.version=1.0.13 commons-httpclient.version=3.1 commons-lang.version=2.6 commons-logging.version=1.1.3 commons-logging-api.version=1.0.4 commons-math.version=3.1.1 commons-el.version=1.0 commons-fileupload.version=1.2 commons-io.version=2.4 commons-net.version=3.1 core.version=3.1.1 coreplugin.version=1.3.2 hsqldb.version=1.8.0.10 ivy.version=2.1.0 jasper.version=5.5.12 jackson.version=1.9.13 #not able to figureout the version of jsp & jsp-api version to get it resolved throught ivy # but still declared here as we are going to have a local copy from the lib folder jsp.version=2.1 jsp-api.version=5.5.12 jsp-api-2.1.version=6.1.14 jsp-2.1.version=6.1.14 jets3t.version=0.6.1 jetty.version=6.1.26 jetty-util.version=6.1.26 jersey-core.version=1.9 jersey-json.version=1.9 jersey-server.version=1.9 junit.version=4.11 jdeb.version=0.8 jdiff.version=1.0.9 json.version=1.0 kfs.version=0.1 log4j.version=1.2.17 lucene-core.version=2.3.1 mockito-all.version=1.8.5 jsch.version=0.1.42 oro.version=2.0.8 rats-lib.version=0.5.1 servlet.version=4.0.6 servlet-api.version=2.5 slf4j-api.version=1.7.5 slf4j-log4j12.version=1.7.5 wagon-http.version=1.0-beta-2 xmlenc.version=0.52 xerces.version=1.4.4 protobuf.version=2.5.0 guava.version=11.0.2 netty.version=3.6.2.Final
build.xml
這個也是同理的,如果你版本不對可以按上面的道理來的。 xml的文件頭記得要頂格寫。
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You 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. --> <project default="jar" name="eclipse-plugin"> <import file="../build-contrib.xml"/> <path id="eclipse-sdk-jars"> <fileset dir="${eclipse.home}/plugins/"> <include name="org.eclipse.ui*.jar"/> <include name="org.eclipse.jdt*.jar"/> <include name="org.eclipse.core*.jar"/> <include name="org.eclipse.equinox*.jar"/> <include name="org.eclipse.debug*.jar"/> <include name="org.eclipse.osgi*.jar"/> <include name="org.eclipse.swt*.jar"/> <include name="org.eclipse.jface*.jar"/> <include name="org.eclipse.team.cvs.ssh3*.jar"/> <include name="com.jcraft.jsch*.jar"/> </fileset> </path> <path id="hadoop-sdk-jars"> <fileset dir="${hadoop.home}/share/hadoop/mapreduce"> <include name="hadoop*.jar"/> </fileset> <fileset dir="${hadoop.home}/share/hadoop/hdfs"> <include name="hadoop*.jar"/> </fileset> <fileset dir="${hadoop.home}/share/hadoop/common"> <include name="hadoop*.jar"/> </fileset> </path> <!-- Override classpath to include Eclipse SDK jars --> <path id="classpath"> <pathelement location="${build.classes}"/> <!--pathelement location="${hadoop.root}/build/classes"/--> <path refid="eclipse-sdk-jars"/> <path refid="hadoop-sdk-jars"/> </path> <!-- Skip building if eclipse.home is unset. --> <target name="check-contrib" unless="eclipse.home"> <property name="skip.contrib" value="yes"/> <echo message="eclipse.home unset: skipping eclipse plugin"/> </target> <!--<target name="compile" depends="init, ivy-retrieve-common" unless="skip.contrib">--> <!-- 此處去掉 depends="init, ivy-retrieve-common" --> <target name="compile" unless="skip.contrib"> <echo message="contrib: ${name}"/> <javac encoding="${build.encoding}" srcdir="${src.dir}" includes="**/*.java" destdir="${build.classes}" debug="${javac.debug}" deprecation="${javac.deprecation}"> <classpath refid="classpath"/> </javac> </target> <!-- Override jar target to specify manifest --> <target name="jar" depends="compile" unless="skip.contrib"> <mkdir dir="${build.dir}/lib"/> <copy todir="${build.dir}/lib/" verbose="true"> <fileset dir="${hadoop.home}/share/hadoop/mapreduce"> <include name="hadoop*.jar"/> </fileset> </copy> <copy todir="${build.dir}/lib/" verbose="true"> <fileset dir="${hadoop.home}/share/hadoop/common"> <include name="hadoop*.jar"/> </fileset> </copy> <copy todir="${build.dir}/lib/" verbose="true"> <fileset dir="${hadoop.home}/share/hadoop/hdfs"> <include name="hadoop*.jar"/> </fileset> </copy> <copy todir="${build.dir}/lib/" verbose="true"> <fileset dir="${hadoop.home}/share/hadoop/yarn"> <include name="hadoop*.jar"/> </fileset> </copy> <copy todir="${build.dir}/classes" verbose="true"> <fileset dir="${root}/src/java"> <include name="*.xml"/> </fileset> </copy> <copy file="${hadoop.home}/share/hadoop/common/lib/protobuf-java-${protobuf.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/log4j-${log4j.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/commons-cli-${commons-cli.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/commons-configuration-${commons-configuration.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/commons-lang-${commons-lang.version}.jar" todir="${build.dir}/lib" verbose="true"/> <!-- 此處增加 commons-collections 依賴--> <copy file="${hadoop.home}/share/hadoop/common/lib/commons-collections-${commons-collections.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/jackson-core-asl-${jackson.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/jackson-mapper-asl-${jackson.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/slf4j-log4j12-${slf4j-log4j12.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/slf4j-api-${slf4j-api.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/guava-${guava.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/hadoop-auth-${hadoop.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/commons-cli-${commons-cli.version}.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.home}/share/hadoop/common/lib/netty-${netty.version}.jar" todir="${build.dir}/lib" verbose="true"/> <jar jarfile="${build.dir}/hadoop-${name}-${version}.jar" manifest="${root}/META-INF/MANIFEST.MF"> <manifest> <attribute name="Bundle-ClassPath" value="classes/, lib/hadoop-mapreduce-client-core-${hadoop.version}.jar, lib/hadoop-mapreduce-client-common-${hadoop.version}.jar, lib/hadoop-mapreduce-client-jobclient-${hadoop.version}.jar, lib/hadoop-auth-${hadoop.version}.jar, lib/hadoop-common-${hadoop.version}.jar, lib/hadoop-hdfs-${hadoop.version}.jar, lib/protobuf-java-${protobuf.version}.jar, lib/log4j-${log4j.version}.jar, lib/commons-cli-${commons-cli.version}.jar, lib/commons-configuration-${commons-configuration.version}.jar, lib/commons-httpclient-${commons-httpclient.version}.jar, lib/commons-lang-${commons-lang.version}.jar, lib/jackson-core-asl-${jackson.version}, lib/jackson-mapper-asl-${jackson.version}.jar, lib/slf4j-log4j12-${slf4j-log4j12.version}.jar, lib/slf4j-api-${slf4j-api.version}.jar, lib/guava-${guava.version}.jar, lib/netty-${netty.version}.jar"/> </manifest> <fileset dir="${build.dir}" includes="classes/ lib/"/> <!--fileset dir="${build.dir}" includes="*.xml"/--> <fileset dir="${root}" includes="resources/ plugin.xml"/> </jar> </target> </project>
makePlus.sh
ant jar -Dversion=2.5.2 -Declipse.home=/home/admin1/Public/eclipse -Dhadoop.home=/home/admin1/下載/hadoop-2.5.2
說明:Declipse就是你eclipse的安裝目錄,Dhadoop就是你hadoop的安裝目錄。
接著運行 ./makePlus.sh就可以編譯了。編譯好之后放到eclipse的plugins中,然后重啟eclipse就可以了。
好吧,說到這里我的內心崩潰的,這里過程臺復雜了有木有,而且最后我重啟eclipse居然沒有成功,后來我發現弄了這么久居然是eclipse的原因,我的內心簡直一萬頭×××,后來我把4.5版的刪了,換成4.4的就可以了。當然中間還有一個小插曲,就是配置后不能右鍵New Hadoop了,所以我就在命令行輸入了:
./eclipse -clean -consolelog -debug
然后重啟就沒有問題了。
現在來看運行配置:
可以在瀏覽器上面看到我剛才新建的幾個文件夾:
關于“怎么配置hadoop”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。