大数据可视化技术之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。
-
下载Miniconda(Python3版本)
下载地址:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
-
安装Miniconda
-
执行以下命令进行安装,并按照提示操作,直到安装完成
[root@localhost ~]# sh Miniconda3-latest-Linux-x86_64.sh
-
出现以下界面按
enter
键 -
进入阅读协议界面,然后按空格键,之后输入
yes
同意协议 -
选择安装路径
/opt/module/miniconda3
-
输入yes,进行初始化
-
安装成功
-
加载环境变量配置文件,使之生效
[root@localhost ~]# source ~/.bashrc
-
取消激活base环境
Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。
(base) [root@localhost ~]# conda config --set auto_activate_base false
执行完成后,重新连接就不会有
base
了
-
2.1.2、创建Python3.6的环境
-
配置
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
-
创建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部署
-
激活superset环境
[root@localhost ~]# conda activate superset (superset) [root@localhost ~]#
-
安装依赖
(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
-
安装(更新)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
-
安装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
-
初始化Superset数据库
(superset) [root@localhost ~]# superset db upgrade
-
创建管理员用户
(superset) [root@localhost ~]# export FLASK_APP=superset (superset) [root@localhost ~]# superset fab create-admin
-
Superset初始化
(superset) [root@localhost ~]# superset init
-
启动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://用户名:密码@主机名:端口号/数据库名称
测试连接成功后保存,保存按钮再最下面