SuperSet服务安装

简介: SuperSet服务安装

Superset概述

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

Superset应用场景

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

Superset安装及使用

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

Superset文档地址:https://superset.apache.org/docs/intro

安装Python环境

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

安装Miniconda

因为目前我们服务器 Python默认版本都是2.x,我们需要一个独立环境安装3.7供Superset使用,conda是一个比较好的选择。

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

其他版本可以查看:https://repo.anaconda.com/miniconda/

安装Miniconda

执行安装脚本

sh Miniconda3-latest-Linux-x86_64.sh

按回车继续

Welcome to Miniconda3 py39_4.11.0

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

空格翻阅安装条款

image-20220318105754177

同意条款,输入yes

Do you accept the license terms? [yes|no]
[no] >>>

输入安装目录

Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>>

运行初始化conda,输入yes

installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>>

取消每次登陆自动激活conda base环境

现在每次登陆该服务器会自动自动进入base环境

image-20220318110258659

刚刚在安装完成时会提示下面一句话

If you'd prefer that conda's base environment not be activated on startup, 
   set the auto_activate_base parameter to false: 

conda config --set auto_activate_base false

我们执行conda config --set auto_activate_base false就是取消自动进入

[root@r-wb-18 software]# conda config --set auto_activate_base false
-bash: conda: 未找到命令

如果提示未找到,我们引用一下环境变量即可 source ~/.bashrc

创建Python3.7(Superset)环境

配置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

创建Superset环境

conda create --name superset python=3.7
或者使用--channel指定国内源
conda create --name superset python=3.8 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

遇到需要安装组件同意安装

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

安装完成提示:

#
# To activate this environment, use
#
#     $ conda activate superset
#
# To deactivate an active environment, use
#
#     $ conda deactivate

conda activate superset 进入我们创建的superset环境

conda deactivate退出

激活Superset环境

conda activate superset

激活后效果如下

[root@r-wb-18 ~]# conda activate superset
(superset) [root@r-wb-18 ~]#

退出Superset环境

conda deactivate

查看python版本

(superset) [root@r-wb-18 ~]# python
Python 3.7.11 (default, Jul 27 2021, 14:32:16) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Superset部署

注意:执行部署前需要进入我们刚刚创建的环境conda activate superset

安装依赖

安装Superset之前,需安装以下所需依赖

yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel

安装Superset

  1. 安装(更新)setuptoolspip

    pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
    
  2. 安装Superset

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

    说明:-i 的作用是指定镜像,这里选择国内镜像

    注:如果遇到网络错误导致不能下载,可尝试更换镜像

    pip install apache-superset --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple
    
  3. 初始化Superset数据库

    superset db upgrade
    

可能遇到的异常

  1. 异常1:

    ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/opt/software/miniconda3/envs/superset/lib/python3.7/site-packages/markupsafe/__init__.py)
    

    解决方法:

    执行python -m pip install markupsafe==2.0.1后重新执行superset db upgrade

    参考:https://github.com/pallets/markupsafe/issues/284

  2. 异常2:

    AttributeError: module 'sqlparse.keywords' has no attribute 'FLAGS'
    

    降低版本

    pip install sqlparse=='0.4.3' -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
    
  3. 异常3:

    Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
    

    执行

    export FLASK_APP=superset
    

    并在环境变量中添加

    vim /etc/profile
    
    export FLASK_APP=superset
    
  4. 异常4

    --------------------------------------------------------------------------------
                                        WARNING
    --------------------------------------------------------------------------------
    A Default SECRET_KEY was detected, please use superset_config.py to override it.
    Use a strong complex alphanumeric string and use a tool to help you generate 
    a sufficiently random sequence, ex: openssl rand -base64 42
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    Refusing to start due to insecure SECRET_KEY
    

解决方法:

随便在一个目录下。输入vim superset_config.py增加配置文件

(注意!!! superset_config.py文件原先是没有的,得自己创建)

在superset_config.py文件下添加以下内容

# Superset specific config
# SS 相关的配置
# 行数限制 5000 行
ROW_LIMIT = 5000

# 网站服务器端口 8088,该端口被Hadoop占用,改为其他端口比如18088
SUPERSET_WEBSERVER_PORT = 8088

# Flask App Builder configuration
# Your App secret key will be used for securely signing the session cookie
# and encrypting sensitive information on the database
# Make sure you are changing this key for your deployment with a strong key.
# You can generate a strong key using `openssl rand -base64 42`
# Flask 应用构建器配置
# 应用密钥用来保护会话 cookie 的安全签名
# 并且用来加密数据库中的敏感信息
# 请确保在你的部署环境选择一个强密钥
# 可以使用命令 openssl rand -base64 42 来生成一个强密钥

SECRET_KEY = "ZT2uRVAMPKpVkHM/QA1QiQlMuUgAi7LLo160AHA99aihEjp03m1HR6Kg" 

# The SQLAlchemy connection string to your database backend
# This connection defines the path to the database that stores your
# superset metadata (slices, connections, tables, dashboards, ...).
# Note that the connection information to connect to the datasources
# you want to explore are managed directly in the web UI
# SQLAlchemy 数据库连接信息
# 这个连接信息定义了 SS 元数据库的路径(切片、连接、表、数据面板等等)
# 注意:需要探索的数据源连接及数据库连接直接通过网页界面进行管理
#SQLALCHEMY_DATABASE_URI = 'sqlite:path/to/superset.db'

# Flask-WTF flag for CSRF
# 跨域请求攻击标识
WTF_CSRF_ENABLED = True

# Add endpoints that need to be exempt from CSRF protection
# CSRF 白名单
WTF_CSRF_EXEMPT_LIST = []

# A CSRF token that expires in 1 year
# CSFR 令牌过期时间 1 年
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365

# Set this API key to enable Mapbox visualizations
# 接口密钥用来启用 Mapbox 可视化
MAPBOX_API_KEY = ''

添加之后,在/etc/profile 文件中加入以下命令:,然后生效以下配置或者重启一下大数据环境即可

export SUPERSET_CONFIG_PATH=/app/superset_config.py

添加后source /etc/profile刷新一下环境变量

  1. 异常5:
ModuleNotFoundError: No module named 'marshmallow_enum'

解决方法

pip install marshmallow_enum -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

参考:https://blog.csdn.net/m0_58195451/article/details/134148085

创建管理员用户

superset fab create-admin

说明:flask是一个python web框架,Superset使用的就是flask

添加创建账号信息

2022-03-18 11:22:47,189:INFO:superset.utils.screenshots:No PIL installation found
Username [admin]: jast
User first name [admin]: jast
User last name [user]: zhang
Email [admin@fab.org]: xxx@foxmail.com
Password: 
Repeat for confirmation: 
Recognized Database Authentications.
Admin User jast created.

Superset初始化

superset init

启动Superset

  1. 安装gunicorn

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

    说明:gunicorn是一个Python Web Server,可以和java中的TomCat类比

  2. 启动Superset

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

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

  3. 登录Superset

    访问http://192.168.60.18:18888,使用我们刚刚创建的管理员用户登录

    image-20220318112850832

    image-20220318112914988

  4. 停止Superset

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

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.60.18: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使用

MySQL数据源

安装MySQL依赖

conda install mysqlclient

说明:对接不同的数据源,需安装不同的依赖,以下地址为官网说明
https://superset.apache.org/docs/databases/installing-database-drivers

官方介绍是使用的pip方法安装,我们替换成conda防止兼容性产生;官方说明:pip install mysqlclient;

数据库连接方法:mysql://<UserName>:<DBPassword>@<Database Host>/<Database Name>

image-20220318135836673

重启Superset

superset restart

MySQL数据源配置

Database 配置

  1. 点击Data->Databases

    image-20220318140332597

  2. 点击添加数据源

    image-20220318142106729

  3. 填写数据库 连接信息

    image-20220318142409731

  4. 创建成功

    image-20220318142654475

Table配置

  1. Data -> Datasets

    image-20220318142819129

  2. 点击 DATASET

    image-20220318142856012

  3. 选择表

    image-20220318143000108

    image-20220318143014906

创建图表

  1. 点击Charts -> CHART

    image-20220318143413521

  2. 选择表和需要展示的图

    image-20220318143614709

  3. 配置统计说明

    image-20220318145038759

    image-20220318150003897

  4. 保存

    image-20220318145131682

    image-20220318145141735

创建仪表盘

  1. Dashboards -> DASHBOARDS

    image-20220318145232247

  2. 托拉拽设置仪表盘

    image-20220318145441362

  3. 将图标拖到展示区域

    image-20220318145524351

  4. 查看结果

    image-20220318145607613

使用SQL查询后以表格形式展示

  1. SQL Lab -> SQL Editor

    image-20220318151059156

  2. 查询SQL,点击EXPLORE,并跳转到Charts

    image-20220318151936938

  3. 保存查询,并自定义命名

    image-20220318152057174

  4. 直接导出了Charts并设置好了字段,我们可以在此基础上进行修改

    image-20220318152244359

  5. 保存为Charts

    image-20220318152527747

  6. 在仪表盘添加Charts image-20220318152741893

  7. 查看结果

    image-20220318152939714

  8. 中文表头设置

    也可以在查询sql时指定中文表明,在展示时候就自动显示成别名了

    image-20220318153326902

系统嵌入

https://www.shuzhiduo.com/A/obzbQP1ydE/

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
SQL API 索引
Superset对接ElasticSearch服务展示
Superset对接ElasticSearch服务展示
1064 2
|
SQL 数据可视化 关系型数据库
【大数据】可视化仪表板 - Superset的安装和使用
【大数据】可视化仪表板 - Superset的安装和使用
2303 0
|
数据可视化 大数据 数据挖掘
Apache Superset 1.2.0教程 (一)—— 安装(Windows版)
Apache Superset 是一款由 Airbnb 开源的“现代化的企业级 BI(商业智能) Web 应用程序”,其通过创建和分享 dashboard,为数据分析提供了轻量级的数据查询和可视化方案。 近日推出了全新的 1.2.0版本,本教程也就从头开始讲解Apache Superset的使用。
2948 0
Apache Superset 1.2.0教程 (一)—— 安装(Windows版)
|
Unix Linux Apache
离线安装Superset 0.37(截图详细版)
上文提到了Superset 0.37的在线安装方式,只需要更新pip,然后pip install就可以了。但是在生产环境中,特别是内网环境中,很多时候是没有外网的,这时候就需要采取离线安装的方式。 本文将详细介绍在Linux系统中离线安装Superset的全过程,并整理了安装过程中遇到的错误。
1440 0
离线安装Superset 0.37(截图详细版)
|
10月前
|
人工智能 自然语言处理 知识图谱
Yuxi-Know:开源智能问答系统,基于大模型RAG与知识图谱技术快速构建知识库
Yuxi-Know是一个结合大模型RAG知识库与知识图谱技术的智能问答平台,支持多格式文档处理和复杂知识关系查询,具备多模型适配和智能体拓展能力。
2633 55
Yuxi-Know:开源智能问答系统,基于大模型RAG与知识图谱技术快速构建知识库
|
数据挖掘 Apache 数据安全/隐私保护
使用Docker部署Apache Superset并实现公网远程访问
使用Docker部署Apache Superset并实现公网远程访问
1854 0
|
消息中间件 SQL 监控
ETL的灵魂:调度系统
ETL的灵魂:调度系统
3083 1
|
SQL Java 大数据
5款开源BI工具优缺点及介绍
【4月更文挑战第15天】对比了几款开源BI报表工具:Superset以其高性能和高度可定制化受青睐,适合复杂分析;Metabase以其简洁易用和广泛兼容性脱颖而出,适合快速构建报表;DataEase以其轻量级和易部署特点吸引中小型企业;JasperReports擅长复杂报表生成,适合Java环境;Pentaho CE则是一体化平台,适合需要全面企业级功能的用户。选择时应结合公司需求、技术背景和数据规模来决定。
5686 6
|
SQL 分布式计算 Apache
Apache Superset
Apache Superset
|
数据可视化 Linux Apache
CentOS部署Apache Superset大数据可视化BI分析工具并实现无公网IP远程访问
CentOS部署Apache Superset大数据可视化BI分析工具并实现无公网IP远程访问