Superset安装配置及应用

目录

1. Superset应用场景

2. Superset安装

2.1 安装Python环境

2.2 安装Miniconda

2.3 创建Python3.6环境

2.4 安装Superset

2.5 启动Superset

3. Superset使用

3.1 对接MySQL数据源

3.2 数据源配置

3.3 制作仪表盘

 


Apache Superset是一个开源的、现代的、轻量级BI分析工具,能够对接多种数据源、拥有丰富的图标展示形式、支持自定义仪表盘,且拥有友好的用户界面,十分易用。

1. Superset应用场景

由于Superset能够对接常用的大数据分析工具,如Hive、Kylin、Druid等,且支持自定义仪表盘,故可作为数仓的可视化工具。

2. Superset安装

Superset官网地址:https://superset.apache.org/

2.1 安装Python环境

Superset是由Python语言编写的Web应用,要求Python3.6的环境。

2.2 安装Miniconda

conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同Python版本的软件包及其依赖,并能够在不同的Python环境之间切换,Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等,Miniconda包括Conda、Python。

2.2.1下载Miniconda(Python3版本)

下载地址:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

2.2.2 安装Miniconda

  • 将Miniconda3-latest-Linux-x86_64.sh上传到/opt/module/路径  (/opt/module/ 自己放文件的目录)

  • 执行以下命令进行安装,并按照提示操作,直到安装完成

bash Miniconda3-latest-Linux-x86_64.sh
  • 一直按回车键,直到出现Please answer 'yes' or 'no':

Please answer 'yes' or 'no':'
>>> yes
  • 在接下来出现>>> 是指定安装路径(根据用户需求指定):/opt/module/miniconda3

>>> /opt/module/miniconda3
  • 是否初始化Miniconda3,输入yes

Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
  • 出现以下字样,即为安装完成

Thank you for installing Miniconda3!

2.2.3 加载环境配置文件,使之生效

  • 配置环境变量

sudo vim /etc/profile.d/my_env.sh

添加如下内容

export CONDA_HOME=/opt/module/miniconda3
export PATH=$PATH:$CONDA_HOME/bin
  • source一下环境变量或者重启一下连接虚拟机的客户端

source /etc/profile.d/my_env.sh

2.2.4 取消激活base环境

Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。

conda config --set auto_activate_base false

2.3 创建Python3.6环境

2.3.1 配置conda国内镜像(清华)

#分别输入
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 config --set show_channel_urls yes

2.3.2 创建Python3.6环境

conda create --name superset python=3.6

说明:

  • conda环境管理常用命令
  • 创建环境:conda create -n env_name
  • 查看所有环境:conda info --envs
  • 删除一个环境:conda remove -n env_name --all

2.3.3 激活superset环境

conda activate superset

激活后效果如下图所示

说明: 退出当前环境:conda deactivate

2.3.4 执行python命令查看python版本

python

2.4 安装Superset

2.4.1 安装Superset依赖

#第一个
sudo yum install -y python-setuptools
#第二个
sudo yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel

2.4.2 安装(更新)setuptools和pip(豆瓣)

pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/

说明:pip是python的包管理工具,可以和centos中的yum类比

2.4.3 安装Supetset

ip install apache-superset -i https://pypi.douban.com/simple/

-i的作用是指定镜像,这里选择国内镜像(豆瓣)

2.4.4 初始化Supetset数据库(Supetset是一个web应用,自带数据库,需要初始化)

superset db upgrade

2.4.5 创建管理员用户(自定义)

flask fab create-admin
Username [admin]: hadoop
User first name [admin]: 
User last name [user]: 
Email [[email protected]]:
Password: ******
Repeat for confirmation:

2.4.6 Superset初始化

superset init

2.5 启动Superset

2.5.1 安装gunicorn

pip install gunicorn -i https://pypi.douban.com/simple/

2.5.2 启动Superset

确保当前conda环境为superset

gunicorn --workers 5 --timeout 120 --bind bigdata02:8787  "superset.app:create_app()" --daemon 

说明:

  • workers:指定进程个数
  • timeout:worker进程超时时间,超时会自动重启
  • bind:绑定本机地址,即为Superset访问地址
  • daemon:后台运行

2.5.3 停止superset

停掉gunicorn进程

ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9

退出superset环境 

conda deactivate

2.5.4 superset启停脚本

vim 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 bigdata02: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.sh start

2.5.5 登录Superset

访问 http://bigdata02:8787  使用之前创建的管理员账号密码

3. Superset使用

3.1 对接MySQL数据源

3.1.1 安装依赖

conda install mysqlclient

说明:对接不同的数据源,需安装不同的依赖,以下地址为官网说明:

http://superset.apache.org/installation.html#database-dependencies

3.1.2 重启superset

停掉gunicorn进程

ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9

启动

gunicorn -w 5 -t 120 -b bigdata02:8787 "superset.app:create_app()"

3.2 数据源配置

3.2.1 Database配置

  • 点击Sources/Databases
  • 点击

  • 点击填写Database及SQL Alchemy URI

注:SQL Alchemy URI编写规范:mysql://账号:密码@IP/数据库名称

  • 点击Test Connection,出现“Seems Ok!”提示即表示连接成功

  • 保存配置

3.2.2 Table配置

  • 点击Sources/Tables
  • 点击
  • 配置Table

3.3 制作仪表盘

3.3.1 创建空白仪表盘

  • 点击Dashboards
  • 点击
  • 配置仪表盘
  • 保存仪表盘

3.3.2 创建图表

  • 点击Charts
  • 点击
  • 选则数据源及图表类型

  • 选择何使的图表类型

  • 创建图表

  • 可修改语言为中文,方便

  • 按照说明配置图表

  • 点击“Run Query”

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

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/Poolweet_/article/details/109811118