网上大部分文档还是 Python2 的部署方式,尤其是汉化,坑还有不少,使用最新docker镜像重新整理了一下。
一、安装开源标准版: 能够访问互联网
(1)安装 docker
(2)下载官方 docker 镜像
docker pull apache/superset
(3)启动 docker 容器:
docker run -d -p 8080:8088 apache/superset
(4)初始化并启动系统系统(元数据库默认使用SQLITE)
docker exec -it -u root be1c60109292 flask fab create-admin
docker exec -it be1c60109292 superset db upgrade
docker exec -it be1c60109292 superset init
docker exec -it be1c60109292 superset run
http://127.0.0.1:8080 查看服务是否正常
(5)汉化
docker exec -it -u root be1c60109292 /bin/bash
sed -i "s/BABEL_DEFAULT_LOCALE = \"en/BABEL_DEFAULT_LOCALE = \"zh/g" superset/config.py
sed -i "s/LANGUAGES = {}/# LANGUAGES = {}/g" superset/config.py
apt-get update
apt-get install python3-babel
cd superset
pybabel compile -d translations
docker restart 567f18b60d9e
(6)解决导出csv文件汉字乱码问题
docker exec -it -u root be1c60109292 /bin/bash
sed -i "s/CSV_EXPORT = {\"encoding\": \"utf-8/CSV_EXPORT = {\"encoding\": \"gbk/g" superset/config.py
(7)查看/编辑后台的 sqlite 数据库
docker exec -it -u root be1c60109292 /bin/bash
apt-get install sqlite3
sqlite3 superset.db
.tables
.schema dbs
select sqlalchemy_uri from dbs;
(8)默认数据库从sqlite更改为mysql
docker exec -it -u root be1c60109292 /bin/bash
superset/config.py
SQLALCHEMY_DATABASE_URI = 'mysql://root:123456@192.168.150.17:3306/superset?charset=utf8'
# 细节参考[https://blog.csdn.net/xianhai_teng/article/details/118547112]
# 注意: 转义字符「 \ 」问题
(9)换 Logo
docker exec -it -u root be1c60109292 /bin/bash
cd /app/superset/static/assets/images
s.png favicon.png superset.png superset-logo-horiz.png
docker cp /Users/zhendong/Desktop/SuperSet_Logo be1c60109292:/app
cp -f SuperSet_Logo/* /app/superset/static/assets/images/
二、使用已有镜像:
(1)导出
docker commit be1c60109292 superset_szzz_220118
docker save -o ~/superset20220118.tar superset_szzz_220118
(2)导入
docker load -i superset20220118.tar
(3)重新运行
docker run --name superset_szzz_220118 -d -p 8080:8088 superset_szzz_220118
docker exec -it -u root 2c634cfddb6e /bin/bash
(4)迁移元数据库
1. SQLite 拷贝 superset.db 文件
2. MySQL 数据备份迁移,注意字符集(GBK -> UTF8)
三、本地MySQL作为测试数据源:
docker pull mysql:5.7 # 拉取 mysql 5.7
docker images
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7