ubuntu22.04安装superset
superset是个开源的BI工具,支持多种数据库,这里记录下两种安装方式,推荐容器部署
pypi部署
首先这里采用的系统是ubuntu22.04,我用ubuntu24.04没有安装成功
安装更新
apt update
安装依赖
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev python3-pip libsasl2-dev libldap2-dev default-libmysqlclient-dev
更新pip
sudo pip install --upgrade pip
下载虚拟环境包
sudo pip install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple
创建虚拟环境
virtualenv superset
激活虚拟环境
source superset/bin/activate
安装Superset
pip install apache-superset -i https://pypi.tuna.tsinghua.edu.cn/simple
初始化数据库
superset db upgrade
此时报错
解决办法:到/root/superset/lib/python3.10/site-packages/superset/执行该命令
又有报错
解决办法:到/root/superset/bin/下新建superset_config.py
# Superset specific config
ROW_LIMIT = 5000
#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`
#使用命令“openssl rand -base64 42”创建SECRET_KEY填写到下面
SECRET_KEY = 'jKnBkDKuvTIXI9L3Yi785j8/cNq+BOhppHrY7+A/2bwTW37OKk4ueiVN'
# 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_DATABASE_URI = 'sqlite:path/to/superset.db'
ENABLE_CSRF_PROTECTION = True
# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = True
WTF_CSRF_CHECK_DEFAULT = 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 * 365
#不填这个会出现登录界面输入正确的用户名和密码后登录无反应的现象
#但是关掉这个可能会降低安全性,可能是superset版本太新(3.0.0),旧版本貌似没有这个问题
TALISMAN_ENABLED=False
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
COMPRESS_REGISTER = False
#默认中文
BABEL_DEFAULT_LOCALE = "zh"
#superset支持的语言
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"},
}
SHOW_STACKTRACE = False
DEBUG = False
APP_NAME = "Superset"
#不填这个会导致报错如下
#ModuleNotFoundError: No module named 'MySQL_db'
SQLALCHEMY_TRACK_MODIFICATIONS = False
9 创建管理员
superset fab create-admin \
--username admin \
--firstname admin\
--lastname Admin \
--email admin@superset.com \
--password admin
10 初始化
superset init
11 安装gunicon
pip install gunicorn -i https://pypi.douban.com/simple/
12 启动superset
gunicorn --workers 5 --timeout 120 --bind 172.28.11.105:8088 "superset.app:create_app()" –daemon
停止superset命令:
ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9
13 编写脚本
vi 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(){
source ~/.bashrc
superset_status >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
source ~/superset/bin/activate ; gunicorn --workers 5 --timeout 120 --bind 172.28.11.105:8088 --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
14 增加执行权限
sudo chmod +x superset.sh
15 启动superset
./superset.sh start
停止superset
./superset.sh stop
安装数据库驱动
安装mysql数据库驱动
pip install mysqlclient -i https://pypi.tuna.tsinghua.edu.cn/simple
报错
解决办法:执行sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config
安装完驱动后,重启superset,重启后再添加数据库时就有mysql的选项了。后面试了sql server发现不行,暂时无解
容器部署
首先用容器部署会发生一个问题,就是用pip安装数据库驱动后,重启会消失,所以用以下写法可以解决这个问题
version: "2.4"
superset:
image: apache/superset:latest
privileged: true
container_name: superset
user: root
volumes:
- ./superset:/app/superset_home
- my-pip-cache:/root/.cache/pip
environment:
SUPERSET_SECRET_KEY=“oh-so-secret”
ports:
- 8088:8088
volumes:
my-pip-cache:
创建超级管理员
podman exec -it superset superset fab create-admin \
--username admin \
--firstname admin\
--lastname Admin \
--email admin@superset.com \
--password admin
初始化数据库
podman exec -it superset superset db upgrade
初始化supserset
podman exec -it superset superset init
安装mysql数据库驱动
podman exec -it superset /bin/bash
pip install mysqlclient -i https://pypi.tuna.tsinghua.edu.cn/simple
同样会报之前那个错
解决办法类似,执行下apt update,再执行sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config
License:
CC BY 4.0