当前位置:   article > 正文

Hadoop3.3.1 HA配置多个namenode(5个Namenode)详细_hadoop多个namenode

hadoop多个namenode

前期准备

所有主机关闭防火墙。

所有主机安装JDK1.8,并配置环境变量。

所有主机设置静态IP地址,修改主机名称。

设置所有主机selinux=disabled。

安装好zookeeper集群。并启动。

下载hadoop3.3.1包

集群配置

机器现状

六台虚拟机a2-a7

1. 配置hadoop-env.sh

export JAVA_HOME=/apps/jdk 可以只配置这其他的我这是后边有问题加上的

export HADOOP_PID_DIR=/apps/hadoop/hadoop_data/tmp/pids

HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/apps/hadoop/share/hadoop/mapreduce/*

2.  配置core-site.xml文件

  1. <!-- 指定hdfs的nameservice为ns1 -->
  2. <property>
  3. <name>fs.defaultFS</name>
  4. <value>hdfs://test</value>
  5. </property>
  6. <!-- 指定hadoop hdfs目录 -->
  7. <property>
  8. <name>hadoop.tmp.dir</name>
  9. <value>/data/hadoop/</value>
  10. </property>
  11. <property>
  12. <name>hadoop.native.lib</name>
  13. <value>false</value>
  14. <description>Should native hadoop libraries, if present, be used.</description>
  15. </property>
  16. <!-- 指定zookeeper地址 -->
  17. <property>
  18. <name>ha.zookeeper.quorum</name>
  19. <value>a1:2181,a2:2181,a3:2181,a4:2181,a5:2181,a6:2181</value>
  20. </property>
  21. <!--可选的配置QJM日志目录-->
  22. <property>
  23. <name>dfs.journalnode.edits.dir</name>
  24. <value>/data/hadoop/journal/local/data</value>
  25. </property>

 3.  配置hdfs-site.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <!--
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License. See accompanying LICENSE file.
  13. -->
  14. <!-- Put site-specific property overrides in this file. -->
  15. <configuration>
  16. <!--指定hdfs的nameservice为test,需要和core-site.xml中的保持一致 -->
  17. <property>
  18. <name>dfs.nameservices</name>
  19. <value>test</value>
  20. </property>
  21. <property>
  22. <name>dfs.ha.namenodes.test</name>
  23. <value>nn1,nn2,nn3,nn4,nn5</value>
  24. </property>
  25. <!--配置每一个NameNode的rpc通信地址-->
  26. <property>
  27. <name>dfs.namenode.rpc-address.test.nn1</name>
  28. <value>a2:8020</value>
  29. </property>
  30. <property>
  31. <name>dfs.namenode.rpc-address.test.nn2</name>
  32. <value>a3:8020</value>
  33. </property>
  34. <property>
  35. <name>dfs.namenode.rpc-address.test.nn3</name>
  36. <value>a4:8020</value>
  37. </property>
  38. <property>
  39. <name>dfs.namenode.rpc-address.test.nn4</name>
  40. <value>a5:8020</value>
  41. </property>
  42. <property>
  43. <name>dfs.namenode.rpc-address.test.nn5</name>
  44. <value>a6:8020</value>
  45. </property>
  46. <!--配置每一个NameNode的web http地址-->
  47. <property>
  48. <name>dfs.namenode.http-address.test.nn1</name>
  49. <value>a2:9870</value>
  50. </property>
  51. <property>
  52. <name>dfs.namenode.http-address.test.nn2</name>
  53. <value>a3:9870</value>
  54. </property>
  55. <property>
  56. <name>dfs.namenode.http-address.test.nn3</name>
  57. <value>a4:9870</value>
  58. </property>
  59. <property>
  60. <name>dfs.namenode.http-address.test.nn4</name>
  61. <value>a5:9870</value>
  62. </property>
  63. <property>
  64. <name>dfs.namenode.http-address.test.nn5</name>
  65. <value>a6:9870</value>
  66. </property>
  67. <property>
  68. <name>dfs.namenode.shared.edits.dir</name>
  69. <value>qjournal://a2:8485;a3:8485;a4:8485/test</value>
  70. </property>
  71. <!--配置QJM日志的目录-->
  72. <property>
  73. <name>dfs.journalnode.edits.dir</name>
  74. <value>/data/hadoop/qjm/edits</value>
  75. </property>
  76. <!--配置为自动切换功能打开,需要在core-site.xml文件中配置ZK地址-->
  77. <property>
  78. <name>dfs.ha.automatic-failover.enabled</name>
  79. <value>true</value>
  80. </property>
  81. <property>
  82. <name>dfs.client.failover.proxy.provider.test</name>
  83. <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
  84. </property>
  85. <!--配置自动切换的方式-->
  86. <property>
  87. <name>dfs.ha.fencing.methods</name>
  88. <value>
  89. sshfence
  90. shell(/bin/true)
  91. </value>
  92. </property>
  93. <!--配置SSH key,注意根据不同的用户名修改目录-->
  94. <property>
  95. <name>dfs.ha.fencing.ssh.private-key-files</name>
  96. <value>/root/.ssh/id_rsa</value>
  97. </property>
  98. <property>
  99. <name>dfs.permissions.enabled</name>
  100. <value>false</value>
  101. </property>
  102. <!-- 配置sshfence隔离机制超时时间 -->
  103. <property>
  104. <name>dfs.ha.fencing.ssh.connect-timeout</name>
  105. <value>30000</value>
  106. </property>
  107. <property>
  108. <name>dfs.namenode.checkpoint.check.period</name>
  109. <value>3600s</value>
  110. </property>
  111. </configuration>

 4.  配置mapreduce-site.xml文件

  1. <property>
  2. <name>mapreduce.framework.name</name>
  3. <value>yarn</value>
  4. </property>

 5.  配置yarn-site.xml文件

  1. <!--配置RM高可靠-->
  2. <property>
  3. <name>yarn.resourcemanager.ha.enabled</name>
  4. <value>true</value>
  5. </property>
  6. <property>
  7. <name>yarn.resourcemanager.cluster-id</name>
  8. <value>cluster1</value>
  9. </property>
  10. <!--配置Resourcemanager个数,hadoop3以后可以为3到5个-->
  11. <property>
  12. <name>yarn.resourcemanager.ha.rm-ids</name>
  13. <value>rm1,rm2,rm3</value>
  14. </property>
  15. <!--以下配置每一个RM的地址-->
  16. <property>
  17. <name>yarn.resourcemanager.hostname.rm1</name>
  18. <value>a2</value>
  19. </property>
  20. <property>
  21. <name>yarn.resourcemanager.hostname.rm2</name>
  22. <value>a3</value>
  23. </property>
  24. <property>
  25. <name>yarn.resourcemanager.hostname.rm3</name>
  26. <value>a4</value>
  27. </property>
  28. <!--配置每一个RM的http地址-->
  29. <property>
  30. <name>yarn.resourcemanager.webapp.address.rm1</name>
  31. <value>a2:8088</value>
  32. </property>
  33. <property>
  34. <name>yarn.resourcemanager.webapp.address.rm2</name>
  35. <value>a3:8088</value>
  36. </property>
  37. <property>
  38. <name>yarn.resourcemanager.webapp.address.rm3</name>
  39. <value>a4:8088</value>
  40. </property>
  41. <!--配置zookeeper地址-->
  42. <property>
  43. <name>yarn.resourcemanager.zk-address</name>
  44. <value>a2:2181,a3:2181,a4:2181</value>
  45. </property>
  46. <property>
  47. <name>yarn.nodemanager.aux-services</name>
  48. <value>mapreduce_shuffle</value>
  49. </property>
  50. <property>
  51. <name>yarn.application.classpath</name>
  52. <value>/apps/hadoop/etc/hadoop:/apps/hadoop/share/hadoop/common/lib/*:/apps/hadoop/share/hadoop/common/*:/apps/hadoop/share/hadoop/hdfs:/apps/hadoop/share/hadoop/hdfs/lib/*:/apps/hadoop/share/hadoop/hdfs/*:/apps/hadoop/share/hadoop/mapreduce/lib/*:/apps/hadoop/share/hadoop/mapreduce/*:/apps/hadoop/share/hadoop/yarn:/apps/hadoop/share/hadoop/yarn/lib/*:/apps/hadoop/share/hadoop/yarn/*</value>
  53. </property>
  54. <property>
  55. <name>yarn.nodemanager.resource.memory-mb</name>
  56. <value>16384</value>
  57. </property>
  58. <property>
  59. <name>yarn.nodemanager.resource.cpu-vcores</name>
  60. <value>4</value>
  61. </property>
  62. <property>
  63. <name>yarn.scheduler.maximum-allocation-vcores</name>
  64. <value>4</value>
  65. </property>

 6.  配置workers文件

  1. a2
  2. a3
  3. a4
  4. a5
  5. a6
  6. a7

7.配置start-dfs.sh/stop-dfs.sh

在中间位置,找到一个空白的位置添加:

HDFS_NAMENODE_USER=root

HDFS_SECONDARYNAMENODE_USER=root

HDFS_DATANODE_USER=root

HDFS_DATANODE_SECURE_USER=root

#以下是高可靠配置的

HDFS_JOURNALNODE_USER=root

HDFS_ZKFC_USER=root

8.配置start-yarn.sh/stop-yarn.sh

在两个配置文件中间位置添加以下内容:

YARN_RESOURCEMANAGER_USER=root

YARN_NODEMANAGER_USER=root

9. 现在配置hadoop的环境变量

export HADOOP_HOME=/data/apps/hadoop-3.3.0
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin

 10.拷贝文件其他主机

scp -r /data/apps/hadoop/  a3:/data/apps/

11.启动journalnode 在journalnode机器上执行

hadoop-daemon.sh start journalnode

12.格式化HDFS

hdfs namenode -format

出现successfully formatted为成功

现在将格式化后的hdfs目录,拷贝到a3,a4,a5,a6主机上的相同目录下:

 scp -r /data/hadoop/dfs/  a3:/data/hadoop/

内容是这样 的目录

 13.格式化zkfc

格式化前要停止

hadoop-daemon.sh stop journalnode 不停止会报错,如果不报错就不用在意

hdfs zkfc -formatZK

Successfully created hadoop-ha/cluster in ZK 出现这个就是成功

14.启动dfs yarn

start-dfs.sh  因为配置了环境变量所以可以直接启动

start-yarn.sh

start-all.sh    启动所有

stop-all.sh    停止全部

 验证

web  访问 http://ip:9870

 

 

也可以通过以下命令,检查NameNode和ResourceManager的状态

$ hdfs haadmin -getServiceState nn1

active

$ hdfs haadmin -getServiceState nn2

standby

$ yarn rmadmin -getServiceState rm1

active

$ yarn rmadmin -getServiceState rm2

standby

有可能出现的问题:

 这个问题现在还没有解决 可以手动切换namenode 到前两个namenode 

Currently, the standby NN will log StandbyExceptions at ERROR level any time a client tries to connect to it. So, if the second NN in an HA pair is active, the first NN will spew a lot of these errors in the log, as each client gets redirected to the proper NN. Instead, this should be at INFO level, and should probably be logged in a less "scary" manner (eg "Received READ request from client 1.2.3.4, but in Standby state. Redirecting client to other NameNode.")

有大神知道怎么解决可以留言谢谢

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/855748
推荐阅读
相关标签
  

闽ICP备14008679号