搭建hadoop徹底分佈式環境,CentOS6.5安裝Hadoop2.7.3完整流程

轉載地址:http://www.open-open.com/lib/view/open1435761287778.htmlhtml

整體思路,準備主從服務器,配置主服務器能夠無密碼SSH登陸從服務器,解壓安裝JDK,解壓安裝Hadoop,配置hdfs、mapreduce等主從關係。

一、環境,3臺CentOS6.5,64位,Hadoop2.7.3須要64位Linux,操做系統十幾分鍾就能夠安裝完成,
Master 192.168.0.182
Slave1 192.168.0.183
Slave2 192.168.0.184


二、SSH免密碼登陸,由於Hadoop須要經過SSH登陸到各個節點進行操做,我用的是root用戶,每臺服務器都生成公鑰,再合併到authorized_keys
(1)CentOS默認沒有啓動ssh無密登陸,去掉/etc/ssh/sshd_config其中2行的註釋,每臺服務器都要設置,
java

#RSAAuthentication yes
#PubkeyAuthentication yes
(2)輸入命令,ssh-keygen -t rsa,生成key,都不輸入密碼,一直回車,/root就會生成.ssh文件夾,每臺服務器都要設置,
(3)合併公鑰到authorized_keys文件,在Master服務器,進入/root/.ssh目錄,經過SSH命令合併,
cat id_rsa.pub>> authorized_keys
ssh root@192.168.0.183 cat ~/.ssh/id_rsa.pub>> authorized_keys
ssh root@192.168.0.184 cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master服務器的authorized_keys、known_hosts複製到Slave服務器的/root/.ssh目錄
(5)完成,ssh root@192.168.0.18三、ssh root@192.168.0.184就不須要輸入密碼了


三、安裝JDK,Hadoop2.7須要JDK7,因爲個人CentOS是最小化安裝,因此沒有OpenJDK,直接解壓下載的JDK並配置變量便可
(1)下載「jdk-7u79-linux-x64.gz」,放到/home/java目錄下
(2)解壓,輸入命令,tar -zxvf jdk-7u79-linux-x64.gz
(3)編輯/etc/profile
export JAVA_HOME=/home/java/jdk1.7.0_79
export CLASSPATH=.: JAVAHOME/jre/lib/rt.jar: JAVA_HOME/lib/dt.jar: JAVAHOME/lib/tools.jarexportPATH= PATH:$JAVA_HOME/bin 
(4)使配置生效,輸入命令,source /etc/profile
(5)輸入命令,java -version,完成


四、安裝Hadoop2.7,只在Master服務器解壓,再複製到Slave服務器
(1)下載「hadoop-2.7.0.tar.gz」,放到/home/hadoop目錄下
(2)解壓,輸入命令,tar -xzvf hadoop-2.7.0.tar.gz
(3)在/home/hadoop目錄下建立數據存放的文件夾,tmp、hdfs、hdfs/data、hdfs/name


五、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的core-site.xml
<configuration>
    <property>
         <name>fs.defaultFS</name>
         <value>hdfs://192.168.0.182:9000</value>
    </property>
    <property>
         <name>hadoop.tmp.dir</name>
         <value>file:/home/hadoop/tmp</value>
    </property>
    <property>
        <name>io.file.buffer.size</name>
        <value>131702</value>
    </property>
</configuration>


六、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的hdfs-site.xml
<configuration>
    <property>
         <name>dfs.namenode.name.dir</name>
         <value>file:/home/hadoop/dfs/name</value>
    </property>
    <property>
         <name>dfs.datanode.data.dir</name>
         <value>file:/home/hadoop/dfs/data</value>
    </property>
    <property>
        <name>dfs.replication</name>
         <value>2</value>
    </property>
    <property>
        <name>dfs.namenode.secondary.http-address</name>
        <value>192.168.0.182:9001</value>
    </property>
    <property>
    <name>dfs.webhdfs.enabled</name>
    <value>true</value>
    </property>
</configuration>


七、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的mapred-site.xml
<configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>192.168.0.182:10020</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>192.168.0.182:19888</value>
    </property>
</configuration>


八、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的mapred-site.xml
<configuration>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
    <property>
        <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
        <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>192.168.0.182:8032</value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.address</name>
        <value>192.168.0.182:8030</value>
    </property>
    <property>
        <name>yarn.resourcemanager.resource-tracker.address</name>
        <value>192.168.0.182:8031</value>
    </property>
    <property>
        <name>yarn.resourcemanager.admin.address</name>
        <value>192.168.0.182:8033</value>
    </property>
    <property>
        <name>yarn.resourcemanager.webapp.address</name>
        <value>192.168.0.182:8088</value>
    </property>
    <property>
        <name>yarn.nodemanager.resource.memory-mb</name>
        <value>768</value>
    </property>
</configuration>


九、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下hadoop-env.sh、yarn-env.sh的JAVA_HOME,不設置的話,啓動不了,
export JAVA_HOME=/home/java/jdk1.7.0_79




十、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的slaves,刪除默認的localhost,增長2個從節點,
192.168.0.183
192.168.0.184


十一、將配置好的Hadoop複製到各個節點對應位置上,經過scp傳送,
scp -r /home/hadoop 192.168.0.183:/home/
scp -r /home/hadoop 192.168.0.184:/home/


十二、在Master服務器啓動hadoop,從節點會自動啓動,進入/home/hadoop/hadoop-2.7.0目錄
(1)初始化,輸入命令,bin/hdfs namenode -format

     注意:執行這步的時候可能會報一個錯誤:node

     java.net.UnknownHostException: tiancunPC: tiancunPC: unknown error
    at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
    at org.apache.hadoop.net.DNS.resolveLocalHostname(DNS.java:264)
    at org.apache.hadoop.net.DNS.<clinit>(DNS.java:57)
    at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:982)
    at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:591)
    at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:157)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:992)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1434)
    at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1559)
Caused by: java.net.UnknownHostException: tiancunPC: unknown error
    at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress 2.lookupAllHostAddr(InetAddress.java:928)atjava.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)atjava.net.InetAddress.getLocalHost(InetAddress.java:1500)8more16/11/1119:15:23WARNnet.DNS:Unabletodetermineaddressofthehostfallingbacktolocalhostaddressjava.net.UnknownHostException:tiancunPC:tiancunPC:unknownerroratjava.net.InetAddress.getLocalHost(InetAddress.java:1505)atorg.apache.hadoop.net.DNS.resolveLocalHostIPAddress(DNS.java:287)atorg.apache.hadoop.net.DNS.<clinit>(DNS.java:58)atorg.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:982)atorg.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:591)atorg.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:157)atorg.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:992)atorg.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1434)atorg.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1559)Causedby:java.net.UnknownHostException:tiancunPC:unknownerroratjava.net.Inet4AddressImpl.lookupAllHostAddr(NativeMethod)atjava.net.InetAddress 2.lookupAllHostAddr(InetAddress.java:928)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
    … 8 more
linux


    linux中使用hostname查看爲:web

   [root@tiancunPC hadoop-2.7.3]# hostname
   tiancunPC
apache


   查看/etc/hosts爲:vim

  [root@tiancunPC hadoop-2.7.3]# cat /etc/hosts
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
   ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
瀏覽器


   難怪會映射不到,修改/etc/hosts服務器

   [root@tiancunPC hadoop-2.7.3]# cat /etc/hosts
   127.0.0.1   tiancunPC localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
markdown

  對應修改另外兩個機器的主機名,在執行那個命令就能夠了

(2)所有啓動sbin/start-all.sh,也能夠分開sbin/start-dfs.sh、sbin/start-yarn.sh

     執行sbin/start-all.sh 可能會有錯誤提示:

     maps to localhost(IP), but this does not map back to the address

    解決辦法:

   

修改  /etc/ssh/ssh_config

vim  /etc/ssh/ssh_config

GSSAPIAuthentication no


這個時候可能還會出現這個錯誤提示:

hadoop出現namenode running as process 18472. Stop it first.,hadoopnamenode

解決辦法:從新啓動一下hadoop


    

(3)中止的話,輸入命令,sbin/stop-all.sh (4)輸入命令,jps,能夠看到相關信息 1三、Web訪問,要先開放端口或者直接關閉防火牆 (1)輸入命令,systemctl stop firewalld.service(CentOS6.5沒有找到這個命令,在CentOS7中出現) (2)瀏覽器打開http://192.168.0.182:8088/ (3)瀏覽器打開http://192.168.0.182:50070/ 1四、安裝完成。這只是大數據應用的開始,以後的工做就是,結合本身的狀況,編寫程序調用Hadoop的接口,發揮hdfs、mapreduce的做用。

相關文章
相關標籤/搜索