- java環(huán)境安裝
- 現(xiàn)有三臺(tái)主機(jī),CentOS 靜態(tài)IP設(shè)置后,CentOS 修改主機(jī)名,修改
hosts
vi /etc/hosts
192.168.31.xxx master
192.168.31.xxx slaver1
192.168.31.xxx slaver2
- 集群ssh無(wú)密匙登錄設(shè)置
--- 在master,slave1,slave2中執(zhí)行
$ ssh-keygen -t rsa //一路回車(chē)
--- 在 master(master角色)服務(wù)器上 執(zhí)行锈麸,將~/.ssh/下的id_rsa.pub
公私作為認(rèn)證發(fā)放到master,slave1,slave2的~/.ssh/
下
# ssh-copy-id -i ~/.ssh/id_rsa.pub master
# ssh-copy-id -i ~/.ssh/id_rsa.pub slave1
# ssh-copy-id -i ~/.ssh/id_rsa.pub slave2
設(shè)置完后,通過(guò)#ssh localhost測(cè)試,第一次登錄會(huì)有如下提示:
The authenticity of host 'localhost (127.0.0.1)' can't be established.
RSA key fingerprint is a2:44:5f:79:00:c9:17:3b:b4:b5:47:cf:66:be:c4:0d.
Are you sure you want to continue connecting (yes/no)?
輸入yes后,之后就不需要了纱新。(必須操作)
--- 在 master上登錄其他Linux服務(wù)器不需要輸入密碼即成功
//不需要輸入密碼
# ssh slaver1
or
# ssh slaver2
- hadoop完全分布式集群文件配置和啟動(dòng)
- 第一步 安裝Hadoop
上傳hadoop的安裝包hadoop-2.6.4.tar.gz到服務(wù)器上去(自由選擇路徑)
$ tar -zxvf hadoop-2.6.4.tar.gz -C /home/cloud/
- 第二步 配置hadoop
$ cd /home/cloud/hadoop-2.6.4/etc/hadoop
hadoop-2.6.4的搭建需要修改幾個(gè)配置文件
第0個(gè)
$ vi /home/cloud/hadoop-2.6.4/etc/hadoop/slaves
這是設(shè)置從節(jié)點(diǎn)hostname的地方(這個(gè)文件表示從節(jié)點(diǎn),只填寫(xiě)主機(jī)名)
master #姑且讓grape0既作namenode又作datanode
slave1 #datanode1
slave2 #datanode2
第一個(gè):vi /home/cloud/hadoop-2.6.4/etc/hadoop/hadoop-env.sh
#第27行 (建議使用推薦的版本號(hào)汇陆,存放路徑自定)
export JAVA_HOME=/home/cloud/jdk1.8.0_101
第二個(gè):vi /home/cloud/hadoop-2.6.4/etc/hadoop/core-site.xml
(添加如下內(nèi)容)
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/cloud/hadoop-2.6.4/temp</value>
<description>Abasefor other temporary directories.</description>
</property>
</configuration>
第三個(gè):vi /home/cloud/hadoop-2.6.4/etc/hadoop/hdfs-site.xml
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/cloud/hadoop-2.6.4/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/cloud/hadoop-2.6.4/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
新建文件夾/home/cloud/hadoop-2.6.4/dfs/name和/home/cloud/hadoop-2.6.4/dfs/data
第四個(gè):mapred-site.xml (改名后得到的文件)
# mapred-site.xml.template重命名 (在/home/cloud/hadoop-2.6.4/etc/hadoop/路徑下)
$ mv mapred-site.xml.template mapred-site.xml
$ vi mapred-site.xml
<!-- Put site-specific property overrides in this file. -->
<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:50030</value>
</property>
<property>
<name>mapreduce.reduce.memory.mb</name>
<value>4096</value>
</property>
</configuration>
第五個(gè):vi /home/cloud/hadoop-2.6.4/etc/hadoop/yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master:8088</value>
</property>
</configuration>
- 第三步 將hadoop添加到環(huán)境變量
$ vim /etc/profile
#hadoop
export HADOOP_HOME=/home/cloud/hadoop-2.6.4
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
$ source /etc/profile
- 第四步 復(fù)制Hadoop配置好的包到其他Linux主機(jī)
# scp -r hadoop-2.7.3 grape1:/home/cloud/
# scp -r hadoop-2.7.3 grape2:/home/cloud/
- 第五步 格式化namenode(是對(duì)namenode進(jìn)行初始化)
第一次啟動(dòng)Hadoop怒炸,需要進(jìn)行格式化主節(jié)點(diǎn)操作
# hadoop namenode -format
以后啟動(dòng)hadoop,不要格式化主節(jié)點(diǎn)了毡代,會(huì)丟失數(shù)據(jù)
- 第六步 啟動(dòng)hadoop
$ cd /home/cloud/hadoop-2.6.4/sbin/#若已配置hadoop環(huán)境變量阅羹,直接在根目錄下輸入下一行代碼
$ start-all.sh
Hadoop搭建到此結(jié)束,接下來(lái)是驗(yàn)證是否搭建成功
使用jps命令驗(yàn)證
出現(xiàn)以下結(jié)果教寂,表明啟動(dòng)成功
[root@xxxxx ]# jps
6417 DataNode
7207 NodeManager
6920 ResourceManager
7258 Jps
6235 NameNode
6700 SecondaryNameNode
打開(kāi)瀏覽器捏鱼,地址欄輸入master:50070查看詳情
7.第七步 終止hadoop
$ cd /home/cloud/hadoop-2.6.4/sbin/ #若已配置hadoop環(huán)境變量,直接在根目錄下輸入下一行代碼
$ stop-all.sh
參考:
Hadoop完全分布式集群搭建手記
Hadoop集群實(shí)踐-完整Hadoop分布式集群部署ubuntu-16.04.1+hadoop-2.7.3