希文的个人博客

白日依山尽,黄河入海流。欲穷千里目,更上一层楼。

0%

06.生产调优手册-集群迁移(cdh集群版)

[TOC]

尚硅谷大数据技术之集群迁移(Apache和CDH)

(作者:尚硅谷大数据研发部)

版本:V1.0

第1章迁移数据

1)准备两套集群,我这使用apache集群和CDH集群。

img

2)启动集群

img

img

3)启动完毕后,将apache集群中,hive库里dwd,dws,ads三个库的数据迁移到CDH集群

img

img

4)在apache集群里hosts加上CDH Namenode对应域名并分发给各机器

[root@hadoop101 ~]# vim /etc/hosts

img

1
2
[root@hadoop101 ~]# scp /etc/hosts hadoop102:/etc/
[root@hadoop101 ~]# scp /etc/hosts hadoop103:/etc/

5)因为集群都是HA模式,所以需要在apache集群上配置CDH集群,让distcp能识别出CDH的nameservice

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[root@hadoop101 hadoop]# vim /opt/module/hadoop-3.1.3/etc/hadoop/hdfs-site.xml 
<!--配置nameservice-->
<property>
<name>dfs.nameservices</name>
<value>mycluster,nameservice1</value>
</property>

<!--指定本地服务-->
<property>
<name>dfs.internal.nameservices</name>
<value>mycluster,nameservice1</value>
</property>
<!--配置多NamenNode-->
<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1,nn2,nn3</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>hadoop101:8020</value>
</property>
<property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>hadoop102:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn3</name>
<value>hadoop103:8020</value>
</property>
<!--配置nameservice1的namenode服务-->
<property>
<name>dfs.ha.namenodes.nameservice1</name>
<value>namenode30,namenode37</value>
</property>
<property>
<name>dfs.namenode.rpc-address.nameservice1.namenode30</name>
<value>hadoop104:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.nameservice1.namenode37</name>
<value>hadoop106:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.nameservice1.namenode30</name>
<value>hadoop104:9870</value>
</property>
<property>
<name>dfs.namenode.http-address.nameservice1.namenode37</name>
<value>hadoop106:9870</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.nameservice1</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!--为NamneNode设置HTTP服务监听-->
<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>hadoop101:9870</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>hadoop102:9870</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn3</name>
<value>hadoop103:9870</value>
</property>
<!--配置HDFS客户端联系Active NameNode节点的Java类-->
<property>
<name>dfs.client.failover.proxy.provider.mycluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>

6)修改CDH hosts

1
[root@hadoop101 ~]# vim /etc/hosts

img

7)进行分发,这里的hadoop104,hadoop105,hadoop106分别对应apache的hadoop101,hadoop102,hadoop103

1
2
[root@hadoop101 ~]# scp /etc/hosts hadoop102:/etc/
[root@hadoop101 ~]# scp /etc/hosts hadoop103:/etc/

8)同样修改CDH集群配置,在所有hdfs-site.xml文件里修改配置

img

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<property>
<name>dfs.nameservices</name>
<value>mycluster,nameservice1</value>
</property>

<property>
<name>dfs.internal.nameservices</name>
<value>nameservice1</value>
</property>

<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1,nn2,nn3</value>
</property>

<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>hadoop104:8020</value>
</property>

<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>hadoop105:8020</value>
</property>

<property>
<name>dfs.namenode.rpc-address.mycluster.nn3</name>
<value>hadoop106:8020</value>
</property>

<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>hadoop104:9870</value>
</property>

<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>hadoop105:9870</value>
</property>

<property>
<name>dfs.namenode.http-address.mycluster.nn3</name>
<value>hadoop106:9870</value>
</property>

<property>
<name>dfs.client.failover.proxy.provider.mycluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>

9)最后注意:重点由于我的Apahce集群和CDH集群3台集群都是hadoop101,hadoop102,hadoop103所以要关闭域名访问,使用IP访问

CDH把钩去了

img

10)apache设置为false

img

11)再使用hadoop distcp命令进行迁移,-Dmapred.job.queue.name指定队列,默认是default队列。上面配置集群都配了的话,那么在CDH和apache集群下都可以执行这个命令

1
[root@hadoop101 hadoop]# hadoop distcp -Dmapred.job.queue.name=hive  webhdfs://mycluster:9070/user/hive/warehouse/dwd.db/  hdfs://nameservice1/user/hive/warehouse

img

12)会启动一个MR任务,正在迁移

img

13)查看cdh 9870 http地址

img

img

img

14)数据已经成功迁移。数据迁移成功之后,接下来迁移hive表结构,编写shell脚本

1
2
3
4
5
6
7
8
[root@hadoop101 module]# vim exportHive.sh 
#!/bin/bash
hive -e "use dwd;show tables">tables.txt
cat tables.txt |while read eachline
do
hive -e "use dwd;show create table $eachline">>tablesDDL.txt
echo ";" >> tablesDDL.txt
done

15)执行脚本后将tablesDDL.txt文件分发到CDH集群下

1
[root@hadoop101 module]# scp tablesDDL.txt hadoop104:/opt/module/

16)然后CDH下导入此表结构,先进到CDH的hive里创建dwd库

1
2
[root@hadoop101 module]# hive
hive> create database dwd;

17)创建数据库后,边界tablesDDL.txt在最上方加上use dwd;

img

18)并且将createtab_stmt都替换成空格

1
[root@hadoop101 module]# sed -i s"#createtab_stmt# #g" tablesDDL.txt

19)最后执行hive -f命令将表结构导入

1
[root@hadoop101 module]# hive -f tablesDDL.txt 

img

20)最后将表的分区重新刷新下,只有刷新分区才能把数据读出来,编写脚本

1
2
3
4
5
6
7
8
9
[root@hadoop101 module]# vim msckPartition.sh
#!/bin/bash
hive -e "use dwd;show tables">tables.txt
cat tables.txt |while read eachline
do
hive -e "use dwd;MSCK REPAIR TABLE $eachline"
done
[root@hadoop101 module]# chmod +777 msckPartition.sh
[root@hadoop101 module]# ./msckPartition.sh

21)刷完分区后,查询表数据

img