hadoop3.2.2集群搭建[通俗易懂]

hadoop3.2.2集群搭建[通俗易懂]说明:本文以HDFSHighAvailabilityUsingtheQuorumJournalManager模式搭建hadoop3.2.0集群。环境CentOS7、jdk1.8.0_181、zookeeper3.4.13、hadoop3.2.0 虚拟机安装CentOS7三台,如下:hostname IP storm 192.168.56.200 st…

大家好,欢迎来到IT知识分享网。

说明:本文以HDFS High Availability Using the Quorum Journal Manager模式搭建hadoop3.2.0集群。

环境

  • CentOS7.5.1804、jdk1.8.0_181、zookeeper3.6.2、hadoop3.2.2
  • 虚拟机安装CentOS7五台,如下: 
hostname IP roles
node-1 192.168.56.129 QuorumPeerMain、NameNode、JournalNode、DFSZKFailoverController、ResourceManager
node-2 192.168.56.130 QuorumPeerMain、NameNode、JournalNode、DFSZKFailoverController、ResourceManager
node-3 192.168.56.131 QuorumPeerMain、NameNode、JournalNode、DFSZKFailoverController、DataNode、NodeManager、JobHistoryServer
node-4 192.168.56.132 DataNode、NodeManager
node-5 192.168.56.133 DataNode、NodeManager

      注意:安装前关闭防火墙,执行如下命令:

           systemctl stop firewalld           

           systemctl disable firewalld

           systemctl status firewalld

  • 安装jdk,省略安装步骤。
  • 三台虚拟机配置免密登录,省略配置过程。
配置免密登录可以使用如下命令:
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
ssh-copy-id -p <port> -i ~/.ssh/id_rsa.pub "<user>@<hostname>" // 根据自己的环境补全命令
chmod 0600 ~/.ssh/authorized_keys

搭建zookeeper集群

hadoop3.2.2集群搭建[通俗易懂]

  • 上传到虚拟机,解压后修改conf/zoo.cfg文件,配置如下:
tickTime=3000
initLimit=10
syncLimit=5
dataDir=/opt/env/zookeeper-3.6.2/data/data
dataLogDir=/opt/env/zookeeper-3.6.2/data/logs
clientPort=2181
autopurge.snapRetainCount=3
autopurge.purgeInterval=1
server.1=node-1:2888:3888
server.2=node-2:2888:3888
server.3=node-3:2888:3888

     在dataDir定义的目录下创建文件myid,把虚拟机各自对应的id存储到myid,即上面的server.id,每台虚拟机只存储自己的id值即可。

    启动zookeeper:bin/zkServer.sh start。

 搭建hadoop

hadoop3.2.2集群搭建[通俗易懂]

  • 修改../hadoop-3.2.2/etc/hadoop下的配置文件:
  • hdfs-site.xml文件配置如下:
<configuration>
  <property>
    <name>dfs.nameservices</name>
    <value>vmcluster</value>
  </property>
  <property>
    <name>dfs.ha.namenodes.vmcluster</name>
    <value>nn1,nn2,nn3</value>
  </property>
  <property>
    <name>dfs.namenode.rpc-address.vmcluster.nn1</name>
    <value>node-1:8020</value>
  </property>
  <property>
    <name>dfs.namenode.rpc-address.vmcluster.nn2</name>
    <value>node-2:8020</value>
  </property>
  <property>
    <name>dfs.namenode.rpc-address.vmcluster.nn3</name>
    <value>node-3:8020</value>
  </property>
  <property>
    <name>dfs.namenode.http-address.vmcluster.nn1</name>
    <value>node-1:9870</value>
  </property>
  <property>
    <name>dfs.namenode.http-address.vmcluster.nn2</name>
    <value>node-2:9870</value>
  </property>
  <property>
    <name>dfs.namenode.http-address.vmcluster.nn3</name>
    <value>node-3:9870</value>
  </property>
  <property>
    <name>dfs.namenode.shared.edits.dir</name>
    <value>qjournal://node-1:8485;node-2:8485;node-3:8485/vmcluster</value>
  </property>
  <property>
    <name>dfs.client.failover.proxy.provider.vmcluster</name>
    <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
  </property>
  <property>
    <name>dfs.ha.fencing.methods</name>
    <value>sshfence</value>
  </property>
  <property>
    <name>dfs.ha.fencing.ssh.private-key-files</name>
    <value>/home/bigdata/.ssh/id_rsa</value>
  </property>
  <property>
    <name>dfs.ha.fencing.ssh.connect-timeout</name>
    <value>30000</value>
  </property>
  <property>
    <name>dfs.namenode.handler.count</name>
    <value>100</value>
  </property>
  <property>
    <name>dfs.safemode.threshold.pct</name>
    <value>1</value>
  </property>
  <property>
    <name>dfs.journalnode.edits.dir</name>
    <value>/opt/env/hadoop-3.2.2/data/jn</value>
  </property>
  <property>
    <name>dfs.ha.automatic-failover.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>dfs.namenode.name.dir</name>
    <value>file://${hadoop.tmp.dir}/dfs/nn</value>
  </property>
  <property>
    <name>dfs.datanode.data.dir</name>
    <value>file://${hadoop.tmp.dir}/dfs/dn</value>
  </property>
  <property>
    <name>dfs.replication</name>
    <value>3</value>
  </property>
  <property>                                        
    <name>dfs.permissions.enabled</name>
    <value>false</value>
  </property>
  <property>                                        
    <name>dfs.blocksize</name>
    <value>67108864</value>
  </property>
</configuration>
  • core-site.xml文件配置如下:
<configuration>
  <property>
    <name>fs.defaultFS</name>
    <value>hdfs://vmcluster</value>
  </property>
  <property>
    <name>ha.zookeeper.quorum</name>
    <value>node-1:2181,node-2:2181,node-3:2181</value>
  </property>
  <property>
    <name>hadoop.tmp.dir</name>
    <value>/opt/env/hadoop-3.2.2/data</value>
  </property>
  </property>
    <property>
    <name>hadoop.http.staticuser.user</name>
    <vaule>bigdata</vaule>
  </property>
  <property>
    <name>hadoop.proxyuser.bigdata.hosts</name>
    <vaule>*</vaule>
  </property>
  <property>
    <name>hadoop.proxyuser.bigdata.groups</name>
    <value>*</value>
  </property>
  <property>
    <name>hadoop.proxyuser.bigdata.users</name>
    <value>*</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>yarnCluster</value>
  </property>
  <property>
    <name>yarn.resourcemanager.ha.automatic-failover.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>yarn.resourcemanager.ha.automatic-failover.embedded</name>
    <value>true</value>
  </property>
  <property>
    <name>yarn.resourcemanager.connect.retry-interval.ms</name>
    <value>2000</value>
  </property>
  <property>
    <name>yarn.resourcemanager.ha.rm-ids</name>
    <value>rm1,rm2</value>
  </property>
  <property>
    <name>yarn.resourcemanager.hostname.rm1</name>
    <value>node-1</value>
  </property>
  <property>
    <name>yarn.resourcemanager.hostname.rm2</name>
    <value>node-2</value>
  </property>
  <property>
    <name>yarn.resourcemanager.webapp.address.rm1</name>
    <value>node-1:8088</value>
  </property>
  <property>
    <name>yarn.resourcemanager.webapp.address.rm2</name>
    <value>node-2:8088</value>
  </property>
  <property>
    <name>yarn.resourcemanager.address.rm1</name>
    <value>node-1:8032</value>
  </property>
  <property>
    <name>yarn.resourcemanager.address.rm2</name>
    <value>node-2:8032</value>
  </property>
  <property>
    <name>yarn.resourcemanager.scheduler.address.rm1</name>
    <value>node-1:8030</value>
  </property>
  <property>
    <name>yarn.resourcemanager.scheduler.address.rm2</name>
    <value>node-2:8030</value>                                    
  </property>
  <property>
    <name>yarn.resourcemanager.zk-address</name>
    <value>node-1:2181,node-2:2181,node-3:2181</value>
  </property>
  <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
  </property>
  <property>
    <name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
  </property>
  <property>
    <name>yarn.nodemanager.env-whitelist</name>
    <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
  </property>
  <property>
    <name>yarn.log-aggregation-enable</name>
    <value>true</value>
  </property>
  <property>  
    <name>yarn.log.server.url</name>  
    <value>http://node-3:19888/jobhistory/logs</value>  
  </property> 
  <property>
    <name>yarn.log-aggregation.retain-seconds</name>
    <value>604800</value>
  </property>
  <property>
    <name>yarn.resourcemanager.scheduler.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
  </property>
  <property>
    <name>yarn.resourcemanager.recovery.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>yarn.resourcemanager.store.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
  </property>
  <property>
    <name>yarn.resourcemanager.zk.state-store.address</name>
    <value>node-1:2181,node-2:2181,node-3:2181</value>
  </property>
  <property>
    <name>yarn.application.classpath</name>
    <value>
      $HADOOP_CONF_DIR,
      $HADOOP_COMMON_HOME/share/hadoop/common/*,
      $HADOOP_COMMON_HOME/share/hadoop/common/lib/*,
      $HADOOP_HDFS_HOME/share/hadoop/hdfs/*,
      $HADOOP_HDFS_HOME/share/hadoop/hdfs/lib/*,
      $HADOOP_YARN_HOME/share/hadoop/yarn/*,
      $HADOOP_YARN_HOME/share/hadoop/yarn/lib/*
    </value>
  </property>
  <property>
    <name>yarn.nodemanager.pmem-check-enabled</name>
    <value>false</value>
  </property>
  <property>
    <name>yarn.nodemanager.vmem-check-enabled</name>
    <value>false</value>
  </property>
</configuration>
  • mapred-site.xml文件配置如下:
<configuration>
  <property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
  </property>
  <property>
    <name>mapreduce.jobhistory.address</name>
    <value>node-3:10020</value>
  </property>
  <property>
    <name>mapreduce.jobhistory.webapp.address</name>
    <value>node-3:19888</value>
  </property>
  <property>
    <name>yarn.app.mapreduce.am.env</name>
    <value>HADOOP_MAPRED_HOME=/opt/env/hadoop-3.2.2</value>
  </property>
  <property>
    <name>mapreduce.map.env</name>
    <value>HADOOP_MAPRED_HOME=/opt/env/hadoop-3.2.2</value>
  </property>
  <property>
    <name>mapreduce.reduce.env</name>
    <value>HADOOP_MAPRED_HOME=/opt/env/hadoop-3.2.2</value>
  </property>
  <property>
    <name>mapreduce.application.classpath</name>
    <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*,$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
  </property>
</configuration>

    workers文件件配置如下:

node-3
node-4
node-5
  • hadoop-env.sh文件配置如下:
export JAVA_HOME=${JAVA_HOME}
export HDFS_NAMENODE_USER=bigdata
export HDFS_DATANODE_USER=bigdata
export HDFS_JOURNALNODE_USER=bigdata
export HDFS_ZKFC_USER=bigdata
export YARN_RESOURCEMANAGER_USER=bigdata
export YARN_NODEMANAGER_USER=bigdata

初始化与启动

五台虚拟机所有配置完成后,依次执行如下命令:

->  ${HADOOP_HOME}/bin/hdfs --daemon start journalnode  # journalnode的节点都执行该命令
执行完成后,查看HADOOP_HOME目录下的logs目录的journalnode日志,是否正常。


->  ${HADOOP_HOME}/bin/hdfs namenode -format  # 格式化,在其中一台namenode虚拟机执行即可
->  ${HADOOP_HOME}/bin/hdfs --daemon start namenode # 启动namenode
执行完成后,查看HADOOP_HOME目录下的logs目录的namenode日志,是否正常


->  ${HADOOP_HOME}/bin/hdfs namenode -bootstrapStandby # 副节点同步主节点格式化文件
其余namenode节点执行该命令

->  ${HADOOP_HOME}/bin/hdfs zkfc -formatZK   # 格式化zkfc,在其中一台namenode虚拟机执行即可
执行完成后,将在ZooKeeper中创建一个znode,自动故障转移系统存储数据。


->  ${HADOOP_HOME}/sbin/stop-dfs.sh

->  ${HADOOP_HOME}/sbin/start-dfs.sh

->  ${HADOOP_HOME}/sbin/start-yarn.sh

->  ${HADOOP_HOME}/bin/mapred --daemon start historyserver
启动配置historyserver的服务器, (node-3)

hadoop3.2.2集群搭建[通俗易懂]

hadoop3.2.2集群搭建[通俗易懂]

运行一个mapreduce的自带例子测试

hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.2.jar wordcount /input/README.txt /output/

hadoop3.2.2集群搭建[通俗易懂]

hadoop3.2.2集群搭建[通俗易懂]

查看historyserver

hadoop3.2.2集群搭建[通俗易懂]

注意:安装centos7的时候如果是最小化安装(默认的选择就是最小化安装),是不安装psmisc包,此时hadoop的HA无法正常切换,需要安装yum install psmisc -y包后,重启。

说明一下:psmisc工具包含了pstree、killall、fuser

pstree:以树状图显示程序;

killall:用于kill指定名称的进程;

fuser:用来显示所有正在使用着指定的file, file system 或者 sockets的进程信息。

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/26432.html

(0)
上一篇 2023-05-04 17:00
下一篇 2024-06-21 22:33

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信