多目录配置:
1、namenode多目录配置:用于冗余,存储多个镜像文件副本
(1)nano /soft/hadoop/etc/hadoop/hdfs-site.xml,添加以下内容:
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/centos/hadoop/dfs/name1,/home/centos/hadoop/dfs/name2</value>
</property>
(2)xsync.sh /soft/hadoop/etc/hadoop/hdfs-site.xml ====== 分发配置文件
(3)cd /home/centos/hadoop/dfs
(4)mv name name1,cp -r name1 name2
2、datanode多目录配置:用于扩容,将所有数据文件存放在不同的磁盘设备上,如ssd等
(1)nano /soft/hadoop/etc/hadoop/hdfs-site.xml,添加以下内容:
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/centos/hadoop/dfs/data1,/home/centos/hadoop/dfs/data2</value>
</property>
(2)xsync.sh /soft/hadoop/etc/hadoop/hdfs-site.xml
(3)xcall.sh mv /home/centos/hadoop/dfs/data /home/centos/hadoop/dfs/data1
(4)启动hdfs,会自动创建data2文件夹
配置zookeeper(分布式协同服务):
0、zookeeper特性:
(1)zk文件系统以"/"为根目录,文件系统为树形结构,每一个目录我们称之为结点
(2)zk不存文件,只存数据
(3)每个结点(znode)存放的数据最多1M
1、tar -xzvf zookeeper-3.4.10.tar.gz -C /soft/
2、ln -s zookeeper-3.4.10/ zookeeper
3、配置环境变量:sudo nano /etc/profile
export ZOOKEEPER_HOME=/soft/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
4、source /etc/profile
5、mv /soft/zookeeper/conf/zoo_sample.cfg /soft/zookeeper/conf/zoo.cfg
6、zkServer.sh start
7、体验zookeeper:
(1)zkCli.sh ====== 启动zk客户端
(2)常用命令:
help ====== 查看帮助
ls / ====== 列出根结点下的子结点
get / ====== 查看结点上存储的数据
stat / ====== 获取根结点状态(没有数据)
set / 'tom' ====== 在根结点写入数据tom
create /a 'tomas' ====== 创建有数据结点
create /b '' ====== 创建无数据结点(两个单引号)
delete /b ====== 删除没有子结点的结点
rmr /a ====== 递归删除结点
(3)quit ====== 退出客户端
zookeeper完全分布式:
1、修改zoo.cfg文件
dataDir=/home/centos/zookeeper
server.102=s102:2888:3888
server.103=s103:2888:3888
server.104=s104:2888:3888
2、将zookeeper文件夹同步到其他节点
xsync.sh /soft/zookeeper-3.4.10
xsync.sh /soft/zookeeper
3、使用root权限,将环境变量同步到其他节点
(1)su root
(2)xsync.sh /etc/profile
(3)exit
4、在s102-s104中创建文件夹/home/centos/zookeeper,并在文件夹内创建文件myid
(1)xcall.sh "mkdir /home/centos/zookeeper"
(2)ssh s102 "echo 102 > /home/centos/zookeeper/myid"
(3)ssh s103 "echo 103 > /home/centos/zookeeper/myid"
(4)ssh s104 "echo 104 > /home/centos/zookeeper/myid"
5、按顺序启动s102-s104的zk
(1)source /etc/profile
(2)zkServer.sh start
6、查看s102-s104的zk状态:zkServer.sh status
配置hadoop高可用的自动容灾:
0、关闭hadoop,开启zookeeper
1、修改hdfs-site.xml:
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
2、修改core-site.xml:
<property>
<name>ha.zookeeper.quorum</name>
<value>s102:2181,s103:2181,s104:2181</value>
</property>
3、分发配置文件:
(1)xsync.sh /soft/hadoop/etc/hadoop/hdfs-site.xml
(2)xsync.sh /soft/hadoop/etc/hadoop/core-site.xml
4、hdfs zkfc -formatZK ====== 初始化zk
5、start-dfs.sh ====== 启动hdfs