1. 程式人生 > >CentOS7安裝Hadoop2.7.3完整步驟

CentOS7安裝Hadoop2.7.3完整步驟

1.環境,3臺CentOS7,64位,Hadoop2.7需要64位Linux,CentOS7 作業系統二十分鐘就可以安裝完成,

 Master 192.168.1.32
 Slave1 192.168.1.33
 Slave2 192.168.1.31

2.(1)修改每臺機器的hosts

 vi /etc/hosts,內容如下:

 Master 192.168.1.32
 Slave1 192.168.1.33
 Slave2 192.168.1.31

  (2)修改主機名:

192.168.1.32上執行:hostnamectl set-hostname Master

192.168.1.33上執行:   hostnamectl set-hostname Slave1

192.168.1.31上執行:   hostnamectl set-hostname Slave2

3.SSH免密碼登入,因為Hadoop需要通過SSH登入到各個節點進行操作,我用的是root使用者,每臺伺服器都生成公鑰,再合併到authorized_keys
(1)CentOS預設沒有啟動ssh無密登入,去掉/etc/ssh/sshd_config其中2行的註釋,每臺伺服器都要設定,
#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

[email protected] cat ~/.ssh/id_rsa.pub>> authorized_keys
ssh [email protected] cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master伺服器的authorized_keys、known_hosts複製到Slave伺服器的/root/.ssh目錄

scp authorized_keys [email protected]:/root/.ssh/

scp known_hosts [email protected]:/root/.ssh/

scp authorized_keys [email protected]:/root/.ssh/

scp known_hosts [email protected]:/root/.ssh/

(5)完成,ssh [email protected]、ssh [email protected]1.31就不需要輸入密碼了

4、安裝JDK,Hadoop2.7需要JDK7,直接解壓下載的JDK並配置變數即可
(1)下載“jdk-7u79-linux-x64.gz”,放到/home/目錄下
(2)解壓,輸入命令,tar -zxvf jdk-7u79-linux-x64.gz
(3)編輯/etc/profile
export JAVA_HOME=/home/java/jdk1.7.0_79
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin 

export HADOOP_HOME=/home/hadoop-2.7.3/
export PATH="$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH"
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop

(4)使配置生效,輸入命令,source /etc/profile
(5)輸入命令,java -version,檢視jdk是否安裝正常

5、安裝Hadoop2.7.3,只在Master伺服器解壓,再複製到Slave伺服器
(1)到官網下載“hadoop-2.7.3.tar.gz”,放到/home目錄下
(2)解壓,輸入命令,tar -xzvf hadoop-2.7.3.tar.gz

6、配置/home/hadoop-2.7.3/etc/hadoop目錄下的core-site.xml
 <configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://Master:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>file:/home/hadoop/tmp</value>
    </property>
 </configuration>

7、配置/home/hadoop-2.7.3/etc/hadoop目錄下的hdfs-site.xml

<configuration>
       <property>
                <name>dfs.namenode.name.dir</name>
                <value>file:/home/hadoop/bigdata/data/namenode</value>
        </property>
        <property>
                <name>dfs.datanode.data.dir</name>
                <value>file:/home/hadoop/bigdata/data/datanode/</value>
        </property>
        <property>
                <name>dfs.replication</name>
                <value>2</value>
        </property>
        <property>
                <name>dfs.namenode.secondary.http-address</name>
                <value>Master:9001</value>
        </property>
 </configuration>

8、配置/home/hadoop-2.7.3/etc/hadoop目錄下的mapred-site.xml

<configuration>

    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>Master:10020</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>Master:19888</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.done-dir</name>
        <value>/history/done</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.intermediate-done-dir</name>
        <value>/history/done_intermediate</value>
    </property>
 </configuration>


 9、配置/home/hadoop-2.7.3/etc/hadoop目錄下的yarn-site.xml
 <configuration>

<!-- Site specific YARN configuration properties -->
    <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>192.168.1.32</value>
    </property>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
</configuration>

10、配置/home/hadoop-2.7.3/etc/hadoop目錄下hadoop-env.sh的JAVA_HOME,不設定的話,啟動不了,
export JAVA_HOME=/home/java/jdk1.7.0_79

11、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目錄下的slaves,刪除預設的localhost,增加2個從節點,
192.168.1.33
192.168.1.31

12、將配置好的Hadoop複製到各個節點對應位置上,通過scp傳送,
scp -r /home/hadoop-2.7.3 192.168.1.33:/home/
scp -r /home/hadoop-2.7.3 192.168.1.31:/home/

並修改profile檔案(同3)

13、在Master伺服器啟動hadoop,從節點會自動啟動,進入/home/hadoop-2.7.3目錄
(1)初始化,輸入命令,bin/hdfs namenode -format
(2)全部啟動sbin/start-all.sh,也可以分開sbin/start-dfs.sh、sbin/start-yarn.sh
(3)停止的話,輸入命令,sbin/stop-all.sh
(4)輸入命令,jps,可以看到相關資訊

14、Web訪問,要先開放埠或者直接關閉防火牆
(1)輸入命令,systemctl stop firewalld.service
(2)瀏覽器開啟http://192.168.1.32:8088/
(3)瀏覽器開啟http://192.168.1.32:50070/

15、安裝完成。這只是大資料應用的開始,之後的工作就是,結合自己的情況,編寫程式呼叫Hadoop的介面,發揮hdfs、mapreduce的作用。