Superset安装

Superset的安装官网上也有比较详细的步骤,参考官方文档。不想踩坑当然推荐还是用docker方式,当然因为Superset本身是用python实现的,对于Python开发者来说,用pypi部署也不是难事,也是一个学习机会。

本文主要是整理了下我部署过程的资料,以供借鉴。

核心步骤不难,主要是各个组件部署在不同的linux环境中,会踩到很多系统组件&动态链接库缺失的问题。

创建Python虚拟环境

我们是在单个机器上部署多个Python服务,所以需要做依赖包的隔离,这里我们采用来管理Python环境。Pyenv:Pyenv安装指引

bash 复制代码
# 安装Python
pyenv install 3.10.14
# 创建虚拟环境
pyenv virtualenv 3.10.14 superset-env
# 激活superset专用python环境
pyenv activate superset-env

安装Superset相关组件

bash 复制代码
# 安装superset本尊
pip install apache-superset
# 安装superset元数据库的连接驱动,如果是mysql
# if failed mysqlclient, then:
# sudo yum install -y python3-devel mysql-devel mysql-server
# 如果都无法解决,试试降级安装pip install mysqlclient==2.1.1
pip install mysqlclient

Superset初始化

编辑初始化配置

先把配置文件写到superset_config.py文件里,后面初始化时会用到这个文件的配置

python 复制代码
from celery.schedules import crontab

# Superset specific config
ROW_LIMIT = 10000

# 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.
# Alternatively you can set it with `SUPERSET_SECRET_KEY` environment variable.
# You MUST set this for production environments or the server will refuse
# to start and you will see an error in the logs accordingly.
SECRET_KEY = ''

# 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
# The check_same_thread=false property ensures the sqlite client does not attempt
# to enforce single-threaded access, which may be problematic in some edge cases
SQLALCHEMY_DATABASE_URI = ''

# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = True
# Add endpoints that need to be exempt from CSRF protection
WTF_CSRF_EXEMPT_LIST = []
# A CSRF token that expires in 1 year
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 1

# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''

# activate Jinja templating
FEATURE_FLAGS = {
  "ENABLE_TEMPLATE_PROCESSING": True,
  "ALERT_REPORTS": True
}

引用初始化配置文件

bash 复制代码
export SUPERSET_CONFIG_PATH=superset_config.py
export FLASK_APP=superset

初始化数据库和元数据

bash 复制代码
# Then, you need to initialize the database:
superset db upgrade
# Create an admin user in your metadata database (use `admin` as username to be able to load the examples)
superset fab create-admin
# Load some data to play with
superset load_examples
# Create default roles and permissions
superset init

启动服务

接下来就可以直接启动服务了,以下我整理的启停脚本:

bash 复制代码
#!/bin/bash
# superset_start.sh
pyenv activate superset-env
export SUPERSET_CONFIG_PATH=superset_config.py
export FLASK_APP=superset

function start() {
  python -m gunicorn --workers 2 --timeout 120 --bind 0.0.0.0:8088 "superset.app:create_app()" --daemon

}

function stop() {
  local name="superset.app"
  pid=$(pgrep -f $name)
  if [ -z "$pid" ]; then
    echo "$ENV $name is not running"
  else
    echo "Stopping $ENV $name, pid=$pid"
    kill $pid
    sleep 3
  fi
}

case $1 in
  start)
    start
  ;;
  stop)
    stop
  ;;
  restart)
    stop
    start
  ;;
  check)
    ps -ef |grep superset.app
  ;;
  *)
    echo "Usage: $0 {start|stop|restart|check}"
esac
相关推荐
算法小白(真小白)2 小时前
低代码软件搭建自学第二天——构建拖拽功能
python·低代码·pyqt
唐小旭2 小时前
服务器建立-错误:pyenv环境建立后python版本不对
运维·服务器·python
007php0072 小时前
Go语言zero项目部署后启动失败问题分析与解决
java·服务器·网络·python·golang·php·ai编程
Chinese Red Guest2 小时前
python
开发语言·python·pygame
骑个小蜗牛3 小时前
Python 标准库:string——字符串操作
python
黄公子学安全5 小时前
Java的基础概念(一)
java·开发语言·python
程序员一诺5 小时前
【Python使用】嘿马python高级进阶全体系教程第10篇:静态Web服务器-返回固定页面数据,1. 开发自己的静态Web服务器【附代码文档】
后端·python
小木_.6 小时前
【Python 图片下载器】一款专门为爬虫制作的图片下载器,多线程下载,速度快,支持续传/图片缩放/图片压缩/图片转换
爬虫·python·学习·分享·批量下载·图片下载器
Jiude6 小时前
算法题题解记录——双变量问题的 “枚举右,维护左”
python·算法·面试