配置
1. 配置hosts
在/etc/hosts中配置ip与机器名关系
192.168.0.1 lc2
192.168.0.2 lc3
192.168.0.3 lc4
2. 配置无秘钥登录
- 生成秘钥
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
- 拷贝
ssh-copy-id -i ~/.ssh/id_rsa.pub user@st1
3. 配置java环境
省略
4. Zookeeper集群搭建
5. Hadoop配置
- core.xml
<configuration>
<!--nameservices-->
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/data/hadoop/tmp</value>
</property>
<!--zookeeper集群-->
<property>
<name>ha.zookeeper.quorum</name>
<value>lc2:2181,lc3:2181,lc4:2181</value>
</property>
</configuration>
- hdfs-site.xml
<configuration>
<!--指定hdfs的nameservice为ns,需要和core-site.xml中的保持一致 -->
<property>
<name>dfs.nameservices</name>
<value>ns</value>
</property>
<!-- ns下面有两个NameNode,分别是nn1,nn2 -->
<property>
<name>dfs.ha.namenodes.ns</name>
<value>nn1,nn2</value>
</property>
<!-- nn1的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns.nn1</name>
<value>lc2:9000</value>
</property>
<!-- nn1的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns.nn1</name>
<value>lc2:50070</value>
</property>
<!-- nn2的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns.nn2</name>
<value>lc3:9000</value>
</property>
<!-- nn2的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns.nn2</name>
<value>lc3:50070</value>
</property>
<!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://lc2:8485;lc3:8485;lc4:8485/ns</value>
</property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/data/hadoop/journal</value>
</property>
<!-- 开启NameNode故障时自动切换 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<!-- 配置失败自动切换实现方式 -->
<property>
<name>dfs.client.failover.proxy.provider.ns</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!-- 配置隔离机制 -->
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<!-- 使用隔离机制时需要ssh免登陆 -->
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/magneto/.ssh/id_rsa</value>
</property>
<!-- 在NN和DN上开启WebHDFS (REST API)功能,不是必须 -->
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///data/hadoop/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///data/hadoop/data</value>
</property>
</configuration>
- yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>rs</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>lc3</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>lc4</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1</name>
<value>lc3:8088</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2</name>
<value>lc4:8088</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>lc2:2181,lc3:2181,lc4:2181</value>
</property>
<property>
<name>yarn.nodemanager.vmem-pmem-ratio</name>
<value>1.5</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>50000</value>
</property>
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>80</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
</property>
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>2048</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>32768</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-vcores</name>
<value>24</value>
</property>
<property>
<name>yarn.scheduler.minimum-allocation-vcores</name>
<value>1</value>
</property>
<property>
<name>yarn.acl.enable</name>
<value>true</value>
<description>使用使用ACL,默认是false</description>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
- mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.cluster.acls.enabled</name>
<value>true</value>
</property>
</configuration>
- slaves
lc2
lc3
lc4
6. 配置Hadoop环境变量
export HADOOP_HOME=/usr/local/hadoop
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export YARN_HOME=$HADOOP_HOME
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
接下来拷贝hadoop目录到所有机器上。
启动
1.启动zookeeper集群
在所有配置了zookeeper机器上执行sh zkServer.sh start
2.启动journalno
在所有journalnode上执行sbin/hadoop-daemons.sh start journalnode
4.格式化zkfc,让在zookeeper中生成ha节点
在lc2上执行如下命令,完成格式化
hdfs zkfc –formatZK
格式化hdfs,执行hadoop namenode –format
5.启动namenode
首先在lc2上启动active节点,在lc2上执行如下命令sbin/hadoop-daemon.sh start namenode
在lc3上同步namenode的数据,执行hdfs namenode –bootstrapStandby
启动lc3上的namenode作为standby,执行sbin/hadoop-daemon.sh start namenode
6.启动datanode
执行sbin/hadoop-daemons.sh start datanode
7.启动ZKFC
在lc2上执行如下命令,完成ZKFC的启动
执行sbin/hadoop-daemons.sh start zkfc
8.启动yarn
执行start-yarn.sh
yarn-daemons.sh start resourcemanager
网友评论