Superset 数据可视化工具
Apache免费开源 易用 可对接多种数据源
由Python编写 使用了Flask框架
1. Superset 安装
-
准备工作
- 安装python3
# 此处使用miniconda安装python sh miniconda3xxx.sh source ~/.bashrc # 禁止激活默认环境 conda config --set auto_activate_base false
- 配置python环境
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main conda create --name superset python=3.7 conda activate superset conda deactivate
- 安装所需依赖
yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel pythonsetuptools openssl-devel cyrus-sasl-devel openldap-devel pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
-
安装Superset
pip install apache-superset -i https://pypi.douban.com/simple/
# 1.init db
superset db upgrade
# 2.set var
export FLASK_APP=superset
# 3.create admin
superset fab create-admin
# 4. init superset
superset init
- 安装gunicorn
由于Superset是一个python的web应用,所以需要安装一个Web容器
pip install gunicorn -i https://pypi.douban.com/simple/
启动 gunicorn
gunicorn --workers 5 --timeout 120 --bind hadoop102:9999 "superset.app:create_app()" --daemon
访问地址
http://hadoop102:9999
用户名和密码在创建admin的时候指定的值
# kill gunicorn
ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9
2. 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(){
superset_status >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
gunicorn --workers 5 --timeout 120 --bind hadoop102:9999 --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 使用
可以对接各类数据源,需要下载对应驱动,以mysql为例
conda install mysqlclient
# 重启superset
3.1 Superset 添加数据源
-
添加DataBases(MySQL Conn)
-
添加DataSets(Table)
3.2 Superset 制作仪表盘
- 折线图:需要配置metric
- 城市地图:需要配置metric
- 柱状图:需要配置series和metric
- 饼图:需要配置groupby 和metric