Apache Superset是一个现代的数据探索和可视化平台。它功能强大且十分易用,可对接各种数据源,包括很多现代的大数据分析引擎,拥有丰富的图表展示形式,并且支持自定义仪表盘。
本案例使用的服务器操作系统为CentOS 7,Superset对接的数据源为MySQL数据库。
Superset官网地址:http://superset.apache.org/
Superset是由Python语言编写的Web应用,要求Python3.7的环境。
conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同Python版本的软件包及其依赖,并能够在不同的Python环境之间切换,Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等,Miniconda包括Conda、Python,在此处,不需要如此多的工具包,故选择MiniConda。
下载地址:
[song@hadoop102 lib]$ bash Miniconda3-latest-Linux-x86_64.sh
[song@hadoop102 lib]$ source ~/.bashrc
Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。
[song@hadoop102 lib]$ conda config --set auto_activate_base false
[song@hadoop102 ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
[song@hadoop102 ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[song@hadoop102 ~]$ conda config --set show_channel_urls yes
[atguigu@hadoop102 ~]$ conda create --name superset python=3.7
[song@hadoop102 ~]$ conda activate superset
(superset) [song@hadoop102 ~]$ conda deactivate
安装Superset之前,需安装以下所需依赖。
(superset) [song@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
(superset) [song@hadoop102 ~]$ pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
说明:pip是python的包管理工具,可以和centos中的yum类比。
(superset) [song@hadoop102 ~]$ pip install apache-superset -i https://pypi.douban.com/simple/
说明:-i的作用是指定镜像,这里选择国内镜像。
注:如果遇到网络错误导致不能下载,可尝试更换镜像。
(superset) [song@hadoop102 ~]$ pip install apache-superset --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple
(superset) [song@hadoop102 ~]$ superset db upgrade
如果初始化数据库报错如下。
则执行如下命令,将markupsafe依赖的版本回退到 2.0.1。
(superset) [song@hadoop102 ~]$ pip install --force-reinstall MarkupSafe==2.0.1
创建管理员用户
(superset) [song@hadoop102 ~]$ export FLASK_APP=superset
(superset) [song@hadoop102 ~]$ superset fab create-admin
说明:flask是一个python web框架,Superset使用的就是flask,会在此创建用户名、密码
(superset) [song@hadoop102 ~]$ superset init
(superset) [song@hadoop102 ~]$ pip install gunicorn -i https://pypi.douban.com/simple/
gunicorn是一个Python Web Server,可以和java中的TomCat类比。
(superset) [song@hadoop102 ~]$ gunicorn --workers 5 --timeout 120 --bind hadoop102:8787 "superset.app:create_app()" --daemon
停掉gunicorn进程。
(superset) [song@hadoop102 ~]$ ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9
退出superset环境。
(superset) [song@hadoop102 ~]$ conda deactivate
#!/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
chmod +x superset.sh
(superset) [atguigu@hadoop102 ~]$ conda install mysqlclient
说明:对接不同的数据源,需安装不同的依赖,以下地址为官网说明。
https://superset.apache.org/docs/databases/installing-database-drivers
(superset) [atguigu@hadoop102 ~]$ superset.sh restart
注:SQL Alchemy URI编写规范:mysql://用户名:密码@主机名:端口号/数据库名称。
此处填写:
mysql://root:000000@hadoop102:3306/gmall_report?charset=utf8