Superset--基础--02--部署

Superset–基础–02–部署


1、环境

软件版本备注
Python3.10.16Superset是由 Python写的
condaMiniconda3-latest-Linux-x86_64.sh
Superset4.1.1

2、安装conda

参考

python--基础--1.6--conda
	5.1、安装
	5.2、操作

2.1、安装

# 下载执行脚本
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# 执行
bash Miniconda3-latest-Linux-x86_64.sh

# 安装路径
/opt/module/miniconda3

# 禁止激活默认base环境
conda config --set auto_activate_base false


# 配置国内镜像源(这个可能有问题)
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 --remove-key channels
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes


# 激活配置
source ~/.bashrc

2.2、创建环境

#创建环境,环境名称 superset,python版本3.10
conda create --name superset python=3.10
 
# 查看所有环境。
conda info --envs

# 激活superset环境
# conda activate superset

3、Superset部署

3.1、部署


# 安装依赖
[root@zhoufei ~]# yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel

# 激活superset环境
[root@zhoufei ~]# conda activate superset


# 安装 superset,指定版本和镜像源
#pip install apache-superset==4.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
(suppert) [root@zhoufei ~]# pip install apache-superset -i https://pypi.tuna.tsinghua.edu.cn/simple/

 
# 在虚拟环境superset的bin目录下,新建文件vim superset_config.py ,添加内容以下
cat > /opt/module/miniconda3/envs/superset/bin/superset_config.py << EOF

#Superset specific config
# SS 相关的配置
# 行数限制 5000 行
ROW_LIMIT = 5000
  
# 网站服务器端口 8088
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 = 'vWAo59TJiEMBp7R2bzwNp+aBxICP6cn041qDNGDtpKGkqGj1qvgn5PDt'
  
# 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 = ''


# 设置默认语言为中文
BABEL_DEFAULT_LOCALE = "zh"
# 指定翻译文件路径
BABEL_DEFAULT_FOLDER = "superset/translations"
# 支持的语言列表
LANGUAGES = {
    "en": {"flag": "us", "name": "English"},
    "es": {"flag": "es", "name": "Spanish"},
    "it": {"flag": "it", "name": "Italian"},
    "fr": {"flag": "fr", "name": "French"},
    "zh": {"flag": "cn", "name": "Chinese"},
    "ja": {"flag": "jp", "name": "Japanese"},
    "de": {"flag": "de", "name": "German"},
    "pt": {"flag": "pt", "name": "Portuguese"},
    "pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
    "ru": {"flag": "ru", "name": "Russian"},
    "ko": {"flag": "kr", "name": "Korean"},
    "sk": {"flag": "sk", "name": "Slovak"},
    "sl": {"flag": "si", "name": "Slovenian"},
    "nl": {"flag": "nl", "name": "Dutch"},
}
# Turning off i18n by default as translation in most languages are
# incomplete and not well maintained.
EOF


# 设置 FLASK_APP 环境变量
# 在初始化之前,需要设置环境变量,flask是一个python web框架,Superset使用的就是flask
(suppert) [root@zhoufei ~]# export FLASK_APP=superset

# 初始化数据库:
(suppert) [root@zhoufei ~]# superset db upgrade

# 创建管理员用户
(superset) [root@zhoufei bin]# superset fab create-admin
    Loaded your LOCAL configuration at [/opt/module/miniconda3/envs/superset/bin/superset_config.py]
    2025-03-24 07:36:21,871:INFO:superset.utils.screenshots:No PIL installation found
    2025-03-24 07:36:22,474:INFO:superset.utils.pdf:No PIL installation found
    Username [admin]: admin
    User first name [admin]: 
    User last name [user]: 
    Email [admin@fab.org]: 
    Password: 
    Repeat for confirmation: 
    Recognized Database Authentications.
    Admin User admin created
    
# superset 初始化
(superset) [root@zhoufei bin]# superset init

# 安装 gunicorn
(superset) [root@zhoufei bin]# pip install gunicorn -i https://pypi.tuna.tsinghua.edu.cn/simple

# 启动命令
(superset) [root@zhoufei bin]# gunicorn --workers 5 --timeout 120 --bind 0.0.0.0:8038 --daemon 'superset.app:create_app()'

--works:指线程数
--timeout:worker 进程超时时间,超时会自动重启
--bind:绑定本机地址,即Superset访问地址。这里绑定的地址需要设置为:0.0.0.0:8088,这样将会使gunicorn监听在所有网络接口上,而不仅仅是localhost。
--daemon:后台运行

# 停止命令
# (superset) [root@zhoufei bin]# ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9
# (superset) [root@zhoufei bin]# conda deactivate

3.2、启停脚本

vim  /opt/superset.sh

内容如下

#!/bin/bash

superset_status(){
    result=`ps -ef | awk '/superset.app:create_app()/ && !/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 0.0.0.0:8038 --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 /opt/superset.sh
# 启动
 /opt/superset.sh start
# 停止
 /opt/superset.sh stop

4、对接数据源

对接数据源,需要执行初始化数据源客户端的操作,具体命令看文档

4.1、文档

https://superset.apache.org/docs/configuration/databases/#installing-database-drivers

在这里插入图片描述

4.2、对接MySQL数据源

# 安装客户端
(superset) [root@zhoufei opt]# conda install mysqlclient

#重启Superset
 /opt/superset.sh restart

5、测试

http://192.168.187.89:8038/
admin/admin

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值