Azure HDInsight 和 Spark 大数据实战(二)

 

HDInsight cluster on Linux

 

登录 Azure portal (https://manage.windowsazure.com )

点击左下角的 NEW 按钮,然后点击 DATA SERVICES 按钮,点击 HDINSIGHT,选择 HADOOP ON LINUX,如下图所示。

 

输入集群名称,选择集群大小和账号,设定集群的密码和存储账号,下表是各个参数的含义和配置说明。

Name

Value

Cluster Name

Name of the cluster.

Cluster Size

Number of data nodes you want to deploy. The default value is 4. But the option to use 1 or 2 data nodes is also available from the drop-down. Any number of cluster nodes can be specified by using the Custom Create option. Pricing details on the billing rates for various cluster sizes are available. Click the ? symbol just above the drop-down box and follow the link on the pop-up.

Password

The password for the HTTP account (default user name: admin) and SSH account (default user name: hdiuser). Note that these are NOT the administrator accounts for the virtual machines on which the clusters are provisioned.

Storage Account

Select the Storage account you created from the drop-down box.
Once a Storage account is chosen, it cannot be changed. If the Storage account is removed, the cluster will no longer be available for use. The HDInsight cluster is co-located in the same datacenter as the Storage account.

 

点击 CREATE HDINSIGHT CLUSTER 即可创建运行于 Azure 的 Hadoop 集群。

上述过程快速创建一个运行Hadoop 的 Linux 集群,且默认 SSH 用户名称为 hdiuser,HTTP 账户默认名称为 admin。若要用自定义选项,例如使用 SSH 密钥进行身份验证创建群集或使用额外的存储空间,请参阅 Provision Hadoop Linux clusters in HDInsight using custom options ( https://azure.microsoft.com/en-us/documentation/articles/hdinsight-hadoop-provision-linux-clusters/ ) 。

 

Installing Spark

 

在 HDInsight 中点击创建的 Hadoop集群(在本例中集群名称为 Hadooponlinux ),进入 dashboard,如下图所示。

 

quick glance 中拷贝 Cluster Connection String的值,此为登录 Hadoop on Linux 配置控制台 Ambari的地址,在浏览器中粘贴 Cluster Connection String的值,此时出现登录用户名和密码的验证。此时的用户名为上一步中快速创建hadoop集群时默认HTTP用户名admin,密码为快速创建hadoop集群时设置的密码。

正确输入用户名和密码后,出现 Ambari的登录用户名和密码验证,此时输入用户名 admin 密码为hadoop即可进入Ambari的管理控制台。

下图展示了使用 Ambari 安装Spark的过程。

The following diagram shows the Spark installation process using Ambari.

 

  1. 选择 Ambari "Services" 选项卡。

在 Ambari "Actions" 下拉菜单中选择 "Add Service." 这将启动添加服务向导。

选择 "Spark",然后点击 "Next" 。

(For HDP 2.2.4, Ambari will install Spark version 1.2.1, not 1.2.0.2.2.)

  1. Ambari 将显示警告消息,确认集群运行的是 HDP 2.2.4 或更高版本,然后单击 "Proceed"。

Note

You can reconfirm component versions in Step 6 before finalizing the upgrade.

 

  1. 选择Spark 历史服务器节点,点击 Click "Next" 继续。

  1. 指定 Spark 的Slaves ,点击 "Next" 继续。

  2. 在客户化服务界面建议您使用默认值为您的初始配置,然后点击 "Next" 继续。
  3. Ambari 显示确认界面,点击 "Deploy" 继续。

Important

On the Review screen, make sure all HDP components are version 2.2.4 or later.

 

  1. Ambari 显示安装、启动和测试界面,其状态栏和消息则指示进度。

  2. 当Ambari安装完成,点击 "Complete" 完成 Spark 的整个安装过程。

 

Run Spark

 

通过 SSH 登录 Hadoop 的 Linux 集群,执行以下的Linux 指令下载文档,为后面的Spark程序运行使用。

wget http://en.wikipedia.org/wiki/Hortonworks


将数据拷贝至 Hadoop 集群的HDFS中,

hadoop fs -put ~/Hortonworks /user/guest/Hortonworks

 

在很多Spark的例子中采用Scala和Java的应用程序演示,本例中使用 PySpark 来演示基于Python语音的Spark使用方法。

pyspark


第一步使用 Spark Context 即 sc 创建RDD,代码如下:

myLines = sc.textFile('hdfs://sandbox.hortonworks.com/user/guest/Hortonworks')

 

现在我们实例化了RDD,下面我们对RDD做转化的操作。为此我们使用python lambda表达式做筛选。

myLines_filtered = myLines.filter( lambda x: len(x) > 0 )


请注意,以上的python语句不会引发任何RDD的执行操作,只有出现类型以下代码的count()行为才会引发真正的RDD运算。

myLines_filtered.count()

 

最终Spark Job运算的结果如下所示。

341.

 

Data Science with Spark

 

对于数据科学家而言Spark是一种高度有效的数据处理工具。数据科学家经常类似Notebook ( 如 iPython http://ipython.org/notebook.html ) 的工具来快速创建原型并分享他们的工作。许多数据科学家喜好使用 R语言,可喜的是Spark与R的集成即 SparkR已成为 Spark 新兴的能力。Apache Zeppelin (https://zeppelin.incubator.apache.org/ ) 是一种新兴的工具,提供了基于 Spark 的 Notebook 功能,这里是Apache Zeppelin 提供的易用于 Spark的用户界面视图。

 

作者:雪松

Microsoft MVP -- Windows Platform Development,

Hortonworks Certified Apache Hadoop 2.0 Developer

posted @ 2015-08-04 09:08  Xuesong  阅读(1760)  评论(2编辑  收藏  举报