SuperSet服务安装

本文涉及的产品
实时计算 Flink 版,5000CU*H 3个月
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
大数据开发治理平台 DataWorks,不限时长
简介: 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/

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
Unix Linux Apache
离线安装Superset 0.37(截图详细版)
上文提到了Superset 0.37的在线安装方式,只需要更新pip,然后pip install就可以了。但是在生产环境中,特别是内网环境中,很多时候是没有外网的,这时候就需要采取离线安装的方式。 本文将详细介绍在Linux系统中离线安装Superset的全过程,并整理了安装过程中遇到的错误。
839 0
离线安装Superset 0.37(截图详细版)
|
数据可视化 大数据 数据挖掘
Apache Superset 1.2.0教程 (一)—— 安装(Windows版)
Apache Superset 是一款由 Airbnb 开源的“现代化的企业级 BI(商业智能) Web 应用程序”,其通过创建和分享 dashboard,为数据分析提供了轻量级的数据查询和可视化方案。 近日推出了全新的 1.2.0版本,本教程也就从头开始讲解Apache Superset的使用。
1586 0
Apache Superset 1.2.0教程 (一)—— 安装(Windows版)
|
关系型数据库 MySQL Linux
airflow安装教程(local模式)
airflow安装教程(local模式)
airflow安装教程(local模式)
Zeppelin安装与配置
本文介绍zeppelin安装与配置指南
Zeppelin安装与配置
|
15天前
|
存储 数据安全/隐私保护 Docker
Airflow安装
Airflow安装
17 0
|
3月前
|
分布式计算 Hadoop 关系型数据库
Sqoop入门指南:安装和配置
Sqoop入门指南:安装和配置
|
数据可视化 数据挖掘 BI
Windows系统快速安装Superset 0.37
Windows系统快速安装Superset 0.37
234 0
Windows系统快速安装Superset 0.37
|
Kubernetes Java 数据库连接
TDengine安装,python客户端测试,接入DBeaver
最近在看TDengine数据库,思考如何和我们的边缘集群结合在一起使用,本文结构是: 服务端:ubuntu18系统,通过deb文件安装TDengine数据库,主机IP 192.168.0.13,使用默认用户名密码 客户端:容器运行,python客户端,可以运行在另外一台机器或者K8S集群里 图形化工具:使用Dbeaver添加jdbc驱动,在图形化工具里使用TDengine
1413 1
TDengine安装,python客户端测试,接入DBeaver
安装 OushuDB Ambari 插件
我们假设用户已经安装了HDP Ambari,并且已经安装了HDFS和Zookeeper。安装步骤可以参考: ● https://docs.hortonworks.com/HDPDocuments/Ambari/Ambari-2.4.2.0/index.html ● https://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.5.3/index.html
138 0
安装 OushuDB Ambari 插件
|
Python Windows
记一次win server 2012的离线python环境安装(包括whl和setup.py)
目录 前言 python3 exe安装 pip whl安装 setup.py安装 最后 前言 总有某些公司是offline的, 你懂的, 然后用着古老的服务器. 所有有了这种奇怪的需求. 这里分成三个部分来说, 首先是py3的离线安装, 就是大家熟悉的exe安装.
6018 0