hadoop 分布式部署

2021年01月15日 阅读数:2
这篇文章主要向大家介绍hadoop 分布式部署,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

一、节点:
192.168.100.40 node04.magedu.com node04 node04
192.168.100.30 node03.magedu.com node03 node03
192.168.100.20 node02.magedu.com node02 node02
192.168.100.10 node01.magedu.com node01 node01html

hadoop 分布式部署

二、配置java 环境
一、yum install java-1.7.0-openjdk-devel
二、vim /etc/profile.d/java.sh
export JAVA_HOME=/usr
#. /etc/profile.d/java.sh source /etc/profile.d/java.sh
####
pssh -ih iplist 'yum install java-1.7.0-openjdk-devel -y'
pssh -ih iplist 'echo export JAVA_HOME=/usr > /etc/profile.d/java.sh'
pssh -ih iplist '. /etc/profile.d/java.sh'
[root@node01 ~]# java -versionjava

三、时间同步:
vim /etc/chrony.conf
server 192.168.100.10 iburst
allow 192.168.100.0/24 node

systemctl is-enabled chronyd
systecmtl enable chronyd
systemctl start chronyd
clock -w 软时间同步应时间
clock -s 硬件时间同步软时间web

pssh -ih iplist 'date' apache

四、配置hadoop.sh
[root@node01~]#cat /etc/profile.d/hadoop.sh
export HADOOP_PREFIX=/bdapps/hadoop
export PATH=$PATH:${HADOOP_PREFIX}/bin:${HADOOP_PREFIX}/sbin
export HADOOP_YARN_HOME=${HADOOP_PREFIX}
export HADOOP_MAPPERD_HOME=${HADOOP_PREFIX}
export HADOOP_COMMON_HOME=${HADOOP_PREFIX}
export HADOOP_HDFS_HOME=${HADOOP_PREFIX}
. /etc/profile.d/hadoop.sh
for i in node0{2..4} ;do scp /etc/profile.d/java.sh /etc/profile.d/hadoop.sh $i:/etc/profile.d/;
pssh -ih iplist ". /etc/profile.d/java.sh ; . /etc/profile.d/hadoop.sh " vim

五、建立用户:
groupadd hadoop
useradd hadoop(4个节点同一用户)
echo 'magedu' |passwd --stdin hadoop
useradd -g hadoop hadoop
su - hadoopcentos

pssh -ih iplist "groupadd hadoop"
pssh -ih iplist "useradd -g hadoop hadoop"
pssh -ih iplist "echo 'centos' |passwd --stdin hadoop "app

六、hadoop 用户免密:
su - hadoop
for i in 1 2 3 4 ; do ssh-copy-id -i .ssh/id_rsa.pub hadoop@node0${i}; done ssh

七、visudo webapp

useradd -g wheel hadoop
usermod -aG wheel hadoop
pssh -ih iplist 'usermod -aG wheel hadoop'
pssh -ih iplist 'id hadoop'

八、建立数据目录及配置目录
[root@node01 ~]#pssh -ih iplist 'mkdir -pv /bdapps /data/hadoop/hdfs/{nn,snn,dn}'
[root@node01 ~]# pssh -ih iplist 'chown -R hadoop:hadoop /data/hadoop/hdfs'
[root@node01 ~]# pssh -ih iplist 'tar xf hadoop-2.7.3.tar.gz -C /bdapps'
[root@node01 ~]# pssh -ih iplist ' ln -sv /bdapps/hadoop-2.7.3 /bdapps/hadoop'
[root@node01 ~]# pssh -ih iplist ' ls -l /bdapps/hadoop '
[root@node01 ~]# pssh -ih iplist ' cd /bdapps/hadoop ; mkdir logs;chmod g+w logs'
[root@node01 ~]# pssh -ih iplist ' chown -R hadoop:hadoop /bdapps'
[root@node01 ~]# pssh -ih iplist ' ls -ld /bdapps/hadoop/logs'
scp /bdapps/hadoop/etc/hadoop/* node3:/bdapps/hadoop/etc/hadoop

9 、hdfs 文件配置:
[root@node01 ~]# cd /bdapps/hadoop/etc/hadoop/
[root@node01 hadoop]# cat core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://node01:8020</value>
<final>true</final>
</property>
</configuration>
[root@node01 hadoop]# cat hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>

    <property>
            <name>dfs.namenode.name.dir</name>
            <value>file:///data/hadoop/hdfs/nn</value>
    </property>

    <property>
            <name>dfs.datanode.data.dir</name>
            <value>file:///data/hadoop/hdfs/dn</value>
    </property>
    <property>
    <name>fs.checkpoint.dir</name>
            <value>file:///data/hadoop/hdfs/snn</value>
    </property>

    <property>
    <name>fs.checkpoint.edits.dir</name>
            <value>file:///data/hadoop/hdfs/snn</value>
    </property>

</configuration>

[root@node01 hadoop]# cat mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>

</configuration>

[root@node01 hadoop]# cat yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.address</name>
<value>node01:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>node01:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>node01:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>node01:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>node01:8088</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce_shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
</property>

</configuration>

十、拷贝配置文件:
[root@node01 hadoop]# su - hadoop
cd /bdapps/hadoop/etc/hadoop/
[hadoop@node01 hadoop]$ for i in node0{2..4}; do scp core-site.xml hdfs-site.xml mapred-site.xml yarn-site.xml $i:/bdapps/hadoop/etc/hadoop/; done
[root@node01 ~]# pssh -ih iplist 'ls /bdapps/hadoop/etc/hadoop/ -l '

十一、格式化:
su - hadoop

hdfs namenode -format

十二、启动服务:
启动hadoop:
namenode:hadoop-daemon.sh(start/stop) namenode
datanode:hadoop-daemon.sh(start|stop) datanode
secondary namenode: hadoop-daemon.sh(start|stop)secondarynamenode

Jps:查看java 进程; jps -v

resourcemanager:yarn-daemon.sh(start|stop)resourcemanager

nodemanager:yarn-daemon.sh(start|stop) nodemanager

###################
[hadoop@node01 mapreduce]$ cd /bdapps/hadoop/sbin/
[hadoop@node01 sbin]$ ls
distribute-exclude.sh kms.sh start-balancer.sh stop-all.cmd stop-yarn.cmd
hadoop-daemon.sh mr-jobhistory-daemon.sh start-dfs.cmd stop-all.sh stop-yarn.sh
hadoop-daemons.sh refresh-namenodes.sh start-dfs.sh stop-balancer.sh yarn-daemon.sh
hdfs-config.cmd slaves.sh start-secure-dns.sh stop-dfs.cmd yarn-daemons.sh
hdfs-config.sh start-all.cmd start-yarn.cmd stop-dfs.sh
httpfs.sh start-all.sh start-yarn.sh stop-secure-dns.sh
[hadoop@node01 sbin]$ stop-yarn.sh stop-dfs.sh start-dfs.sh start-yarn.sh
####################

1三、hadoop 测试
hdfs dfs -mkdir /test
hdfs dfs -put /etc/fstab /test/fstab

hdfs dfs -cat /test/fstab

hdfs dfs -put /etc/rc.d/init.d/functions /test/

hdfs dfs -put /etc/issue hdfs://master/test/

1四、排错:
一、dn 与nn 一直刷尝试链接:
[hadoop@node02 dn]$ tail /bdapps/hadoop/logs/hadoop-hadoop-datanode-node02.magedu.com.log
2020-11-08 19:34:49,420 INFO org.apache.hadoop.ipc.Client: Retrying connect to server: node01/192.168.100.10:8020. Already tried 2 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1000 MILLISECONDS)
没有关闭防火墙:
sudo systemctl stop firewalld

二、nn节点 格式化:致使cluster id 与 dn clusterid 不一致:

[hadoop@node01 logs]$ tail hadoop-hadoop-datanode-node01.magedu.com.log -n 30
2020-11-08 19:14:12,537 WARN org.apache.hadoop.hdfs.server.common.Storage: Failed to add storage directory [DISK]file:/data/hadoop/hdfs/dn/
java.io.IOException: Incompatible clusterIDs in /data/hadoop/hdfs/dn: namenode clusterID = CID-98ce0fbd-2d2b-4fc4-a461-df4fbd2181de; datanode clusterID = CID-3148d552-2e5a-4a66-8a2f-5275bd1be8da
cat /data/hadoop/hdfs/dn/current/VERSION
hadoop 分布式部署

三、nn 建立副本 数据流50010 钝口禁止:因防火墙没有关闭:
hadoop 分布式部署

1五、webgui
web ui 概览
hadoop: $hostname:50070
yarn:firefox localhost:8088
hadoop 分布式部署

1六、
http://192.168.100.10:50070/dfshealth.html#tab-overview
hadoop 分布式部署

[hadoop@node01 hadoop]$ hdfs dfsadmin -report
hadoop 分布式部署

hadoop 分布式部署

cd /data/hadoop/hdfs/dn/current/BP-28146739-192.168.100.10-1604886639374/current/finalized/subdir0/subdir0/
hadoop 分布式部署

yarn:8088
hadoop 分布式部署

hadoop 分布式部署
yarn测试:
[hadoop@node01 mapreduce]$ pwd
/bdapps/hadoop/share/hadoop/mapreduce
[hadoop@node01 mapreduce]$ yarn jar /bdapps/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar

hadoop 分布式部署

[hadoop@node01 mapreduce]$ hdfs dfs -ls /test/fstab.out/
Found 2 items
-rw-r--r-- 2 hadoop supergroup 0 2020-11-08 20:29 /test/fstab.out/_SUCCESS
-rw-r--r-- 2 hadoop supergroup 432 2020-11-08 20:29 /test/fstab.out/part-r-00000

[hadoop@node01 mapreduce]$ hdfs dfs -cat /test/fstab.out/part-r-00000
'/dev/disk' 1
/ 1
/boot 1
/etc/fstab 1
0 6
08:19:43 1
2020 1
5 1
Accessible 1
Created 1
Nov 1
See 1
Thu 1

yarn :

[hadoop@node01 sbin]$ yarn application -list -appStates=ALL
20/11/08 20:40:02 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
Total number of applications (application-types: [] and states: [NEW, NEW_SAVING, SUBMITTED, ACCEPTED, RUNNING, FINISHED, FAILED, KILLED]):1
Application-Id Application-Name Application-Type User Queue State Final-State Progress Tracking-URL
application_1604890022094_0001 word count MAPREDUCE hadoop default FINISHED SUCCEEDED 100% http://node01.magedu.com:19888/jobhistory/job/job_1604890022094_0001
[hadoop@node01 sbin]$ yarn application -list
20/11/08 20:40:26 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
Total number of applications (application-types: [] and states: [SUBMITTED, ACCEPTED, RUNNING]):0
Application-Id Application-Name Application-Type User Queue State Final-State Progress Tracking-URL
[hadoop@node01 sbin]$

[hadoop@node01 sbin]$ yarn application -status application_1604890022094_0001
20/11/08 20:44:49 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
Application Report :
Application-Id : application_1604890022094_0001
Application-Name : word count
Application-Type : MAPREDUCE
User : hadoop
Queue : default
Start-Time : 1604896147557
Finish-Time : 1604896174398
Progress : 100%
State : FINISHED
Final-State : SUCCEEDED
Tracking-URL : http://node01.magedu.com:19888/jobhistory/job/job_1604890022094_0001
RPC Port : 39072
AM Host : node01.magedu.com
Aggregate Resource Allocation : 81943 MB-seconds, 46 vcore-seconds
Diagnostics :

            -kill 

[hadoop@node01 sbin]$ yarn application -kill application_1604890022094_0001
20/11/08 20:47:24 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
Application application_1604890022094_0001 has already finished

node
#############
yarn node -list
yarn node -status $node-id
yarn logs -applicationId application_1444_01
yarn classpath
RMAdmin
yarn rmadmin -refreshNodes
DaemonLog;
####################

[hadoop@node01 sbin]$ yarn node -list
20/11/08 20:49:48 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
Total Nodes:4
Node-Id Node-State Node-Http-Address Number-of-Running-Containers
node01.magedu.com:44801 RUNNING node01.magedu.com:8042 0
node02.magedu.com:35211 RUNNING node02.magedu.com:8042 0
node03.magedu.com:38156 RUNNING node03.magedu.com:8042 0
node04.magedu.com:38078 RUNNING node04.magedu.com:8042 0

[hadoop@node01 sbin]$ yarn node -status node01.magedu.com:44801
20/11/08 20:51:53 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
Node Report :
Node-Id : node01.magedu.com:44801
Rack : /default-rack
Node-State : RUNNING
Node-Http-Address : node01.magedu.com:8042
Last-Health-Update : Sun 08/Nov/20 08:50:39:428PST
Health-Report :
Containers : 0
Memory-Used : 0MB
Memory-Capacity : 8192MB
CPU-Used : 0 vcores
CPU-Capacity : 8 vcores
Node-Labels :

[hadoop@node01 sbin]$ yarn logs -applicationId application_1604890022094_0001
20/11/08 20:53:55 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8032
/tmp/logs/hadoop/logs/application_1604890022094_0001 does not exist.
Log aggregation has not completed or is not enabled.

hadoop 分布式部署

[hadoop@node01 sbin]$ yarn rmadmin -refreshNodes
20/11/08 20:55:51 INFO client.RMProxy: Connecting to ResourceManager at node01/192.168.100.10:8033

运行yarn application

hadoop 分布式部署