>>关闭集群
master:
[root@master ~]# hadoop-daemon.sh stop namenode
stopping namenode
[root@master ~]# jps
2156 Jps
[root@master ~]#
slaves:
[root@slave1 ~]# hadoop-daemon.sh stop datanode
stopping datanode
[root@slave1 ~]# jps
2391 Jps
[root@slave1 ~]#
>>master上添加slaves信息:
[root@master ~]# vim /usr/local/hadoop/etc/hadoop/slaves
加入slaves信息:
slave1
slave2
slave3
>>master上启动集群:
[root@master ~]# start-dfs.sh
在slaves上查看进程:
[root@slave1 ~]# jps
2822 DataNode
3561 Jps
>>master上设置免密登录
[root@master ~]# cd .ssh
[root@master .ssh]# ssh-keygen -t rsa
[root@master .ssh]# ssh-copy-id slave1
[root@master .ssh]# ssh-copy-id slave2
[root@master .ssh]# ssh-copy-id slave3
[root@master .ssh]# ssh-copy-id master
[root@master .ssh]# stop-dfs.sh
[root@master .ssh]# start-dfs.sh
Starting namenodes on [master]
master: starting namenode, logging to /usr/local/hadoop/logs/hadoop-root-namenode-master.out
slave1: starting datanode, logging to /usr/local/hadoop/logs/hadoop-root-datanode-slave1.out
slave2: starting datanode, logging to /usr/local/hadoop/logs/hadoop-root-datanode-slave2.out
slave3: starting datanode, logging to /usr/local/hadoop/logs/hadoop-root-datanode-slave3.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /usr/local/hadoop/logs/hadoop-root-secondarynamenode-master.out
[root@master .ssh]#
>>master对文件进行增删改查操作
[root@master .ssh]# hadoop fs -ls /
[root@master .ssh]# cd /usr/local
[root@master local]# ls
bin games hadoop-2.7.3.tar.gz jdk-8u91-linux-x64.rpm lib64 sbin src
etc hadoop include lib libexec share
[root@master local]# hadoop fs -put hadoop-2.7.3.tar.gz /
[root@master local]# hadoop fs -ls /
Found 1 items
-rw-r--r-- 3 root supergroup 214092195 2019-04-13 19:00 /hadoop-2.7.3.tar.gz
[root@master local]#
>>master修改复制副本数默认属性
[root@master local]# cd hadoop/etc/hadoop
[root@master hadoop]# vim hdfs-site.xml
添加:
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
master测试修改后的副本数:
[root@master hadoop]# cd /usr/local
[root@master local]# hadoop fs -put jdk-8u91-linux-x64.rpm /
[root@master local]# hadoop fs -ls /
Found 2 items
-rw-r--r-- 3 root supergroup 214092195 2019-04-13 19:00 /hadoop-2.7.3.tar.gz
-rw-r--r-- 2 root supergroup 160162581 2019-04-13 19:05 /jdk-8u91-linux-x64.rpm
[root@master local]#
在浏览器中查看:http://192.168.85.110:50070/explorer.html#/
>>master修改心跳检查时间以便测试一台slave关机后的副本自动复制功能
[root@master local]# vim /usr/local/hadoop/etc/hadoop/hdfs-site.xml
添加:
<property>
<name>dfs.namenode.heartbeat.recheck-interval</name>
<value>10000</value>
</property>
>>测试slave3关机后hadoop的自动复制功能
重启集群:
[root@master local]# stop-dfs.sh
[root@master local]# start-dfs.sh
在slave3上:
[root@slave3 ~]# hadoop-daemon.sh stop datanode
stopping datanode
过1分钟左右在浏览器中查看:http://192.168.85.110:50070/explorer.html#/
当slave3关机后,hadoop自动复制复本到slave1上
重新启动slave3后
[root@slave3 ~]# hadoop-daemon.sh start datanode
在浏览器中查看:http://192.168.85.110:50070/explorer.html#/
>>Master机器上修改默认文件放置位置
修改前 http://192.168.85.110:50070/dfshealth.html#tab-overview:
关闭集群
[root@master /]# stop-dfs.sh
修改core-site配置文件
[root@master local]# vim /usr/local/hadoop/etc/hadoop/core-site.xml
添加:
<property>
<name>hadoop.tmp.dir</name>
<value>/var/hadoop</value>
</property>
删除所有datanode节点的文件
#删除所有datanode节点的文件
#rm -rf /tmp/hadoop-{username}/*
rm -rf /tmp/hadoop-root/*
重新格式化namenode:
hdfs namenode -format
启动集群:
[root@master local]# start-dfs.sh
如果datanode启动不成功,可以尝试再次格式化和重启集群。
修改后 http://192.168.85.110:50070/dfshealth.html#tab-overview: