Superset操作指南

1 Superset概述

superset是一个开源的、现代的、轻量级BI分析工具,支持多种数据源、拥有丰富的图表展示形式、支持自定义仪表盘。

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

2 Superset安装部署

superset是由python语言开发的web应用,要求python3.6环境

2.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

[atguigu@hadoop102 superset]$ bash Miniconda3-latest-Linux-x86_64.sh 

image-20210112162848672

image-20210112163016628

image-20210112163102379

image-20210112163140196

image-20210112163458469

image-20210112163644156

步骤3:加载环境变量配置文件,使之生效

[atguigu@hadoop102 lib]$ source ~/.bashrc

步骤4:取消激活base环境

miniconda安装完成后,再次启动会话窗口会进入到base环境,需要禁止激活base环境

[atguigu@hadoop102 lib]$ conda config --set auto_activate_base false

2.2 创建Python3.6环境

superset开发测试使用的是python3.6环境,支持python3.6和python3.7的环境

步骤1:配置conda国内镜像

(base) [atguigu@hadoop102 ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
(base) [atguigu@hadoop102 ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
(base) [atguigu@hadoop102 ~]$ conda config --set show_channel_urls yes

image-20210112163852426

步骤2:创建python3.6环境

  • conda创建环境:conda create -n env_name 或 conda create --name env_name python=版本号
  • 查看所有环境:conda info --envs
  • 删除一个环境:conda remove -n env_name --all
(base) [atguigu@hadoop102 ~]$ conda create --name superset python=3.6

image-20210112164636564

步骤3:激活superset环境

image-20210112164753673

退出当前环境

image-20210112164844873

2.3 Superset部署

步骤1:安装依赖

安装superset之前需要安装如下依赖:

(superset) [atguigu@hadoop102 ~]$ sudo yum install -y python-setuptools
(superset) [atguigu@hadoop102 ~]$ sudo yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel

步骤2:安装(更新)setuptools和pip

pip是python的包管理工具,可以和centos中的yum类比

(superset) [atguigu@hadoop102 ~]$ pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/

image-20210112171526015

步骤3:安装superset

-i的作用是指定镜像,这里选择的是国内的镜像

(superset) [atguigu@hadoop102 ~]$ pip install apache-superset -i https://pypi.douban.com/simple/

步骤4:初始化superset数据库

(superset) [atguigu@hadoop102 ~]$ superset db upgrade

image-20210112172045631

步骤5:创建管理员用户

flask是一个python web框架,superset使用的就是flask

(superset) [atguigu@hadoop102 ~]$ export FLASK_APP=superset
(superset) [atguigu@hadoop102 ~]$ flask fab create-admin

创建管理员用户,其实就是登录superset的用户:

image-20210112172650199

步骤6:superset初始化

(superset) [atguigu@hadoop102 ~]$ superset init

2.4 启动superset

步骤1:安装gunicorn

**说明:**gunicorn是一个Python Web Server,可以和java中的TomCat类比

(superset) [atguigu@hadoop102 ~]$ pip install gunicorn -i https://pypi.douban.com/simple/

image-20210112172740645

步骤2:启动superset

注意!确保当前conda环境为superset

  • –workers:指定进程个数
  • –timeout:worker进程超时时间,超时会自动重启
  • –bind:绑定本机地址,即为superset访问地址
  • –daemon:后台运行
(superset) [atguigu@hadoop102 ~]$ gunicorn --workers 5 --timeout 120 --bind hadoop102:8787  "superset.app:create_app()" --daemon 

步骤3:登录superset

访问http://hadoop102:8787

image-20210112173010026

步骤4:停止superset

①停掉superset进程

(superset) [atguigu@hadoop102 ~]$ ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9

②退出superset环境

(superset) [atguigu@hadoop102 ~]$ conda deactivate

2.5 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(){
        # 该段内容取自~/.bashrc,所用是进行conda初始化
        # >>> conda initialize >>>
        # !! Contents within this block are managed by 'conda init' !!
        __conda_setup="$('/opt/module/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
        if [ $? -eq 0 ]; then
            eval "$__conda_setup"
        else
            if [ -f "/opt/module/miniconda3/etc/profile.d/conda.sh" ]; then
                . "/opt/module/miniconda3/etc/profile.d/conda.sh"
            else
                export PATH="/opt/module/miniconda3/bin:$PATH"
            fi
        fi
        unset __conda_setup
        # <<< conda initialize <<<
        superset_status >/dev/null 2>&1
        if [[ $? -eq 0 ]]; then
            conda activate superset ; gunicorn --workers 5 --timeout 120 --bind hadoop102: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

3 Superset使用

3.1 对接MySQL数据库

步骤1:安装MySQL依赖

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

http://superset.apache.org/installation.html#database-dependencies

(superset) [atguigu@hadoop102 ~]$ conda install mysqlclient

步骤2:重启superset

(superset) [atguigu@hadoop102 ~]$ superset.sh restart

3.2 数据源配置

①数据库database配置

注:SQL Alchemy URI编写规范:mysql://账号:密码@IP/数据库名称

点击Test Connection,出现“Seems Ok!”提示即表示连接成功

image-20210112182556007

②表table配置

image-20210112182726852

3.3 制作仪表盘

①创建空白仪表盘

image-20210112204415175

②创建图表

image-20210112183302254

image-20210112204621613

image-20210112204719961

3.4 编辑仪表盘

image-20210112204745484

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

最佳第六六六人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值