前言
當業務成長到必定規模以後,會有許多想看各類不一樣類型報表的需求,若是單獨作在後臺,那麼無疑會浪費前端和後端開發的時間。因此一直都有在尋找一款好用的BI工具。
後面查了一下,市面上好用的一些非商業的BI工具,主要的是 Superset,Redash, Metabase 這三種。
評測請看:
數據可視化的開源方案: Superset vs Redash vs Metabase (一)
數據可視化的開源方案: Superset vs Redash vs Metabase (二)前端
剛開始採用的是 Superset 這個工具,後面發現從使用體驗上來看的話,感受很差用。 並且文檔比較混亂, 最重要的是不支持 mongo。
後面考慮到本身項目的使用狀況, 再加上大部分的編寫人員都是技術人員,因此後面就選了 Redash 打算先試用一下。node
安裝
參照官方文檔採用docker安裝: 官方docker安裝文檔python
前置環境
docker, docker compose, nodejs 都要安裝,這邊就不細講了。mysql
git clone 庫
啓動docker 服務(走不通)
可是發現一直報這個錯誤:

好像是 pip 的版本過低了,要升級到 18.1 版本。可是我後面升上去以後呢:nginx
1 2
|
[root@VM_156_200_centos redash]# pip -V pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
|
他仍是繼續給我報這個bug???git
docker-compose.production.yml文件
後面就從新參照了這個教程: redash安裝及使用
編輯docker-compose.production.yml文件,將數據目錄映射出來以及更改密碼。就改兩個地方:github
- 這個映射的註釋取消掉:

- 修改這個字段,其實就是密碼:
1
|
REDASH_COOKIE_SECRET: youPassword
|
運行命令完成數據庫初始化操做
1
|
docker-compose -f docker-compose.production.yml run --rm server create_db
|
1 2 3 4 5 6 7
|
[root@VM_156_200_centos redash]# docker-compose -f docker-compose.production.yml run --rm server create_db Pulling redis (redis:3.0-alpine)... Trying to pull repository docker.io/library/redis ... 3.0-alpine: Pulling from docker.io/library/redis 88286f41530e: Pull complete ...... [2018-11-23 08:18:56,499][PID:1][INFO][alembic.runtime.migration] Running stamp_revision -> 71477dadd6ef
|
利用docker-compose啓動docker運行起來
1
|
docker-compose -f docker-compose.production.yml up
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
[root@VM_156_200_centos redash]# docker-compose -f docker-compose.production.yml up Pulling nginx (redash/nginx:latest)... Trying to pull repository docker.io/redash/nginx ... latest: Pulling from docker.io/redash/nginx 03e1855d4f31: Pull complete a3ed95caeb02: Pull complete ccca24cf536d: Pull complete 6114b204585d: Pull complete 46062b965522: Pull complete Digest: sha256:b10bc96086fa30b8fd8a8d1c47ce6fdb5f531c91cbfa5820595a687b33082be3 Status: Downloaded newer image for docker.io/redash/nginx:latest redash_postgres_1 is up-to-date Creating redash_worker_1 ... Creating redash_worker_1 ... done Creating redash_server_1 ... done Creating redash_nginx_1 ... error
ERROR: for redash_nginx_1 Cannot start service nginx: driver failed programming external connectivity on endpoint redash_nginx_1 (21aba0dfa8812cb0de0f52563d7f347281cf353890d11577a1a20fba142190f6): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: for nginx Cannot start service nginx: driver failed programming external connectivity on endpoint redash_nginx_1 (21aba0dfa8812cb0de0f52563d7f347281cf353890d11577a1a20fba142190f6): Bind for 0.0.0.0:80 failed: port is already allocated ERROR: Encountered errors while bringing up the project.
|
發現報錯了,原來是 nginx的鏡像啓動失敗,80 端口被佔用了, 查了一下 docker 容器,發現確實有兩個以前就運行的nginx容器還在跑,那就把這個兩個容器刪掉:web
1 2 3 4 5 6 7 8 9 10 11
|
[root@VM_156_200_centos redash]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ...... a9ee06d55082 nginx:v3 "nginx -g 'daemon ..." 7 months ago Up 7 months 0.0.0.0:80->80/tcp webserver3 89e76cdbfe98 nginx "nginx -g 'daemon ..." 7 months ago Up 7 months 0.0.0.0:8080->80/tcp webserver
[root@VM_156_200_centos redash]# docker rm -f a9ee06d55082 a9ee06d55082 [root@VM_156_200_centos redash]# docker rm -f 89e76cdbfe98 89e76cdbfe98
|
這樣就刪掉了, 重試一下:redis
1 2 3 4 5 6 7 8 9
|
[root@VM_156_200_centos redash]# docker-compose -f docker-compose.production.yml up redash_redis_1 is up-to-date redash_postgres_1 is up-to-date redash_worker_1 is up-to-date redash_server_1 is up-to-date Starting redash_nginx_1 ... done Attaching to redash_redis_1, redash_postgres_1, redash_worker_1, redash_server_1, redash_nginx_1 ...... worker_1 | [2018-11-23 08:20:43,810][PID:1][INFO][MainProcess] Received task: redash.tasks.refresh_queries[00156e42-0213-40b3-a9a2-8ff475584bfb]
|
這樣就跑起來了。 接下來就訪問 http://119.xx.xx.28/setup 能夠看到已經有站點了, 這個就是設置頁面:

這時候看了一下 docker 的容器,就會發現 redash 有5個相關的容器:sql
1 2 3 4 5 6 7 8
|
[root@VM_156_200_centos redash]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 751e870e42c7 redash/nginx:latest "nginx -g 'daemon ..." 5 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 443/tcp redash_nginx_1 e48dd3875394 redash/redash:latest "/app/bin/docker-e..." 5 minutes ago Up 5 minutes 0.0.0.0:5000->5000/tcp redash_server_1 5de34df455e8 redash/redash:latest "/app/bin/docker-e..." 5 minutes ago Up 5 minutes 5000/tcp redash_worker_1 c4ef5ca8af6f redis:3.0-alpine "docker-entrypoint..." 7 minutes ago Up 7 minutes 6379/tcp redash_redis_1 515d93e8f4bc postgres:9.5.6-alpine "docker-entrypoint..." 7 minutes ago Up 7 minutes 5432/tcp redash_postgres_1 ......
|
設置管理員的用戶名和密碼

這樣就進去了

使用
web 頁面添加數據源
在這邊能夠添加數據源:


添加一個新的, 而後選擇 mysql:

而後就輸入鏈接配置,這樣就鏈接上了。

我這邊配了兩個mysql
建立一條query
點擊新建query,而後寫入sql,生成數據:

能夠看到,有數據出來了。 接下來選擇 New Visualization 來建立圖表

命名完以後, 點擊 save ,而後點擊右上角的 publish,就能夠發佈出去了, 就能夠在queries列表看到了

建立dashboard
點擊建立一個新的dashboard:

點擊 Edit,而後點擊下面的 Add Widget, 添加query, 將剛纔建立的query以圖表的方式加進去

最後publish,就能夠看到了:

總結
基本上基礎的安裝和使用就這樣子了,至於後面更細的,得看redash對業務的使用狀況。