Apache Superset 安装和配置

官方文档

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/ 即可看到登录页面:

image.png

配置文件

#---------------------------------------------------------
# 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后可得,如下图:

image.png

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'

参考文章

Superset搭建及其简单使用
可能是目前颜值最高的开源BI工具-Superset
superset使用笔记

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容