1. Superset概述
Apache Superset是一个开源的、现代的、轻量级BI分析工具,能够对接多种数据源、拥有丰富的图标展示形式、支持自定义仪表盘,且拥有友好的用户界面,十分易用。
2.Superset应用场景
由于Superset能够对接常用的大数据分析工具,如Hive、Kylin、Druid等,且支持自定义仪表盘,故可作为数仓的可视化工具。
3.SuperSet的安装和使用
3.1 安装python环境
Superset是由Python语言编写的Web应用,要求Python3.6的环境。
3.1.1 安装Miniconda
conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同Python版本的软件包及其依赖,并能够在不同的Python环境之间切换,Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等,Miniconda包括Conda、Python。
此处,我们不需要如此多的工具包,只是用来管理不同版本的Python环境,故选择MiniConda。

1)下载Miniconda
链接:https://pan.baidu.com/s/1kqOzo4LsboT6_drWKPniYw
提取码:n9yh
2)安装Miniconda
① 将Miniconda3-latest-Linux-x86_64.sh上传到/opt/module/路径
② 执行以下命令进行安装,并按照提示操作,直到安装完成
[an@hadoop101 module]$ bash ./Miniconda3-latest-Linux-x86_64.sh
③ 一直按回车键,直到出现Please answer 'yes' or 'no':'
Please answer 'yes' or 'no':'
>>> yes
④ 指定安装路径(根据用户需求指定):/opt/module/miniconda3
[/home/an/miniconda3] >>> /opt/module/miniconda3
⑤ 是否初始化Miniconda3,输入yes
Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
⑥ 出现以下字样,即为安装完成
If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:
conda config --set auto_activate_base false
Thank you for installing Miniconda3!
3)加载环境变量配置文件,使之生效
① 配置环境变量
[an@hadoop101 module]$ sudo vim /etc/profile.d/my_env.sh
添加如下内容
export CONDA_HOME=/opt/module/miniconda3
export PATH=$PATH:$CONDA_HOME/bin
② source一下
[an@hadoop101 module]$ source /etc/profile.d/my_env.sh
4)取消激活base环境
Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。
[an@hadoop101 module]$ conda config --set auto_activate_base false
3.1.2 创建Python3.6环境
1)配置conda国内镜像(清华)
[an@hadoop101 module]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
[an@hadoop101 module]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[an@hadoop101 module]$ conda config --set show_channel_urls yes
2)创建Python3.6环境
执行命令之前,组好把shell窗口关闭,然后重新启动一下。要不可能出现安装超时。之后安装的时间会有一点长,耐心等待。即使安装出错,可以再次执行命令
[an@hadoop101 module]$ conda create --name superset python=3.6
说明:
- conda环境管理常用命令
- 创建环境:conda create -n env_name
- 查看所有环境:conda info --envs
- 删除一个环境:conda remove -n env_name --all
出现这样,就是安装成功了
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate superset
#
# To deactivate an active environment, use
#
# $ conda deactivate
3)激活效果如下
(superset) [an1@hadoop101 ~]$ python
Python 3.6.12 |Anaconda, Inc.| (default, Sep 8 2020, 23:10:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
3.2 Superset部署
3.2.1 安装Superset
1)安装Superset依赖
(superset) [an1@hadoop101 ~]$ sudo yum install -y python-setuptools
(superset) [an1@hadoop101 ~]$ 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(用豆瓣镜像)
(superset) [an1@hadoop101 ~]$ pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
说明:pip是python的包管理工具,可以和centos中的yum类比
3)安装Supetset
(superset) [an1@hadoop101 ~]$ pip install apache-superset -i https://pypi.douban.com/simple
4)初始化Supetset数据库(Supetset是一个web应用,自带数据库,需要初始化)
(superset) [an1@hadoop101 ~]$ superset db upgrade
这里可能会出现错误

这里由报错信息可以看出,没有 ‘dataclasses’模块,那么安装一下(缺少其他模块也可以这样安装)
(superset) [an1@hadoop101 ~]$ pip install dataclasses
5)创建管理员用户
(superset) [an1@hadoop101 ~]$ export FLASK_APP=superset
(superset) [an1@hadoop101 ~]$ flask fab create-admin
Username [admin]: an
User first name [admin]: an
User last name [user]: an
Email [admin@fab.org]:
Password:
Repeat for confirmation:
说明:flask是一个python web框架,Superset使用的就是flask
6)Superset初始化
(superset) [an1@hadoop101 ~]$ superset init
3.2.2 启动Supterset
1)安装gunicorn
(superset) [an1@hadoop101 ~]$ pip install gunicorn -i https://pypi.douban.com/simple/
2)启动Superset
第一步:确保当前conda环境为superset,及下图所示
(superset) [an1@hadoop101 ~]$
第二步:启动
(superset) [an1@hadoop101 ~]$ gunicorn --workers 5 --timeout 120 --bind alihadoop101:8787 "superset.app:create_app()" --daemon
说明:
- workers:指定进程个数
- timeout:worker进程超时时间,超时会自动重启
- bind:绑定本机地址,即为Superset访问地址
- daemon:后台运行
安装成功,查看相对应的进程
(superset) [an1@hadoop101 /]$ ps -ef | grep gunicorn

停掉gunicorn进程
ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9
退出superset环境
conda deactivate
3)superset启停脚本
(superset) [an1@hadoop101 sbin]$ pwd
/usr/local/sbin
(superset) [an1@hadoop101 sbin]$ vim superset.sh
① 创建superset.sh文件
#!/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 alihadoop101: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) [an1@hadoop101 sbin]$ sudo chmod +x superset.sh
③ 测试

4)登录Superset
访问http://alihadoop101:8787,并使用3.2.1节中第5步创建的管理员账号进行登录。
例如:用户名:an 密码:123456

4. Superset使用
4.1 对接MySQL数据源
4.1.1 安装依赖
1)安装连接MySQL数据源的依赖
superset) [an1@hadoop101 sbin]$ conda install mysqlclient
说明:对接不同的数据源,需安装不同的依赖,以下地址为官网说明
https://superset.apache.org/docs/databases/installing-database-drivers
2)重启Superset
[an1@hadoop101 ~]$ superset.sh restart
4.1.2 数据源配置
1)Database配置
(1)点击Sources/Databases

(2)点击+

(3)点击填写Database及SQL Alchemy URI
测试数据:
链接:https://pan.baidu.com/s/1kMVYOPpH2jjsgZyhKMcJpg
提取码:3n4b 
(4)点击Test Connection,出现“Seems Ok!”提示即表示连接成功

(5)保存配置

2)Table配置
(1)点击DataSource/DataSets,我这里的版本很奇怪,所以要点DataSets

(2)点击+

(3)选择表,之后save

4.1.3 创建空白仪表盘
这里只输入仪表盘的名字即可

4.1.4 创建图表
1)点击Charts/+

2)选则数据源及图表类型

3)选择何使的图表类型,选择之后点击create

4)可修改语言为中文,方便配置

5)按照说明配置图表,配置好之后点击Run

6)保存图表,并将其添加到仪表盘

7)看板

807

被折叠的 条评论
为什么被折叠?



