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 進行安裝。
注意容器內(nèi)的兩個路徑,/var/lib/superset是元數(shù)據(jù)的數(shù)據(jù)庫地址,/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注意在容器啟動前就設(shè)置好,值好像跟某些元數(shù)據(jù)有關(guān)系,筆者在第一次啟動后修改重啟容器,遇到數(shù)據(jù)源無法查看的問題。
MAPBOX_API_KEY是支持地圖類報表的服務提供商mapbox的密鑰,注冊一個account后可得,如下圖:

image.png

Demo

執(zhí)行命令superset load_examples可加載樣例數(shù)據(jù)。

[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 重新執(zhí)行了命令 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開了全局代理模式導致。。。
期間參考其他文章手動執(zhí)行了 superset runserver 命令,通過返回的日志信息可以看到這種啟動方式已經(jīng)被 gunicorn 方式替代。

3. 打開數(shù)據(jù)源報錯

第一次啟動后更改了superset_config.py里的SECRET_KEY導致。默認值是:

SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'

參考文章

Superset搭建及其簡單使用
可能是目前顏值最高的開源BI工具-Superset
superset使用筆記

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容