zoukankan      html  css  js  c++  java
  • CDH 集群机器上部署 Jupyter notebook 使用 Pyspark 读取 Hive 数据库

    开始直接在 CDH Pyspark 的环境里面运行 Ipython 。

    spark = SparkSession 
            .builder 
            .master('yarn') 
            .appName('md_day_dump_users') 
            .enableHiveSupport() 
            .getOrCreate()

    In [3]: spark.sql('show databases').show()
    +------------+
    |databaseName|
    +------------+
    | default|
    +------------+

    可以用看到,我们直接使用这个配置去读取 hive 数据库并不能获得我们想要的数据库,而是只能读取到一个 default 默认数据库。

    很明显是我们现在的 client 端还并没有得到 hive metastore 数据库的数据。无法知晓现在 hive 数据库的情况。

    所以我们需要为其添加一些参数让他能读取到 hive 的 metastore,通过访问 hive 的 metastore.uris 就可以用获取,我们使用配置

    spark = SparkSession 
            .builder 
            .master('yarn') 
            .appName('md_day_dump_users') 
            .config("hive.metastore.uris", "thrift://ryze-1:9083") 
            .enableHiveSupport() 
            .getOrCreate()
    spark.sql("show databases").show()
    
    +-------------+
    | databaseName|
    +-------------+
    |ads_algorithm|
    | analytics_db|
    |       course|
    |      default|
    |dw_dim_global|
    |    dw_matrix|
    |       member|
    |          pay|
    |    recommend|
    |      sensors|
    |          tmp|
    |         user|
    |       yanzhi|
    +-------------+

    替换当前的配置,就可以了。

    在 ipython 跑通整个流程之后,剩下的我们就是在当前权限用户下安装 Jupyter 。按照官方教程来安装,注意我们使用的是 Python2.7.x 所以要选择 2.7.x 的安装方法,最终我的同事折腾了一下还替换掉一个 kernal 搞定。跑起来之后就可以从服务器上直接通过 SparkSession 来方便的使用 Spark 测试跑数据或者出数据了。

    另外需要注意的一点是,由于我们使用的是 CDH ,可以非常方便的动态配置资源池,在为了不影响其他同步任务的情况下,我为 Jupyter 配置了单独的支援池,可以和其他池子里面的任务互不影响。因为这个脚本可能起多个,所以如果我们起得太多可能会影响到正常的同步脚本和任务使用资源。

    使用特定的池也很简单,指定参数  .config('spark.yarn.queue', 'root.jupyter')  即可。

    Reference:

    https://stackoverflow.com/questions/51128243/hive-databases-only-list-default-db  hive-databases-only-list-default-db

    https://stackoverflow.com/questions/31980584/how-to-connect-to-a-hive-metastore-programmatically-in-sparksql  how-to-connect-to-a-hive-metastore-programmatically-in-sparksql

    https://stackoverflow.com/questions/48646097/setting-yarn-queue-in-pyspark  setting-yarn-queue-in-pyspark

  • 相关阅读:
    Azure PowerShell (7) 使用CSV文件批量设置Virtual Machine Endpoint
    Windows Azure Cloud Service (39) 如何将现有Web应用迁移到Azure PaaS平台
    Azure China (7) 使用WebMetrix将Web Site发布至Azure China
    Microsoft Azure News(4) Azure新D系列虚拟机上线
    Windows Azure Cloud Service (38) 微软IaaS与PaaS比较
    Windows Azure Cloud Service (37) 浅谈Cloud Service
    Azure PowerShell (6) 设置单个Virtual Machine Endpoint
    Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    功能代码(1)---通过Jquery来处理复选框
    案例1.用Ajax实现用户名的校验
  • 原文地址:https://www.cnblogs.com/piperck/p/10453530.html
Copyright © 2011-2022 走看看