Top

NSD ARCHITECTURE DAY04

  1. 案例1:数据分析
  2. 案例2:节点扩容
  3. 案例3:缩减集群节点
  4. 案例4:创建账户并授权
  5. 案例5:在nfsgw上运行网关服务
  6. 案例6:挂载NFS

1 案例1:数据分析

1.1 问题

本案例要求统计分析练习:

1.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:词频统计

  1. [root@hadoop1 hadoop]# ./bin/hadoop fs -ls /        //查看集群文件系统的根,没有内容
  2. [root@hadoop1 hadoop]# ./bin/hadoop fs -mkdir /aaa        
  3. //在集群文件系统下创建aaa目录
  4. [root@hadoop1 hadoop]# ./bin/hadoop fs -ls /        //再次查看,有刚创建的aaa目录
  5. Found 1 items
  6. drwxr-xr-x - root supergroup 0 2018-09-10 09:56 /aaa
  7. [root@hadoop1 hadoop]# ./bin/hadoop fs -touchz /fa    //在集群文件系统下创建fa文件
  8. [root@hadoop1 hadoop]# ./bin/hadoop fs -put *.txt /aaa     
  9. //上传*.txt到集群文件系统下的aaa目录
  10. [root@hadoop1 hadoop]# ./bin/hadoop fs -ls /aaa //查看
  11. Found 3 items
  12. -rw-r--r-- 2 root supergroup 86424 2018-09-10 09:58 /aaa/LICENSE.txt
  13. -rw-r--r-- 2 root supergroup 14978 2018-09-10 09:58 /aaa/NOTICE.txt
  14. -rw-r--r-- 2 root supergroup 1366 2018-09-10 09:58 /aaa/README.txt
  15. [root@hadoop1 hadoop]# ./bin/hadoop fs -get /aaa //下载集群文件系统的aaa目录
  16. [root@hadoop1 hadoop]# ./bin/hadoop jar \
  17. share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount /aaa /bbb    //hadoop集群分析大数据,hadoop集群/aaa里的数据存到hadoop集群/bbb下
  18. [root@hadoop1 hadoop]# ./bin/hadoop fs -cat /bbb/*        //查看集群里的数据

2 案例2:节点扩容

2.1 问题

本案例要求实现节点扩容:

2.2 方案

另外准备两台主机,newnode和nfsgw,作为新添加的节点和网关,具体要求如表-2所示:

表-2

2.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:增加节点

1)增加一个新的节点newnode

  1. [root@hadoop5 ~]# echo newnode > /etc/hostname     //更改主机名为newnode
  2. [root@hadoop5 ~]# hostname newnode
  3. [root@newnode ~]# yum -y install java-1.8.0-openjdk-devel
  4. [root@newnode ~]# mkdir /var/hadoop
  5. [root@hadoop1 .ssh]# ssh-copy-id 192.168.1.64
  6. [root@hadoop1 .ssh]# vim /etc/hosts
  7. 192.168.1.50 hadoop1
  8. 192.168.1.51 node-0001
  9. 192.168.1.52 node-0002
  10. 192.168.1.53 node-0003
  11. 192.168.1.54 newnode
  12. [root@hadoop1 .ssh]# scp /etc/hosts 192.168.1.54:/etc/
  13. [root@hadoop1 ~]# cd /usr/local/hadoop/
  14. [root@hadoop1 hadoop]# vim ./etc/hadoop/slaves
  15. node-0001
  16. node-0002
  17. node-0003
  18. newnode
  19. [root@hadoop1 hadoop]# for i in {51..54}; do rsync -aSH --delete /usr/local/hadoop/
  20. \ 192.168.1.$i:/usr/local/hadoop/ -e 'ssh' & done        //同步配置
  21. [1] 1841
  22. [2] 1842
  23. [3] 1843
  24. [4] 1844
  25. [root@newnode ~]# cd /usr/local/hadoop/
  26. [root@newnode hadoop]# ./sbin/hadoop-daemon.sh start datanode //启动

2)查看状态

  1. [root@newnode hadoop]# jps
  2. 24439 Jps
  3. 24351 DataNode

3)设置同步带宽

  1. [root@newnode hadoop]# ./bin/hdfs dfsadmin -setBalancerBandwidth 60000000
  2. Balancer bandwidth is set to 60000000
  3. [root@newnode hadoop]# ./sbin/start-balancer.sh

3 案例3:缩减集群节点

3.1 问题

本案例要求缩减集群:

3.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:缩减集群

1)删除节点

  1. [root@hadoop1 hadoop]# vim /usr/local/hadoop/etc/hadoop/slaves        
  2. //去掉之前添加的newnode
  3. node-0001
  4. node-0002
  5. node-0003
  6. [root@hadoop1 hadoop]# vim /usr/local/hadoop/etc/hadoop/hdfs-site.xml        
  7. //在此配置文件里面加入下面四行
  8. <property>
  9. <name>dfs.hosts.exclude</name>
  10. <value>/usr/local/hadoop/etc/hadoop/exclude</value>
  11. </property>
  12.  
  13. [root@hadoop1 hadoop]# vim /usr/local/hadoop/etc/hadoop/exclude
  14. newnode

5)导出数据

  1. [root@hadoop1 hadoop]# ./bin/hdfs dfsadmin -refreshNodes
  2. Refresh nodes successful
  3. [root@hadoop1 hadoop]# ./bin/hdfs dfsadmin -report
  4. //查看newnode显示Decommissioned
  5.  
  6. Name: 192.168.1.64:50010 (newnode)
  7. Hostname: newnode
  8. Decommission Status : Decommissioned
  9. Configured Capacity: 2135949312 (1.99 GB)
  10. DFS Used: 4096 (4 KB)
  11. Non DFS Used: 1861509120 (1.73 GB)
  12. DFS Remaining: 274436096 (261.72 MB)
  13. DFS Used%: 0.00%
  14. DFS Remaining%: 12.85%
  15. Configured Cache Capacity: 0 (0 B)
  16. Cache Used: 0 (0 B)
  17. Cache Remaining: 0 (0 B)
  18. Cache Used%: 100.00%
  19. Cache Remaining%: 0.00%
  20. Xceivers: 1
  21. Last contact: Tue Mar 05 17:17:09 CST 2019
  22.  
  23.  
  24. [root@newnode hadoop]# ./sbin/hadoop-daemon.sh stop datanode    //停止datanode
  25. stopping datanode
  26. [root@newnode hadoop]# ./sbin/yarn-daemon.sh start nodemanager    
  27. //yarn 增加 nodemanager
  28. [root@newnode hadoop]# ./sbin/yarn-daemon.sh stop nodemanager //停止nodemanager
  29. stopping nodemanager
  30. [root@newnode hadoop]# ./bin/yarn node -list        
  31. //yarn 查看节点状态,还是有newnode节点,要过一段时间才会消失
  32. Total Nodes:4
  33. Node-Id     Node-State    Node-Http-Address    Number-of-Running-Containers
  34. node-0003:34628     RUNNING     node-0003:8042     0
  35. node-0002:36300     RUNNING     node-0002:8042     0
  36. newnode:42459     RUNNING     newnode:8042     0
  37. node-0001:39196     RUNNING     node-0001:8042     0

4 案例4:创建账户并授权

4.1 问题

本案例要求:

4.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:基础准备

1)更改主机名,配置/etc/hosts(/etc/hosts在hadoop1和nfsgw上面配置)

  1. [root@localhost ~]# echo nfsgw > /etc/hostname
  2. [root@localhost ~]# hostname nfsgw
  3. [root@hadoop1 hadoop]# vim /etc/hosts
  4. 192.168.1.50 hadoop1
  5. 192.168.1.51 node-0001
  6. 192.168.1.52 node-0002
  7. 192.168.1.53 node-0003
  8. 192.168.1.54 newnode
  9. 192.168.1.55 nfsgw

2)创建代理用户(hadoop1和nfsgw上面操作),以hadoop1为例子

  1. [root@hadoop1 hadoop]# groupadd -g 800 nfsuser
  2. [root@hadoop1 hadoop]# useradd -u 800 -g 800 -r -d /var/hadoop nfsuser

3)配置core-site.xml

  1. [root@hadoop1 hadoop]# ./sbin/stop-all.sh //停止所有服务
  2. This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh
  3. Stopping namenodes on [hadoop1]
  4. hadoop1: stopping namenode
  5. node-0002: stopping datanode
  6. newnode: no datanode to stop
  7. node-0003: stopping datanode
  8. node-0001: stopping datanode
  9. Stopping secondary namenodes [hadoop1]
  10. hadoop1: stopping secondarynamenode
  11. stopping yarn daemons
  12. stopping resourcemanager
  13. node-0002: stopping nodemanager
  14. node-0003: stopping nodemanager
  15. newnode: no nodemanager to stop
  16. node-0001: stopping nodemanager
  17. ...
  18.  
  19. [root@hadoop1 hadoop]# cd etc/hadoop
  20. [root@hadoop1 hadoop]# >exclude
  21. [root@hadoop1 hadoop]# vim core-site.xml
  22. <property>
  23. <name>hadoop.proxyuser.nfsuser.groups</name>
  24. <value>*</value>
  25. </property>
  26. <property>
  27. <name>hadoop.proxyuser.nfsuser.hosts</name>
  28. <value>*</value>
  29. </property>

4)同步配置到node-0001,node-0002,node-0003

  1. [root@hadoop1 hadoop]# for i in {51..53}; do rsync -aSH --delete /usr/local/hadoop/ 192.168.1.$i:/usr/local/hadoop/ -e 'ssh' & done
  2. [4] 2722
  3. [5] 2723
  4. [6] 2724

5)启动集群

  1. [root@hadoop1 hadoop]# /usr/local/hadoop/sbin/start-dfs.sh

6)查看状态

  1. [root@hadoop1 hadoop]# /usr/local/hadoop/bin/hdfs dfsadmin -report

5 案例5:在nfsgw上运行网关服务

5.1 问题

本案例要求在 nfsgw 上运行网关服务:

5.2 步骤

实现此案例需要按照如下步骤进行。

步骤二:NFSGW配置

1)卸载rpcbind 和 nfs-utils

  1. [root@nfsgw ~]# yum remove -y rpcbind nfs-utils

2)安装java-1.8.0-openjdk-devel和rsync

  1. [root@nfsgw ~]# yum -y install java-1.8.0-openjdk-devel
  2. [root@hadoop1 hadoop]# rsync -avSH --delete \
  3. /usr/local/hadoop/ 192.168.1.55:/usr/local/hadoop/ -e 'ssh'

3)创建数据根目录 /var/hadoop(在NFSGW主机上面操作)

  1. [root@nfsgw ~]# mkdir /var/hadoop

4)创建转储目录,并给用户nfs 赋权

  1. [root@nfsgw ~]# mkdir /var/nfstmp
  2. [root@nfsgw ~]# chown nfsuser:nfsuser /var/nfstmp

5)给/usr/local/hadoop/logs赋权(在NFSGW主机上面操作)

  1. [root@nfsgw ~]# setfacl -m user:nfsuser:rwx /usr/local/hadoop/logs
  2. [root@nfsgw ~]# vim /usr/local/hadoop/etc/hadoop/hdfs-site.xml
  3. <property>
  4. <name>nfs.exports.allowed.hosts</name>
  5. <value>* rw</value>
  6. </property>
  7. <property>
  8. <name>nfs.dump.dir</name>
  9. <value>/var/nfstmp</value>
  10. </property>

6)可以创建和删除即可

  1. [root@nfsgw ~]# su - nfs
  2. [nfs@nfsgw ~]$ cd /var/nfstmp/
  3. [nfs@nfsgw nfstmp]$ touch 1
  4. [nfs@nfsgw nfstmp]$ ls
  5. 1
  6. [nfs@nfsgw nfstmp]$ rm -rf 1
  7. [nfs@nfsgw nfstmp]$ ls
  8. [nfs@nfsgw nfstmp]$ cd /usr/local/hadoop/logs/
  9. [nfs@nfsgw logs]$ touch 1
  10. [nfs@nfsgw logs]$ ls
  11. 1 hadoop-root-secondarynamenode-hadoop1.log yarn-root-resourcemanager-hadoop1.log
  12. hadoop-root-namenode-hadoop1.log hadoop-root-secondarynamenode-hadoop1.out yarn-root-resourcemanager-hadoop1.out
  13. hadoop-root-namenode-hadoop1.out hadoop-root-secondarynamenode-hadoop1.out.1
  14. hadoop-root-namenode-hadoop1.out.1 SecurityAuth-root.audit
  15. [nfs@nfsgw logs]$ rm -rf 1
  16. [nfs@nfsgw logs]$ ls

7)启动服务

  1. [root@nfsgw ~]# /usr/local/hadoop/sbin/hadoop-daemon.sh --script ./bin/hdfs start portmap        //portmap服务只能用root用户启动
  2. starting portmap, logging to /usr/local/hadoop/logs/hadoop-root-portmap-nfsgw.out
  3. [root@nfsgw ~]# jps
  4. 23714 Jps
  5. 23670 Portmap
  6.  
  7. [root@nfsgw ~]# su - nfsuser
  8. Last login: Mon Sep 10 12:31:58 CST 2018 on pts/0
  9. [nfsuser @nfsgw ~]$ cd /usr/local/hadoop/
  10. [nfsuser@nfsgw hadoop]$ ./sbin/hadoop-daemon.sh --script ./bin/hdfs start nfs3
  11. //nfs3只能用代理用户启动
  12. starting nfs3, logging to /usr/local/hadoop/logs/hadoop-nfsuser-nfs3-nfsgw.out
  13. [nfs@nfsgw hadoop]$ jps                    
  14. 1362 Jps
  15. 1309 Nfs3
  16. [root@nfsgw hadoop]# jps            //root用户执行可以看到portmap和nfs3
  17. 1216 Portmap
  18. 1309 Nfs3
  19. 1374 Jps

6 案例6:挂载NFS

6.1 问题

本案例要求:

6.2 步骤

实现此案例需要按照如下步骤进行。

步骤二:NFSGW测试

1)实现客户端挂载(客户端可以用newnode这台主机)

  1. [root@newnode ~]# rm -rf /usr/local/hadoop
  2. [root@newnode ~]# yum -y install nfs-utils
  3. [root@newnode ~]# mount -t nfs -o \
  4. vers=3,proto=tcp,nolock,noatime,sync,noacl 192.168.1.55:/ /mnt/ //挂载
  5. [root@newnode ~]# cd /mnt/
  6. [root@newnode mnt]# ls
  7. aaa bbb fa system tmp
  8. [root@newnode mnt]# touch a
  9. [root@newnode mnt]# ls
  10. a aaa bbb fa system tmp
  11. [root@newnode mnt]# rm -rf a
  12. [root@newnode mnt]# ls
  13. aaa bbb fa system tmp

8)实现开机自动挂载

  1. [root@newnode ~]# vim /etc/fstab
  2. 192.168.1.55:/ /mnt/ nfs vers=3,proto=tcp,nolock,noatime,sync,noacl,_netdev 0 0
  3. [root@newnode ~]# mount -a
  4. [root@newnode ~]# df -h
  5. 192.168.1.26:/ 64G 6.2G 58G 10% /mnt
  6.  
  7. [root@newnode ~]# rpcinfo -p 192.168.1.55
  8. program vers proto port service
  9. 100005 3 udp 4242 mountd
  10. 100005 1 tcp 4242 mountd
  11. 100000 2 udp 111 portmapper
  12. 100000 2 tcp 111 portmapper
  13. 100005 3 tcp 4242 mountd
  14. 100005 2 tcp 4242 mountd
  15. 100003 3 tcp 2049 nfs
  16. 100005 2 udp 4242 mountd
  17. 100005 1 udp 4242 mountd