機(jī)器規(guī)劃:
10.241.95.109 master jdk,hadoop namenode,ZKFC,Resourcemanager
10.241.95.107 h107 jdk,hadoop namenode,ZKFC,Resourcemanager,zookeeper,Journalnode,
10.241.95.110 slave1 jdk,hadoop natanode, nodemanager
10.241.95.111 slave2 jdk,hadoop, natanode,nodemanager
10.241.95.105 h105 jdk,hadoop, natanode,nodemanager,zookeeper,Journalnode,
10.241.95.106 h106 jdk, hadoop, natanode,nodemanager,zookeeper,Journalnode
1:設(shè)置服務(wù)器的hostname
目標(biāo)文件:/etc/hosts 對(duì)象: 6臺(tái)機(jī)器通用
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 salve2
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.241.95.109 master
10.241.95.110 slave1
10.241.95.111 slave2
10.241.95.105 h105
10.241.95.106 h106
10.241.95.107 h107
2:設(shè)置javahome和hadoophome
目標(biāo)文件:/etc/profile 對(duì)象: 6臺(tái)機(jī)器通用
JAVA_HOME=/usr/java/jdk1.8.0_201
HADOOP_HOME=/opt/app/hadoop-3.1.2
CLASSPATH=PATH:HADOOP_HOME/bin:$HADOOP_HOME/sbin
3:設(shè)置ssh免密碼登陸
執(zhí)行:ssh-keygen 生成密鑰
/root/.ssh/id_rsa.pub中生成的內(nèi)容粘貼到 /root/.ssh/authorized_keys中,然后復(fù)制到每一臺(tái)機(jī)器,6臺(tái)機(jī)器就是6套密鑰
4:hadoop配置文件
對(duì)象:6臺(tái)機(jī)器通用
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1/</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/hadoop-3.1.2/tmp</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>h105:2181,h106:2181,h107:2181</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.http.address</name>
<value>10.241.95.109:9870</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>ns1</value>
</property>
<property>
<name>dfs.ha.namenodes.ns1</name>
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn1</name>
<value>10.241.95.109:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>10.241.95.109:9870</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>10.241.95.107:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>10.241.95.107:9870</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://h105:8485;h106:8485;h107:8485/ns1</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/opt/app/hadoop-3.1.2/journaldata</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.ns1</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>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
</configuration>
mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.application.classpath</name>
<value>/opt/app/hadoop-3.1.2/share/hadoop/mapreduce/, /opt/app/hadoop-3.1.2/share/hadoop/mapreduce/lib/</value>
</property>
<property>
<name>mapreduce.job.reduce.slowstart.completedmaps</name>
<value>0.9</value>
</property>
<property>
<name>yarn.nodemanager.vmem-pmem-ratio</name>
<value>2.1</value>
</property>
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>2</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>8192</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>8192</value>
</property>
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>2046</value>
</property>
<property>
<name>mapreduce.map.memory.mb</name>
<value>2046</value>
</property>
<property>
<name>mapreduce.reduce.memory.mb</name>
<value>2046</value>
</property>
</configuration>
yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>10.241.95.109</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>10.241.95.107</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>h105:2181,h06:2181,h107:2181</value>
</property>
</configuration>
5:設(shè)置從屬文件
對(duì)象:master,h107
works.xml
slave1
slave2
h106
h105
6:格式化HDFS
對(duì)象master:hdfs namenode -format
然后把主節(jié)點(diǎn)的數(shù)據(jù)copy到standby機(jī)器上
格式化后會(huì)在根據(jù)core-site.xml中的hadoop.tmp.dir配置生成個(gè)文件斯碌,這里我配置的是主節(jié)點(diǎn)/home/hadoop/hadoop-3.1.2/tmp娩缰,然后將/home/hadoop/hadoop-3.1.2/tmp拷貝到從節(jié)點(diǎn)的/home/hadoop/hadoop-3.1.2/下甚亭。
7:初始化zk
對(duì)象:master
hdfs zkfc -formatZK
8:啟動(dòng)hadoop
對(duì)象:集群中任意一臺(tái)機(jī)器
start-dfs.sh
start-yarn.sh
至此hadoop高可用集群搭建完畢