Use ambari easy one-button set up large data clusters

Disclaimer: This article is the original article bloggers, bloggers girlfriend without permit shall not be reproduced. https://blog.csdn.net/qq_26442553/article/details/88845920

Ambari with Hadoop and other open source software, is a project of the Apache Software Foundation, and is a top-level project. The latest released version is 2.0.1, the next version 2.1 will be released soon. On the role of Ambari, it is to create, manage, monitor Hadoop cluster, but Hadoop here is a broad sense, refers to the entire Hadoop ecosystem (such as Hive, Hbase, Sqoop, Zookeeper, etc.), and not just specific to Hadoop . One sentence, Ambari is to allow Hadoop and big data related to a software tool easier to use.

Here, you should understand what the people need most Ambari. Those struggling to take several days to install, debugging Hadoop beginners is the best place to appreciate the convenience of the Ambari. Moreover, Ambari now supported by more and more platform components, such as the popular Spark, Storm and other computing framework, and resource scheduling platform YARN, etc., we can easily be deployed by Ambari.

Ambari itself is a distributed architecture of the software, mainly consists of two parts: Ambari Server and Ambari Agent. Briefly, the user notification Ambari Server Ambari Agent install the corresponding software; - Agent periodically transmits the state of each individual machine to Ambari Server software module, eventually the status information presented in the GUI Ambari, user clusters learned various states, and the corresponding maintenance. Detailed operation will be introduced and described in subsequent sections.

Ambari installation

Installation Preparation

About installation Ambari, the current Internet can find two releases, one is the Apache Ambari, the other is Hortonworks's little difference between the two. Here as an Apache Ambari 2.0.1 of example. As used herein, three Redhat 6.6 installation environment (currently running tests to verify results Ambari relatively stable in the version of Redhat 6.6), three machines were zwshen37.example.com, zwshen38.example.com, zwshen39.example.com. zwshen37 as Ambari plan to install the Server, the other two for the Ambari Agent.

Install the most convenient way is to use Ambari public library source (public repository). Interested friends can look at themselves to build a local database (local repository) to install. This is not the point, so not repeat them here. Before specific installation, you need to do some preparatory work.

  1. SSH login without a password;
    Ambari the Server Agent can SSH into the machine, copy and execute commands. So we need to configure Ambari Server to SSH Agent no login password. In this example, zwshen37 can SSH without password zwshen38 and zwshen39.
  2. Yum can ensure normal work;
    through public libraries (public repository), installation of Hadoop software, in fact, is the application behind the Yum rpm packages installed inside the public library. So here you need your machine can access the Internet.
  3. Ensure write access to home directories.
    Ambari will create some OS users.
  4. Python versions ensure that the machine is equal to or greater than 2.6. (Redhat6.6, the default is 2.6).

After the above preparations are completed, we can really begin the installation Ambari.

Installation process

First we need to get Ambari public libraries (public repository). Log on to the Linux host and execute the following command (you can also download their own hand):

1

wget <a href="http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.0.1/ambari.repo"><code>http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.0.1/ambari.repo</code></a>

Ambari.repo the downloaded files are copied to the Linux system directory /etc/yum.repos.d/. After the copy, we need to get a list of all the source files of the public library. In turn execute the following command.

1

2

yum clean all

yum list|grep ambari

As shown in Figure 1:

Figure 1. Obtain a list of source files public library

Figure 1. Obtain a list of source files public library

If you can see a list of installed packages corresponding version of the Ambari, the Public Library has been configured successfully. Then you can install the package of Ambari. Execute the following command to install Ambari Server to the machine.

1

yum install ambari-server

After the installation is complete, you need to make a simple Ambari Server configuration. Execute the following command.

1

amari-server setup

In this interactive setup, you can use the default settings. Ambari will use Postgres database, installed by default and uses Oracle's JDK. The default setting of the Ambari GUI login user is admin / admin. And specify Ambari Server running user is root.

After a simple setup configuration is complete. You can start the Ambari. Run the following command.

1

ambari-server start

After the successful launch of Ambari Server, you can log in from a browser, the default port 8080. This paper to the environment, for example, in the address bar of the browser input http://zwshen37.example.com:8080, password is admin / admin. Page after login Ambari in the following figure.

Figure 2. Ambari welcome page

Figure 2. Ambari welcome page

Click for larger image

So far, Ambari Server installation is complete.

Deploy a cluster Hadoop2.x

To this section, we will be able to truly experience the Ambari arena, and at the convenience it can bring.

After logging Ambari, click the button "Launch Install Wizard", you can begin to create their own big data platform.

The first step , named after the name of the cluster. This environment bigdata.

第二步,选择一个 Stack,这个 Stack 相当于一个 Hadoop 生态圈软件的集合。Stack 的版本越高,里面的软件版本也就越高。这里我们选择 HDP2.2,里面的对应的 Hadoop 版本为 2.6.x。

第三步,指定 Agent 机器(如果配置了域,必须包含完整域名,例如本文环境的域为 example.com),这些机器会被安装 Hadoop 等软件包。还记得在安装章节中提到的 SSH 无密码登陆吗,这里需要指定当时在 Ambari Server 机器生成的私钥(ssh-keygen 生成的,公钥已经拷贝到 Ambari Agent 的机器,具体的 SSH 无密码登录配置,可以在网上很容易找到配置方法,不在此赘述)。另外不要选择“Perform manual registration on hosts and do not use SSH“。因为我们需要 Ambari Server 自动去安装 Ambari Agent。具体参见下图示例。

图 3. 安装配置页面

Figure 3. Installation configuration page

点击查看大图

第四步,Ambari Server 会自动安装 Ambari Agent 到刚才指定的机器列表。安装完成后,Agent 会向 Ambari Server 注册。成功注册后,就可以继续 Next 到下一步。

第五步,这里我们终于看到跟 Hadoop 有关的名词了。在这一步,我们需要选择要安装的软件名称。本文环境选择了 HDFS,YARN + MapReduce2,Zoopkeeper,Storm 以及 Spark。选的越多,就会需要越多的机器内存。选择之后就可以继续下一步了。这里需要注意某些 Service 是有依赖关系的。如果您选了一个需要依赖其他 Service 的一个 Service,Ambari 会提醒安装对应依赖的 Service。参见下图。

图 4. Service 选择页面

Figure 4. Service selection page

点击查看大图

第六步和第七步,分别是选择安装软件所指定的 Master 机器和 Slave 机器,以及 Client 机器。这里使用默认选择即可(真正在生产环境中,需要根据具体的机器配置选择)。

第八步,就是 Service 的配置。绝大部分配置已经有默认值,不需要修改。初学者,如果不需要进行调优是可以直接使用默认配置的。有些 Service 会有一些必须的手工配置项,则必须手动输入,才可以下一步。本文环境直接使用默认配置。

第九步,Ambari 会总结一个安装列表,供用户审阅。这里没问题,就直接下一步。

第十步,Ambari 会开始安装选择的 Service 到 Ambari Agent 的机器(如下图)。这里可能需要等好一会,因为都是在线安装。安装完成之后,Ambari 就会启动这些 Service。

图 5. Service 的安装进度

5. Service of the progress of the installation of FIG.

点击查看大图

安装完成之后,就可以查看 Ambari 的 Dashboard 了。例如下图。

图 6. Ambari 的 Dashboard 页面

Figure 6. Ambari the Dashboard page

点击查看大图

至此,您专属的 bigdata 集群已经安装完成。

利用 Ambari 管理 Hadoop 集群

在上一章节中,我们已经体验到 Ambari 为 Hadoop 生态圈的安装提供的便利。这已经省去了很多的人力成本。尤其是对大数据圈子的测试人员来说,自动化就容易了很多。下面我们看看如何通过 Ambari 管理 Hadoop 的集群。

Service Level Action(服务级别的操作)

首先我们进到 Ambari 的 GUI 页面,并查看 Dashboard。在左侧的 Service 列表中,我们可以点击任何一个您想要操作的 Service。以 MapReduce2 为例(Hadoop 这里的版本为 2.6.x,也就是 YARN+HDFS+MapReduce),当点击 MapReduce2 后,就会看到该 Service 的相关信息,如下图。

图 7. MapRduce2 的 Service 页面

Figure 7. MapRduce2 of Service page

点击查看大图

中间部分是 Service 的模块(Component)信息,也就是该 Service 有哪些模块及其数目。右上角有个 Service Action 的按钮,当点击该按钮后就可以看到很多 Service 的控制命令。也就是通过这些 Service Action 命令,对 Service 进行管理的。

可能有的人会说,装完 Hadoop 的集群后,并不知道这个集群是不是可用。这时候我们就可以运行一个“Run Service Check”。点击这个命令后,就会出现下图的进度显示。

图 8. MapReduce Service Check

图 8. MapReduce Service Check

点击查看大图

其实这里就是通过运行一个经典的 MapReduce Wordcount 实例,来检查 MapReduce 是不是正常。对于 Service Action 里面的 Start、Stop 的含义就是,启停整个集群所有该 Service 的模块(也就是 Service level)。当执行进度页面弹出来的时候,我们可以点击 Operations 的名字,进而查看每个机器的进度和运行 log。如下图 Stop 的操作。

图 9. 命令执行进度 1

9. FIG command execution progress

点击查看大图

图 10. 命令执行进度 2

10. FIG progress command 2

点击查看大图

维护模式(Maintenance Mode)以及如何添加一个自定义的命令到 Service Action,我会在后续的连载中进行介绍。

Host Level Action(机器级别的操作)

首先,我们回到 Ambari 的 Dashboard 页面。页面最上面中间的地方有个 Hosts,点击这个标签,我们就可以看到 Ambari 所管理的机器列表。如下图。

图 11. Ambari 的机器列表

The list view of the machine 11. Ambari

点击查看大图

图片中红色的数字是警告信息(Ambari Alert),这里我们先略过它,后续文章再做介绍。先看左上角的 Actions,点击这个按钮,就可以看到 Host level Action 的选项了,其实和 Service Level 是类似的,只是执行的范围不一样。如下图。当用户选择 All Hosts -> Hosts -> Start All Components,Ambari 就会将所有 Service 的所有模块启动。

图 12. 启动所有 Service 的所有模块

图 12. 启动所有 Service 的所有模块

如果用户选择 All Hosts-> DataNodes -> Stop,Ambari 就会把所有机器的 DataNode 这个模块关闭。如下图。

图 13. 关闭所有的 DataNode 模块

图 13. 关闭所有的 DataNode 模块

Component Level Action(模块级别的操作)

上面的图中,我们可以看到 Decommisson、Recommission。这些命令其实是自定义的模块级别的操作(Component Level Action)。不过上图中命令一旦执行,就是对多个机器的同个模块执行。

我们现在尝试只对单个机器的一个模块(Component)执行。首先我们回到 Hosts 的页面。这时候点击机器名,我们就会进入到该机器的 Component 页面。如下图。

图 14. Component 页面

图 14. Component 页面

这时候只要点击每个 Component(模块)后面的按钮,就可以看到该模块的操作命令了。例如,我们可以停掉这台机器的 DataNode 模块。

图 15. 停止 DataNode 模块 1

图 15. 停止 DataNode 模块

图 16. 停止 DataNode 模块 2

图 16. 停止 DataNode 模块 2

点击查看大图

关于如何给一个模块添加自定义的命令,也会在后续的连载中做介绍。

这一章节中,主要介绍了如何通过三种级别的 Action(操作)管理 Hadoop 的集群。在 Ambari 中已经加入了很多自定义的 Action 去做一些特殊的操作。如果对 Hadoop 生态圈的软件足够熟悉,就可以尝试更多的 Action。可能有的人会问,Ambari 可不可以扩容集群。答案当然是可以的。Ambari 可以给自身的集群添加机器(也就是添加 Ambari Agent),然后将 Service 的模块安装在新的机器,也可以把某些模块安装到已有的其他的机器。篇幅有限,将在后续的连载中介绍更多的内容。

Ambari 的架构和工作原理

Ambari 基本的架构和工作原理如下图 17 所示。

图 17. Ambari 的基本架构

图 17. Ambari 的基本架构

Ambari Server 会读取 Stack 和 Service 的配置文件。当用 Ambari 创建集群的时候,Ambari Server 传送 Stack 和 Service 的配置文件以及 Service 生命周期的控制脚本到 Ambari Agent。Agent 拿到配置文件后,会下载安装公共源里软件包(Redhat,就是使用 yum 服务)。安装完成后,Ambari Server 会通知 Agent 去启动 Service。之后 Ambari Server 会定期发送命令到 Agent 检查 Service 的状态,Agent 上报给 Server,并呈现在 Ambari 的 GUI 上。

Ambari Server 支持 Rest API,这样可以很容易的扩展和定制化 Ambari。甚至于不用登陆 Ambari 的 GUI,只需要在命令行通过 curl 就可以控制 Ambari,以及控制 Hadoop 的 cluster。具体的 API 可以参见 Apache Ambari 的官方网页 API reference。

对于安全方面要求比较苛刻的环境来说,Ambari 可以支持 Kerberos 认证的 Hadoop 集群。

扩展 Ambari 管理一个自定义的 Service

首先,我们需要规划自定义的 Service 属于哪个 Stack(当然 Stack 也是可以自定义的)。这里为了快速创建一个新的 Service,而且我们已经安装了 HDP 2.2 的 Stack,所以就将自定义的 Service 放在 HDP 2.2 之下。

第一步,首先在 Ambari Service 机器上找到 HDP 2.2 Stack 的目录,如下图所示。

图 18. HDP 2.2 的目录

图 18. HDP 2.2 的目录

第二步,需要创建一个 Service 目录,我们这里用“SAMPLE”作为目录名。并在 SAMPLE 底下创建 metainfo.xml。示例代码如下。主要解释下 xml 代码中的两个字段 category 和 cardinality。category 指定了该模块(Component)的类别,可以是 MASTER、SLAVE、CLIENT。Cardinality 指的是所要安装的机器数,可以是固定数字 1,可以是一个范围比如 1-2,也可以是 1+,或者 ALL。如果是一个范围的时候,安装的时候会让用户选择机器。另外这里有关 Service 和 Component 的 name 配置要用大写,小写有时候会有问题。Displayname 可以随意设置。

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

<?xml version="1.0"?>

<metainfo>

 <schemaVersion>2.0</schemaVersion>

 <services>

 <service>

 <name>SAMPLE</name>

 <displayName>My Sample</displayName>

 <comment>My v1 Sample</comment>

 <version>1.0</version>

 <components>

 <component>

 <name>MYMASTER</name>

 <displayName>My Master</displayName>

 <category>MASTER</category>

 <cardinality>1</cardinality>

 <commandScript>

 <script>scripts/master.py</script>

 <scriptType>PYTHON</scriptType>

 <timeout>5000</timeout>

 </commandScript>

 </component>

 <component>

 <name>MYSALVE</name>

 <displayName>My Slave</displayName>

 <category>SLAVE</category>

 <cardinality>1+</cardinality>

 <commandScript>

 <script>scripts/slave.py</script>

 <scriptType>PYTHON</scriptType>

 <timeout>5000</timeout>

 </commandScript>

 </component>

 </components>

 <osSpecifics>

 <osSpecific>

 <osFamily>any</osFamily>

 </osSpecific>

 </osSpecifics>

 </service>

 </services>

</metainfo>

第三步,需要创建 Service 的控制脚本。这里我们需要在 SAMPLE 底下创建一个 package 目录,然后在 package 底下创建目录 scripts ,进而创建 master.py 和 slave.py。这里需要保证脚本路径和上一步中 metainfo.xml 中的配置路径是一致的。这两个 Python 脚本是用来控制 Master 和 Slave 模块的生命周期。脚本中函数的含义也如其名字一样:install 就是安装调用的接口;start、stop 分别就是启停的调用;Status 是定期检查 component 状态的调用;Configure 是安装完成配置该模块的调用。示例目录结构如下图。

图 19. Sample Service 的目录结构

图 19. Sample Service 的目录结构

Python 脚本的示例代码:

Master.py:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

import sys, os

from resource_management import *

from resource_management.core.exceptions import ComponentIsNotRunning

from resource_management.core.environment import Environment

from resource_management.core.logger import Logger

 

class Master(Script):

 def install(self, env):

 print "Install My Master"

 

 def configure(self, env):

 print "Configure My Master"

 

 def start(self, env):

 print "Start My Master"

 

 def stop(self, env):

 print "Stop My Master"

 

 def status(self, env):

 print "Status..."

 

if __name__ == "__main__":

 Master().execute()

Slave.py:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

import sys, os

from resource_management import *

from resource_management.core.exceptions import ComponentIsNotRunning

from resource_management.core.environment import Environment

from resource_management.core.logger import Logger

 

class Slave(Script):

 def install(self, env):

 print "Install My Slave"

 

 def configure(self, env):

 print "Configure My Slave"

 

 def start(self, env):

 print "Start My Slave"

 

 def stop(self, env):

 print "Stop My Slave"

 def status(self, env):

 print "Status..."

 

if __name__ == "__main__":

 Slave().execute()

第四步,需要重启 Ambari Server。因为 Ambari Server 只有在重启的时候才会读取 Service 和 Stack 的配置。命令行执行:

1

ambari-server restart

第五步,登录 Ambari 的 GUI,点击左下角的 Action,选择 Add Service。如下图:

图 20. Add Service 按钮

图 20. Add Service 按钮

这时候就可以看到我们自定义的 Service:SAMPLE。如下图:

图 21. Sample Service 列表

图 21. Sample Service 列表

点击查看大图

选择左侧 My Sample 后,就可以一路 Next 了,这个过程其实和我们在搭建 Hadoop2.x 集群的时候是类似的。由于这个 Service 没有真的安装包,所以安装过程会非常的快,启动命令也没有真正的逻辑,所以启动过程也是很快的。等最后点击完 Complete,整个安装过程也就结束了。再回到 Ambari 的 Dashboard 的时候,我们就可以看到这个 My Sample 了,如下图:

图 22. My Sample 的 Service 页面

图 22. My Sample 的 Service 页面

点击查看大图

This will be the fourth quarter and in the same Hadoop cluster management to manage our My Sample. For example the following figure, Stop our My Sample.

FIG page 23. Stop Sample 1

图 23. Stop Sample 页面 1

FIG page 24. Stop Sample 2

图 24. Stop Sample 页面 2

Figure 25. Stop Sample page 3

图 25. Stop Sample 页面 3

Advanced in space, we will explore how to customize how My Sample dependencies between some of the Actions, and Action definitions. Limited space, here on the first stop here. I hope the above introduction to ignite people's passion for Ambari.

to sum up

Big data and cloud computing data center today can be described as two of the hottest areas of technology, almost all IT service providers want to accomplish something in these two technologies. I believe Ambari Hadoop can help some beginners. In the long run, is inseparable from the development of big data cloud computing can be described as very mature cloud IaaS, and low prices. At this time many companies zeroed in on the PaaS. Popular big data is to accelerate the development of related PaaS products, and the emergence of inevitable Ambari can narrow the distance between IaaS and PaaS is. That has Ambari, perhaps coupled with Docker, then the rapid evolution from IaaS to PaaS it is not so difficult.

Of course, here Ambari keep IaaS better fit, there is a rival that is the Sahara. It is another native of OpenStack subproject, which also aims to quickly set up in clusters like Hadoop Openstack above. These projects can look forward to rapid growth, we have the help of the future.

Guess you like

Origin blog.csdn.net/qq_26442553/article/details/88845920