Superset环境搭建与基本使用

Apache Superset 是一个现代化的企业级商业智能 Web 应用程序,快速、轻量和直观。Superset支持接入各类数据源,提供了丰富的图表,所有技能组合的用户都可以轻松地对数据进行探索和可视化。

Miniconda安装

Superset是基于Python环境开发, 我们需要一套Python的环境。 推荐使用Conda搭建Python环境,对环境进行管理,在本地操作系统可搭建多套环境, 实现对环境的隔离、升级和切换等。

Conda是一个在Windows、macOS和Linux上运行的开源软件包和环境管理系统。Conda可以快速安装、运行和更新软件包及其依赖项。它还可以轻松地在本地计算机上创建、保存、加载和切换环境。它是为Python程序创建的,但它可以为任何语言打包和分发软件。支持的编程语言:Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN等。

Miniconda是conda的简化版本, 仅包括conda、Python及其所依赖的包,以及少量其他有用的包,包括pip、zlib和其他一些包。

Miniconda的官方文档:

  • https://docs.conda.io/en/latest/miniconda.html

我们使用Miniconda管理Superset的环境。

下载链接:

  • https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh 。

下载好的安装脚本如下:

<code style="margin-left:0"># ls -lh
总用量 74M
-rw-r--r-- 1 root root 74M 8月  24 11:22 Miniconda3-py39_4.12.0-Linux-x86_64.sh</code>

安装Miniconda:

<code style="margin-left:0">bash Miniconda3-py39_4.12.0-Linux-x86_64.sh </code>

提示输入回车键(Enter),阅读协议,然后提示是否已接受licence条款,如下所示,输入yes:

<code style="margin-left:0">Do you accept the license terms? [yes|no]
[no] >>> 
Please answer 'yes' or 'no':'</code>

如下提示,输入安装的位置,直接回车:

<code style="margin-left:0">Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>> </code>

是否运行conda init,输入yes,完成安装:

<code style="margin-left:0">installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> </code>

使Superset的环境变量生效:

<code style="margin-left:0">$ source ~/.bashrc</code>

验证Miniconda是否安装成功, 输入conda help,显示如下,则表示conda安装成功:

<code style="margin-left:0"># conda help
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    compare      Compare packages between conda environments.
    config       Modify configuration values in .condarc. This is modeled after the git config command. Writes to the user .condarc file (/root/.condarc)
                 by default.
    create       Create a new conda environment from a list of specified packages.
    help         Displays a list of available conda commands and their help strings.
    info         Display information about current conda install.
    init         Initialize conda for shell interaction. [Experimental]
    install      Installs a list of packages into a specified conda environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove.
    run          Run an executable in a conda environment.
    search       Search for packages and display associated information. The input is a MatchSpec, a query language for conda packages. See examples
                 below.
    update       Updates conda packages to the latest compatible version.
    upgrade      Alias for conda update.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit</code>

主页如下:

(2)、第一步,选择"ClickHouse Connect"作为数据库的类型。

(3)、第二步,输入:

  • **HOST和PORT:**ClickHouse的主机和HTTP端口。当启用TLS,端口为8143,否则为8123。也可以指定为代理主机的主机名和端口, 例如chproxy的主机和端口。
  • **DATABASE NAME:**数据库名。
  • **USERNAME和PASSWORD:**用户名和密码。
  • **DISPLAY NAME:**ClickHouse数据库的显示名称。
  • **ADDITIONAL PARAMETERS:**额外的参数,例如socket超时时间,外部聚合的参数等。

(4)、点击"CONNECT"和下一步的"FINISH"按钮完成设置向导。 在页面上显示添加的数据库列表。

添加数据集

使用Superset与ClickHouse交互,需要定义一个数据集。

(1)、在顶部菜单,选择Data,下拉选择Datasets,添加一个数据集。

(2)、点击添加数据集的按钮,选择一个数据库作为数据源,下拉将看到定义的库和表。

下拉选择DATABASE、SCHEMA和TABLE:

(3)、点击ADD按钮, 在页面上显示添加的数据集列表。

在Superset创建charts

在Superset中创建charts和dashboard, 一个dashboard由多个charts组成。

(1)、在顶部菜单,选择Charts,点击添加图表按钮CHART。

(2)、选择数据集、图表,点击"CREATE NEW CHART"按钮

  • 此处,选择"Big Number"的chart。

(3)、添加Metric

(4)、指定Metric为COUNT(*)

(5)、点击左上侧的"RUN"或者右侧的"RUN QUERY"按钮,查看运行的结果。

效果如下:

(6)、点击左上侧的"SAVE"按钮,指定"CHART NAME", 保存chart。

在Charts页面,可以看到创建的Chart列表:


在Superset创建dashboard

(1)、在顶部菜单,选择Dashboards,点击添加按钮DASHBOARD。

(2)、切换至CHARTS,可以看到创建的charts列表。

(3)、在"bignumber"的chart上面,按住鼠标左键,拖拽至左侧的画布。

(4)、修改dashboard名称,并保存。

Dashboard的效果如下:


Superset官方的ClickHouse Driver

刚刚介绍的是基于ClickHouse官方提供的ClickHouse Driver,连接至ClickHouse,使用的是HTTP的协议。Superset官方也提供了ClickHouse的Driver, 使用的TCP的协议。

除了在Superset创建数据库有所差异,其他使用方式与ClickHouse提供的driver相同。

(1)、安装Python库

<code style="margin-left:0">pip install clickhouse-driver==0.2.4 

pip install clickhouse-sqlalchemy==0.1.10</code>

(2)、创建数据库

第一步,选择ClickHouse类型。

第二步, 指定URI:

SQLALCHEMY URI格式:

<code style="margin-left:0">clickhouse+native://{username}:{password}@{hostname}:{port}/{database} </code>

端口为TCP端口,默认为90000。

未经允许不得转载:木盒主机 » Superset环境搭建与基本使用

赞 (0)

相关推荐

    暂无内容!