官方文档
Python版本
Superset is tested against Python 2.7 and Python 3.4. Airbnb currently uses 2.7.* in production. We do not plan on supporting Python 2.6.
云原生 Cloud-native
Superset is designed to be highly available. It is “cloud-native” as it has been designed scale out in large, distributed environments, and works well inside containers. While you can easily test drive Superset on a modest setup or simply on your laptop, there’s virtually no limit around scaling out the platform. Superset is also cloud-native in the sense that it is flexible and lets you choose your web server (Gunicorn, Nginx, Apache), your metadata database engine (MySQL, Postgres, MariaDB, …), your message queue (Redis, RabbitMQ, SQS, …), your results backend (S3, Redis, Memcached, …), your caching layer (memcached, Redis, …), works well with services like NewRelic, StatsD and DataDog, and has the ability to run analytic workloads against most popular database technologies.
Superset is battle tested in large environments with hundreds of concurrent users. Airbnb’s production environment runs inside Kubernetes and serves 600+ daily active users viewing over 100K charts a day.
The Superset web server and the Superset Celery workers (optional) are stateless, so you can scale out by running on as many servers as needed.
安装和启动
采用 镜像 amancevice/superset 进行安装。
注意容器内的两个路径,/var/lib/superset
是元数据的数据库地址,/etc/superset or /home/superset
是配置文件的地址。
Volumes
The image defines two data volumes: one for mounting configuration into the container, and one for data (logs, SQLite DBs, &c).
The configuration volume is located alternatively at /etc/superset or /home/superset; either is acceptable. Both of these directories are included in the PYTHONPATH of the image. Mount any configuration (specifically the superset_config.py file) here to have it read by the app on startup.
The data volume is located at /var/lib/superset and it is where you would mount your SQLite file (if you are using that as your backend), or a volume to collect any logs that are routed there. This location is used as the value of the SUPERSET_HOME environmental variable.
➜ ~ docker search superset
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
amancevice/superset [0.26.3] Superset on Debian+Python3 129 [OK]
tylerfowler/superset An extendable Docker image for Airbnb's Supe… 3
➜ ~ docker pull amancevice/superset
Using default tag: latest
latest: Pulling from amancevice/superset
0bd44ff9c2cf: Pull complete
2576b77b8a87: Pull complete
4d2fed87d171: Pull complete
Digest: sha256:d85229d3bae54cc5281e52d615a0c4752bfefa0ae62c754c598411b4f8e529cd
Status: Downloaded newer image for amancevice/superset:latest
➜ ~ mkdir /opt/docker/superset/conf & mkdir /opt/docker/superset/data
➜ ~ docker run --name superset -u 0 -d -p 8088:8088 -v /opt/docker/superset/conf:/etc/superset -v /opt/docker/superset/data:/var/lib/superset amancevice/superset
aa3fc2b4aadeecc949771844384110e7813ee028cb38bf21d8bbd73fc54c71a5
➜ ~ docker exec -it superset superset-init
Username [admin]: admin
User first name [admin]: admin
User last name [user]: admin
Email [admin@fab.org]: admin@qq.com
Password:
Repeat for confirmation:
Recognized Database Authentications.
Admin User admin created.
访问本机 http://localhost:8088/ 即可看到登录页面:
配置文件
#---------------------------------------------------------
# Superset specific config
#---------------------------------------------------------
ROW_LIMIT = 5000
SUPERSET_WEBSERVER_PORT = 8088
#---------------------------------------------------------
#---------------------------------------------------------
# Flask App Builder configuration
#---------------------------------------------------------
# Your App secret key
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'
# 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:////var/lib/superset/superset.db'
# 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 * 365
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
SECRET_KEY
注意在容器启动前就设置好,值好像跟某些元数据有关系,笔者在第一次启动后修改重启容器,遇到数据源无法查看的问题。
MAPBOX_API_KEY
是支持地图类报表的服务提供商mapbox的密钥,注册一个account后可得,如下图:
Demo
执行命令superset load_examples
可加载样例数据。
[root@VM_41_21_centos ~]# docker exec -it superset superset load_examples
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
Loading examples into <SQLA engine='sqlite:////var/lib/superset/superset.db'>
Creating default CSS templates
Loading energy related dataset
Creating table [wb_health_population] reference
2018-08-09 06:37:26,001:INFO:root:Creating database reference
2018-08-09 06:37:26,056:INFO:root:Database.get_sqla_engine(). Masked URL: sqlite:////var/lib/superset/superset.db
Loading [World Bank's Health Nutrition and Population Stats]
Creating table [wb_health_population] reference
2018-08-09 06:37:37,091:INFO:root:Creating database reference
Creating slices
Creating a World's Health Bank dashboard
Loading [Birth names]
Done loading table!
--------------------------------------------------------------------------------
Creating table [birth_names] reference
2018-08-09 06:37:40,139:INFO:root:Creating database reference
Creating some slices
Creating a dashboard
Loading [Random time series data]
Done loading table!
--------------------------------------------------------------------------------
Creating table [random_time_series] reference
2018-08-09 06:37:41,208:INFO:root:Creating database reference
Creating a slice
Loading [Random long/lat data]
Done loading table!
--------------------------------------------------------------------------------
Creating table reference
2018-08-09 06:37:57,368:INFO:root:Creating database reference
Creating a slice
Loading [Country Map data]
Done loading table!
--------------------------------------------------------------------------------
Creating table reference
2018-08-09 06:37:57,790:INFO:root:Creating database reference
Creating a slice
Loading [Multiformat time series]
Done loading table!
--------------------------------------------------------------------------------
Creating table [multiformat_time_series] reference
2018-08-09 06:37:58,072:INFO:root:Creating database reference
Creating Heatmap charts
Loading [Misc Charts] dashboard
Creating the dashboard
Loading [Paris GeoJson]
Creating table paris_iris_mapping reference
2018-08-09 06:38:00,659:INFO:root:Creating database reference
2018-08-09 06:38:00,704:INFO:root:Database.get_sqla_engine(). Masked URL: sqlite:////var/lib/superset/superset.db
Loading [San Francisco population polygons]
Creating table sf_population_polygons reference
2018-08-09 06:38:00,877:INFO:root:Creating database reference
Loading [Flights data]
2018-08-09 06:38:05,662:INFO:root:Creating database reference
Done loading table!
Loading [BART lines]
Creating table bart_lines reference
2018-08-09 06:38:05,965:INFO:root:Creating database reference
Loading [Multi Line]
Creating table [wb_health_population] reference
2018-08-09 06:38:17,894:INFO:root:Creating database reference
Creating slices
Creating a World's Health Bank dashboard
Done loading table!
--------------------------------------------------------------------------------
Creating table [birth_names] reference
2018-08-09 06:38:20,453:INFO:root:Creating database reference
Creating some slices
Creating a dashboard
Loading DECK.gl demo
Loading deck.gl dashboard
Creating Scatterplot slice
Creating Screen Grid slice
Creating Hex slice
Creating Grid slice
Creating Polygon slice
Creating Arc slice
Creating Path slice
Creating a dashboard
包括几个样例Dashboard:
image.png
看几个酷炫的地图报表:
image.png
image.png
image.png
image.png
遇到的坑
1. superset-init 报错
➜ ~ docker exec -it superset superset-init
Username [admin]: admin
User first name [admin]: admin
User last name [user]: admin
Email [admin@fab.org]: admin@qq.com
Password:
Repeat for confirmation:
2018-07-20 00:37:13,146:ERROR:flask_appbuilder.base:'NoneType' object has no attribute 'name'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/flask_appbuilder/base.py", line 469, in _add_permission
self.sm.add_permissions_view(baseview.base_permissions, baseview.__class__.__name__)
File "/usr/local/lib/python3.5/dist-packages/flask_appbuilder/security/manager.py", line 819, in add_permissions_view
if perm_view.permission.name not in base_permissions:
AttributeError: 'NoneType' object has no attribute 'name'
2018-07-20 00:37:13,151:ERROR:flask_appbuilder.base:Add Permission on View Error: 'NoneType' object has no attribute 'name'
2018-07-20 00:37:13,395:ERROR:flask_appbuilder.base:'NoneType' object has no attribute 'name'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/flask_appbuilder/base.py", line 469, in _add_permission
self.sm.add_permissions_view(baseview.base_permissions, baseview.__class__.__name__)
File "/usr/local/lib/python3.5/dist-packages/flask_appbuilder/security/manager.py", line 819, in add_permissions_view
if perm_view.permission.name not in base_permissions:
AttributeError: 'NoneType' object has no attribute 'name'
2018-07-20 00:37:13,395:ERROR:flask_appbuilder.base:Add Permission on View Error: 'NoneType' object has no attribute 'name'
2018-07-20 00:37:13,745:ERROR:flask_appbuilder.base:'NoneType' object has no attribute 'name'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/flask_appbuilder/base.py", line 469, in _add_permission
self.sm.add_permissions_view(baseview.base_permissions, baseview.__class__.__name__)
File "/usr/local/lib/python3.5/dist-packages/flask_appbuilder/security/manager.py", line 819, in add_permissions_view
if perm_view.permission.name not in base_permissions:
AttributeError: 'NoneType' object has no attribute 'name'
2018-07-20 00:37:13,746:ERROR:flask_appbuilder.base:Add Permission on View Error: 'NoneType' object has no attribute 'name'
Recognized Database Authentications.
Admin User admin created.
···
参考了 这个issue 重新执行了命令 superset init
即可。
➜ ~ docker exec -it superset superset init
2018-07-20 00:41:47,708:INFO:root:Creating database reference
2018-07-20 00:41:47,717:INFO:root:Syncing role definition
2018-07-20 00:41:47,724:INFO:root:Syncing Admin perms
2018-07-20 00:41:47,802:INFO:root:Syncing Alpha perms
2018-07-20 00:41:47,882:INFO:root:Syncing Gamma perms
2018-07-20 00:41:47,958:INFO:root:Syncing granter perms
2018-07-20 00:41:48,033:INFO:root:Syncing sql_lab perms
2018-07-20 00:41:48,108:INFO:root:Fetching a set of all perms to lookup which ones are missing
2018-07-20 00:41:48,181:INFO:root:Creating missing datasource permissions.
2018-07-20 00:41:48,252:INFO:root:Creating missing database permissions.
2018-07-20 00:41:48,254:INFO:root:Creating missing metrics permissions
2018-07-20 00:41:48,258:INFO:root:Cleaning faulty perms
从 github源码 可以看出来 superset-init
命令是原来几个初始化命令的组合。
2. localhost:8088无法访问
由于笔者的ss开了全局代理模式导致。。。
期间参考其他文章手动执行了 superset runserver
命令,通过返回的日志信息可以看到这种启动方式已经被 gunicorn 方式替代。
3. 打开数据源报错
第一次启动后更改了superset_config.py
里的SECRET_KEY
导致。默认值是:
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'
网友评论