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.

安裝和啟動(dòng)

采用 鏡像 amancevice/superset 進(jìn)行安裝。
注意容器內(nèi)的兩個(gè)路徑,/var/lib/superset是元數(shù)據(jù)的數(shù)據(jù)庫(kù)地址,/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.

訪(fǎng)問(wèn)本機(jī) http://localhost:8088/ 即可看到登錄頁(yè)面:

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注意在容器啟動(dòng)前就設(shè)置好,值好像跟某些元數(shù)據(jù)有關(guān)系,筆者在第一次啟動(dòng)后修改重啟容器,遇到數(shù)據(jù)源無(wú)法查看的問(wèn)題。
MAPBOX_API_KEY是支持地圖類(lèi)報(bào)表的服務(wù)提供商mapbox的密鑰,注冊(cè)一個(gè)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

包括幾個(gè)樣例Dashboard:


image.png

看幾個(gè)酷炫的地圖報(bào)表:


image.png

image.png

image.png

image.png

遇到的坑

1. superset-init 報(bào)錯(cuò)

?  ~ 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.
···

參考了 這個(gè)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源碼 可以看出來(lái) superset-init 命令是原來(lái)幾個(gè)初始化命令的組合。

2. localhost:8088無(wú)法訪(fǎng)問(wèn)

由于筆者的ss開(kāi)了全局代理模式導(dǎo)致。。。
期間參考其他文章手動(dòng)執(zhí)行了 superset runserver 命令,通過(guò)返回的日志信息可以看到這種啟動(dòng)方式已經(jīng)被 gunicorn 方式替代。

3. 打開(kāi)數(shù)據(jù)源報(bào)錯(cuò)

第一次啟動(dòng)后更改了superset_config.py里的SECRET_KEY導(dǎo)致。默認(rèn)值是:

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

參考文章

Superset搭建及其簡(jiǎn)單使用
可能是目前顏值最高的開(kāi)源BI工具-Superset
superset使用筆記

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,885評(píng)論 6 541
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,312評(píng)論 3 429
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事。” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 177,993評(píng)論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 63,667評(píng)論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 72,410評(píng)論 6 411
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 55,778評(píng)論 1 328
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,775評(píng)論 3 446
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 42,955評(píng)論 0 289
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,521評(píng)論 1 335
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 41,266評(píng)論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 43,468評(píng)論 1 374
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,998評(píng)論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,696評(píng)論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 35,095評(píng)論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 36,385評(píng)論 1 294
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 52,193評(píng)論 3 398
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 48,431評(píng)論 2 378

推薦閱讀更多精彩內(nèi)容