大数据可视化技术之Superset

1、介绍

1.1、概述

  • Apache Superset 是一个开源的数据探查与可视化平台(曾用名 Panoramix、Caravel ),该工具在可视化、易用性和交互性上非常有特色,用户可以轻松对数据进行可视化分析。Superset 也是一款企业级商业智能 Web 应用程序。

  • Apache Superset是一个开源的、现代的、轻量级BI分析工具,能够对接多种数据源、拥有丰富的图标展示形式、支持自定义仪表盘,且拥有友好的用户界面,十分易用。

1.2 Superset应用场景

由于Superset能够对接常用的大数据分析工具,如Hive、Kylin、Druid等,且支持自定义仪表盘,故可作为数仓的可视化工具。

在这里插入图片描述

2、superset的安装

superset官网Welcome | Superset (apache.org)

2.1、安装Python环境

Superset是由Python语言编写的Web应用,要求Python3.6的环境。

2.1.1、安装Miniconda

conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同Python版本的软件包及其依赖,并能够在不同的Python环境之间切换,Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等,Miniconda包括Conda、Python。此处,我们不需要如此多的工具包,故选择MiniConda。

  1. 下载Miniconda(Python3版本)

    下载地址:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

  2. 安装Miniconda

    1. 执行以下命令进行安装,并按照提示操作,直到安装完成

      [root@localhost ~]# sh Miniconda3-latest-Linux-x86_64.sh
      
    2. 出现以下界面按enter

      在这里插入图片描述

    3. 进入阅读协议界面,然后按空格键,之后输入yes 同意协议

      在这里插入图片描述

    4. 选择安装路径 /opt/module/miniconda3

      在这里插入图片描述

    5. 输入yes,进行初始化

      在这里插入图片描述

    6. 安装成功

      在这里插入图片描述

    7. 加载环境变量配置文件,使之生效

      [root@localhost ~]# source ~/.bashrc
      

      在这里插入图片描述

    8. 取消激活base环境

      Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。

      (base) [root@localhost ~]# conda config --set auto_activate_base false
      

      执行完成后,重新连接就不会有base

2.1.2、创建Python3.6的环境
  1. 配置conda国内镜像

    [root@localhost ~]# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    [root@localhost ~]# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
    [root@localhost ~]# conda config --set show_channel_urls yes
    
  2. 创建Python3.6环境,将这个环境命名为superset

    [root@localhost ~]# conda create --name superset python=3.6
    

    在这里插入图片描述

    说明:conda环境管理常用命令

    创建环境:conda create -n env_name

    查看所有环境:conda info --envs

    删除一个环境:conda remove -n env_name --all

2.2、Superset部署

  1. 激活superset环境

    [root@localhost ~]# conda activate superset
    (superset) [root@localhost ~]#  
    
  2. 安装依赖

    (superset) [root@localhost ~]# yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel
    
  3. 安装(更新)setuptools和pip

    (superset) [root@localhost ~]# pip install --upgrade setuptools pip -i https://pypi.tuna.tsinghua.edu.cn/simple
    

    安装两个库

    (superset) [root@localhost ~]# pip install sqlalchemy==1.3.24
    (superset) [root@localhost ~]# pip install dataclasses
    
  4. 安装Superset

    # -i 是指定国内镜像
    (superset) [root@localhost ~]# pip install apache-superset -i https://pypi.tuna.tsinghua.edu.cn/simple
    

    cryptography这个库删除,版本太低了,安装3.4.8版本的

    (superset) [root@localhost ~]# pip uninstall cryptography
    (superset) [root@localhost ~]# pip install cryptography==3.4.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  5. 初始化Superset数据库

    (superset) [root@localhost ~]# superset db upgrade
    
  6. 创建管理员用户

    (superset) [root@localhost ~]# export FLASK_APP=superset
    (superset) [root@localhost ~]# superset fab create-admin
    

    在这里插入图片描述

  7. Superset初始化

    (superset) [root@localhost ~]# superset init
    
  8. 启动Supterset

    (superset) [root@localhost ~]# gunicorn --workers 5 --timeout 120 --bind 192.168.48.100:8787  "superset.app:create_app()" --daemon
    

    说明:

    –workers:指定进程个数

    –timeout:worke进程超时时间,超时会自动重启

    –bind:绑定本机地址,即为Superset访问地址

    –daemon:后台运行

访问http://192.168.48.100:8787/,并使用上面创建的管理员账号进行登录

2.3、编写superset启停脚本

#!/bin/bash

superset_status(){
    result=`ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | wc -l`
    if [[ $result -eq 0 ]]; then
        return 0
    else
        return 1
    fi
}
superset_start(){
        source ~/.bashrc
        superset_status >/dev/null 2>&1
        if [[ $? -eq 0 ]]; then
            conda activate superset ; gunicorn --workers 5 --timeout 120 --bind 192.168.48.100:8787 --daemon 'superset.app:create_app()'
        else
            echo "superset正在运行"
        fi

}

superset_stop(){
    superset_status >/dev/null 2>&1
    if [[ $? -eq 0 ]]; then
        echo "superset未在运行"
    else
        ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9
    fi
}


case $1 in
    start )
        echo "启动Superset"
        superset_start
    ;;
    stop )
        echo "停止Superset"
        superset_stop
    ;;
    restart )
        echo "重启Superset"
        superset_stop
        superset_start
    ;;
    status )
        superset_status >/dev/null 2>&1
        if [[ $? -eq 0 ]]; then
            echo "superset未在运行"
        else
            echo "superset正在运行"
        fi
esac
# 启动superset
(superset) [root@localhost shell]# sh superset.sh start
# 停止superset
(superset) [root@localhost shell]# sh superset.sh stop
# 重启superset
(superset) [root@localhost shell]# sh superset.sh restart
# 查看superset运行状态
(superset) [root@localhost shell]# sh superset.sh status

3、superset的使用

快速入门地址快速入门 | Websoft9

1、对接数据库

# 对接MySQL
(superset) [root@localhost shell]# conda install mysqlclient

说明:对接不同的数据源,需安装不同的依赖,以下地址为官网说明

https://superset.apache.org/docs/databases/installing-database-drivers

2、数据源配置

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

注:SQL Alchemy URI编写规范:mysql://用户名:密码@主机名:端口号/数据库名称

测试连接成功后保存,保存按钮再最下面

3、配置表

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

4、制作仪表盘

在这里插入图片描述

5、创建图表

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值