目录
一、Superset入门
1、Superset概述
Apache Superset是一个开源的、现代的、轻量级BI分析工具,能够对接多种数据源、拥有丰富的图表展示形式、支持自定义仪表盘,且拥有友好的用户界面,十分易用。
2、Superset应用场景
由于Superset能够对接常用的大数据分析工具,如Hive、Kylin、Druid等,且支持自定义仪表盘,故可作为数仓的可视化工具。
二、Superset安装及使用
Superset官网地址:http://superset.apache.org/
1、安装Python环境
Superset是由Python语言编写的Web应用,要求Python3.7的环境。
1.1 安装Miniconda
conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同Python版本的软件包及其依赖,并能够在不同的Python环境之间切换,Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等,Miniconda包括Conda、Python。
此处,我们不需要如此多的工具包,故选择MiniConda。
2、Superset部署
2.1 安装依赖
安装Superset之前,需安装以下所需依赖
(superset) [atguigu@hadoop102 ~]$ sudo yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel
2.2 安装Superset
1)安装(更新)setuptools和pip
(superset) [atguigu@hadoop102 ~]$ pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
说明:pip是python的包管理工具,可以和centos中的yum类比
2)安装Supetset
(superset) [atguigu@hadoop102 ~]$ pip install apache-superset -i https://pypi.douban.com/simple/
说明:-i的作用是指定镜像,这里选择国内镜像
注:如果遇到网络错误导致不能下载,可尝试更换镜像
(superset) [atguigu@hadoop102 ~]$ pip install apache-superset --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple
3)初始化Supetset数据库
(superset) [atguigu@hadoop102 ~]$ superset db upgrade
4)创建管理员用户
(superset) [atguigu@hadoop102 ~]$ export FLASK_APP=superset
(superset) [atguigu@hadoop102 ~]$ superset fab create-admin
说明:flask是一个python web框架,Superset使用的就是flask
5)Superset初始化
superset) [atguigu@hadoop102 ~]$ superset init
这里不知道为啥python3.7 3.8 3.9不断会报错,因此这里调成了pthon3.6
2.3 启动Supterset
2.4 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 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
三、Superset使用
1、对接MySQL数据源
1.1 安装依赖
1.2 重启Superset
(superset) [atguigu@hadoop102 ~]$ superset.sh restart
1.3 数据源配置
2、制作仪表盘
2.1 创建空白仪表盘
2.2 创建图表
2.3 编辑仪表盘
四、Superser实战
1、制作地图
2、制作饼状图