配置
1. 配置hosts
在/etc/hosts中配置ip與機(jī)器名關(guān)系
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環(huán)境
省略
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的元數(shù)據(jù)在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://lc2:8485;lc3:8485;lc4:8485/ns</value>
</property>
<!-- 指定JournalNode在本地磁盤存放數(shù)據(jù)的位置 -->
<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>
<!-- 配置失敗自動切換實(shí)現(xiàn)方式 -->
<property>
<name>dfs.client.failover.proxy.provider.ns</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!-- 配置隔離機(jī)制 -->
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<!-- 使用隔離機(jī)制時需要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,默認(rèn)是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環(huán)境變量
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目錄到所有機(jī)器上召嘶。
啟動
1.啟動zookeeper集群
在所有配置了zookeeper機(jī)器上執(zhí)行sh zkServer.sh start
2.啟動journalno
在所有journalnode上執(zhí)行sbin/hadoop-daemons.sh start journalnode
4.格式化zkfc,讓在zookeeper中生成ha節(jié)點(diǎn)
在lc2上執(zhí)行如下命令父晶,完成格式化
hdfs zkfc –formatZK
格式化hdfs,執(zhí)行hadoop namenode –format
5.啟動namenode
首先在lc2上啟動active節(jié)點(diǎn)弄跌,在lc2上執(zhí)行如下命令sbin/hadoop-daemon.sh start namenode
在lc3上同步namenode的數(shù)據(jù)甲喝,執(zhí)行hdfs namenode –bootstrapStandby
啟動lc3上的namenode作為standby,執(zhí)行sbin/hadoop-daemon.sh start namenode
6.啟動datanode
執(zhí)行sbin/hadoop-daemons.sh start datanode
7.啟動ZKFC
在lc2上執(zhí)行如下命令铛只,完成ZKFC的啟動
執(zhí)行sbin/hadoop-daemons.sh start zkfc
8.啟動yarn
執(zhí)行start-yarn.sh
yarn-daemons.sh start resourcemanager