hadoop高可用,依赖于zookeeper。
用于生产环境, 企业部署必须的模式.
1. 部署环境规划
1.1. 虚拟机及hadoop角色划分
|--------|----------|----------|-----------------|-------------|------|-------------|-----------|
| 主机名称 | namenode | datanode | resourcemanager | nodemanager | zkfc | journalnode | zookeeper |
| master | * | * | * | * | * | * | * |
| slave1 | * | * | | * | * | * | * |
| slave2 | | * | * | * | * | * | * |
1.2. 软件版本
|-----------|---------|
| java | jdk-1.8 |
| Hadoop | 3.3.0 |
| zookeeper | 3.7.0 |
1.3. 数据目录规划
|---------------|-----------------------|
| 名称 | 目录 |
| namenode目录 | /data/hadoop/dfs/name |
| datanode目录 | /data/hadoop/dfs/data |
| hadoop临时目录 | /data/hadoop/tmp |
| zookeeper数据目录 | /data/zookeeper/data |
2. 免密登录
略
3. 安装jdk
略
4. zookeeper安装
4.1. 解压
解压到目录/usr/local/ 下
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz -C /usr/local/zookeeper
4.2. 环境配置
cat>>/etc/profile <<EOF
export ZOOKEEPER_HOME=/usr/local/zookeeper/apache-zookeeper-3.7.0-bin
export PATH=\$ZOOKEEPER_HOME/bin:\$PATH
EOF
source /etc/profile
#创建数据/日志目录
mkdir -pv /data/zookeeper/{data,log}
4.3. 修改配置文件
cd /usr/local/zookeeper/apache-zookeeper-3.7.0-bin/conf/
cp zoo_sample.cfg zoo.cfg
修改zoo.cfg配置文件
dataDir=/data/zookeeper/data/
dataLogDir=/data/zookeeper/log/
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
分发到slave1,slave2节点
scp zoo.cfg slave1:/usr/local/zookeeper/apache-zookeeper-3.7.0-bin/conf/
scp zoo.cfg slave2:/usr/local/zookeeper/apache-zookeeper-3.7.0-bin/conf/
4.4. 创建myid
根据服务器对应的数字,配置相应的myid,master配置1,slave1配置2,slave2配置3
#各节点配置,根据server.1就是1
echo 1 > /data/zookeeper/data/myid
4.5. 启动zookeeper
各个节点启动
zkServer.sh start
zkServer.sh status
5. hadoop安装
5.1. 解压
tar -zxvf hadoop-3.3.0.tar.gz -C /usr/local/
5.2. 环境配置
环境配置(所有节点都执行),root用户执行
chown -R hadoop:hadoop /usr/local/hadoop-3.3.0
cat>>/etc/profile <<EOF
export HADOOP_HOME=/usr/local/hadoop-3.3.0
export PATH=\$HADOOP_HOME/bin:\$HADOOP_HOME/sbin:\$PATH
EOF
source /etc/profile
5.3. 修改配置文件
5.3.1. hadoop-env.sh
cd $HADOOP_HOME/etc/hadoop
vi hadoop-env.sh
export JAVA_HOME=/usr/java/jdk1.8.0_311
5.3.2. core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster/</value>
<description>自定义的集群名称</description>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/data/hadoop/tmp</value>
<description>namenode上本地的hadoop临时文件夹</description>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>master:2181,slave1:2181,slave2:2181</value>
<description>指定zookeeper地址</description>
</property>
<property>
<name>ha.zookeeper.session-timeout.ms</name>
<value>1000</value>
<description>hadoop链接zookeeper的超时时长设置ms</description>
</property>
</configuration>
5.3.3. hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
<description>Hadoop的备份系数是指每个block在hadoop集群中有几份,系数越高,冗余性越好,占用存储也越多</description>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/data/hadoop/dfs/name</value>
<description>namenode上存储hdfs名字空间元数据 </description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/data/hadoop/dfs/data</value>
<description>datanode上数据块的物理存储位置</description>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
<!--指定hdfs的nameservice为myha01,需要和core-site.xml中的保持一致
dfs.ha.namenodes.[nameservice id]为在nameservice中的每一个NameNode设置唯一标示符。
配置一个逗号分隔的NameNode ID列表。这将是被DataNode识别为所有的NameNode。
例如,如果使用"myha01"作为nameservice ID,并且使用"nn1"和"nn2"作为NameNodes标示符
-->
<property>
<name>dfs.nameservices</name>
<value>mycluster</value>
</property>
<!-- myha01下面有两个NameNode,分别是nn1,nn2 -->
<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1,nn2</value>
</property>
<!-- nn1的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>master:9000</value>
</property>
<!-- nn1的http通信地址 -->
<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>master:50070</value>
</property>
<!-- nn2的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>slave1:9000</value>
</property>
<!-- nn2的http通信地址 -->
<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>slave1:50070</value>
</property>
<!-- 指定NameNode的edits元数据的共享存储位置。也就是JournalNode列表
该url的配置格式:qjournal://host1:port1;host2:port2;host3:port3/journalId
journalId推荐使用nameservice,默认端口号是:8485 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://master:8485;slave1:8485;slave2:8485/mycluster</value>
</property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/data/hadoop/data/journaldata</value>
</property>
<!-- 开启NameNode失败自动切换 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<!-- 配置失败自动切换实现方式 -->
<property>
<name>dfs.client.failover.proxy.provider.mycluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!-- 配置隔离机制方法,多个机制用换行分割,即每个机制暂用一行 -->
<property>
<name>dfs.ha.fencing.methods</name>
<value>
sshfence
shell(/bin/true)
</value>
</property>
<!-- 使用sshfence隔离机制时需要ssh免登陆 -->
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/hadoop/.ssh/id_rsa</value>
</property>
<!-- 配置sshfence隔离机制超时时间 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
<property>
<name>ha.failover-controller.cli-check.rpc-timeout.ms</name>
<value>60000</value>
</property>
</configuration>
注意 mycluster 所有地方都要一样
5.3.4. mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
<description>The runtime framework for executing MapReduce jobs. Can be one of local, classic or yarn.</description>
<final>true</final>
</property>
<property>
<name>mapreduce.jobtracker.http.address</name>
<value>master:50030</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>mapred.job.tracker</name>
<value>http://master:9001</value>
</property>
</configuration>
5.3.5. yarn-site.xml
<configuration>
<!-- 开启RM高可用 -->
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<!-- 指定RM的cluster id -->
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<!-- 指定RM的名字 -->
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<!-- 分别指定RM的地址 -->
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>slave1</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>slave2</value>
</property>
<!-- 指定zk集群地址 -->
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>master:2181,slave1:2181,slave2:2181</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>86400</value>
</property>
<!-- 启用自动恢复 -->
<property>
<name>yarn.resourcemanager.recovery.enabled</name>
<value>true</value>
</property>
<!-- 制定resourcemanager的状态信息存储在zookeeper集群上 -->
<property>
<name>yarn.resourcemanager.store.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
</property>
<property>
<name>yarn.application.classpath</name>
<value>/usr/local/hadoop-3.3.0/etc/hadoop:/usr/local/hadoop-3.3.0/share/hadoop/common/lib/*:/usr/local/hadoop-3.3.0/share/hadoop/common/*:/usr/local/hadoop-3.3.0/share/hadoop/hdfs:/usr/local/hadoop-3.3.0/share/hadoop/hdfs/lib/*:/usr/local/hadoop-3.3.0/share/hadoop/hdfs/*:/usr/local/hadoop-3.3.0/share/hadoop/mapreduce/*:/usr/local/hadoop-3.3.0/share/hadoop/yarn:/usr/local/hadoop-3.3.0/share/hadoop/yarn/lib/*:/usr/local/hadoop-3.3.0/share/hadoop/yarn/*</value>
</property>
</configuration>
5.3.6. workers
vim workers
master
slave1
slave2
5.4. 分发到其他服务器
scp -r /usr/local/hadoop-3.3.0/ slave1:/usr/local/
scp -r /usr/local/hadoop-3.3.0/ slave2:/usr/local/
6. 启动集群
以下顺序不能错
6.1. 启动journalnode(所有节点)
hadoop-daemon.sh start journalnode
6.2. 格式化namenode(master)
hadoop namenode -format
6.3. 同步元数据
scp -r /data/hadoop/dfs/name/current/ root@slave1:/data/hadoop/dfs/name/
6.4. 格式化zkfc(master)
hdfs zkfc -formatZK
6.5. 启动HDFS(master)
start-yarn.sh
6.6. 查看各主节点状态hdfs/yarn
hdfs haadmin -getServiceState nn1
hdfs haadmin -getServiceState nn2
yarn rmadmin -getServiceState rm1
yarn rmadmin -getServiceState rm2
7. 查看页面
hdfs:http://master:9870
接付费咨询,调bug, 10元一次。+v:644789108