开源BI分析工具 -- superset安装

本文章主要介绍superset的安装,用于连接到kylin数据库,做可视化数据分析用。superset连接kylin的案例分析将在下篇博客中介绍。
本人kylin安装节点是 6、7、8
superset安装节点为8,8的资源利用率最少,安装时为最新版,下面参考文档中有些配置已经过时,因此写下此博客供最新版本的安装。
OS: centos7
Superset版本:0.22.1
Python版本:2.7 virtualenv-15.1.0
Druid版本:0.9.2
步骤一:安装cryptography
cryptography的作用是将连接密码加密。
# yum upgrade python-setuptools
# yum install gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel libsasl2-devel openldap-devel

步骤二,安装pip
如果还没有安装pip,就需要安装pip:
pip下载:
wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
pip安装:
tar -xzvf pip-1.5.4.tar.gz
cd pip-1.5.4
python setup.py install
如果报错,请看:

步骤三,安装virtualenv
官网推荐在virtualenv中安装 superset (Python 3 already ships virtualenv, for Python 2 you need to install it)。
[[email protected] ~]#pip install virtualenv

步骤四,创建虚拟环境
[[email protected] ~]#virtualenv venv
New python executable in /root/venv/bin/python2
Also creating executable in /root/venv/bin/python
Installing setuptools, pip, wheel...
很简单,就是virtualenv 环境名称[自定义的名称,自己喜欢什么就写什么]
默认情况下,虚拟环境会依赖系统环境中的site packages,就是说系统中已经安装好的第三方package也会安装在虚拟环境中,
如果不想依赖这些package,那么可以加上参数 --no-site-packages 建立虚拟环境
即变成了:
[[email protected] ~]# virtualenv venv --no-site-packagesNew python executable in test_env/bin/pythonInstalling setuptools, pip...done.

步骤五,启动虚拟环境
创建成功后,会在当前目录下生成对应的目录文件。
[[email protected] ~]# ls -al ./venv
total 8
drwxr-xr-x 5 root root 82 Mar 1 13:18 .
dr-xr-x---. 9 root root 4096 Mar 1 13:17 ..
drwxr-xr-x 2 root root 248 Mar 1 13:18 bin
drwxr-xr-x 2 root root 23 Mar 1 13:17 include
drwxr-xr-x 3 root root 23 Mar 1 13:17 lib
lrwxrwxrwx 1 root root 3 Mar 1 13:17 lib64 -> lib
-rw-r--r-- 1 root root 60 Mar 1 13:18 pip-selfcheck.json

[[email protected] ~]# cd venv/bin/
[[email protected] bin]#source ./activate
启动成功后,会在前面多出 venv 字样,如下所示
(venv) [[email protected] bin]#
接下来的操作都是在这个虚拟环境下进行的。
若想退出虚拟环境
(venv) [[email protected] bin]# deactivate

步骤六,安装mysqlclient。(此次安装,superset元数据不保存在MySQL,所以步骤略)
将superset的元数据存储改成mysql,就需要这一步。
ROOT权限下
yum install mysql-devel
virtualenv下:
pip install mysqlclient
参考:将 superset 的sqlite 改成 MySQL :

https://github.com/apache/incubator-superset/issues/2467

步骤七,安装superset
1.安装
查看有哪些版本
pip查看superset所有可用版本(这里指定了镜像。官网的太慢),输入一个不存在的版本号,pip就会告诉你可用的版本号:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple superset==999999
开源BI分析工具 -- superset安装开源BI分析工具 -- superset安装
开源BI分析工具 -- superset安装
(venv) [[email protected] bin]#pip install -i https://pypi.tuna.tsinghua.edu.cn/simple superset==0.22.1
如果不指定镜像,直接输入下面的即可:
pip install superset==0.18.4
卸载:
pip uninstall superset

2.设置Druid的时区:
(venv) [[email protected] superset]#vi /root/venv/lib/python2.7/site-packages/superset/config.py
DRUID_TZ = tz.tzutc()
改成:DRUID_TZ = tz.gettz('Asia/Shanghai')
如下图:
开源BI分析工具 -- superset安装

开源BI分析工具 -- superset安装



3.添加superset的配置文件
在python所在的目录(如,我这里是/root/venv/bin下),手动添加superset的配置文件superset_config.py。内容如下(中文字符的行删掉):

# ===============superset_config.py开始================
#使用python2.7,如果下面三行不加的话,使用中文时会出问题。
import sys # import sys package, if not already imported
reload(sys)
sys.setdefaultencoding('utf-8')
#---------------------------------------------------------
# Superset specific config
#---------------------------------------------------------
ROW_LIMIT = 5000
SUPERSET_WORKERS = 4
#默认是8088,改成8388
SUPERSET_WEBSERVER_PORT = 8388
#---------------------------------------------------------

#---------------------------------------------------------
# Flask App Builder configuration
#---------------------------------------------------------
# Your App secret key 这个我也不知道具体什么作用。按照官网就这么写了
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'

#元数据存储默认使用的是sqlite。SQLALCHEMY_DATABASE_URI = 'sqlite:////path/to/superset.db'
#我这里改成mysql
#mysql://用户名:密码@192.168.1.162/数据库名?charset=utf8
SQLALCHEMY_DATABASE_URI = 'mysql://datag:yjkdatag@192.168.1.162/superset?charset=utf8'
# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = True

# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
#汉化
BABEL_DEFAULT_LOCALE='zh'
LANGUAGES = {
'zh': {'flag': 'cn', 'name': 'Chinese'},
'en': {'flag': 'us', 'name': 'English'}
}
# =============== superset_config.py结束================

4.初始化数据
# Create an admin user (you will be prompted to set username, first and last name before setting a password)
fabmanager create-admin --app superset开源BI分析工具 -- superset安装
password为:superset

# Initialize the database 初始化数据库
superset db upgrade
开源BI分析工具 -- superset安装

# Load some data to play with
supersetload_examples
开源BI分析工具 -- superset安装

# Create default roles and permissions
supersetinit
开源BI分析工具 -- superset安装

5.汉化(此步骤略,老版本需要此操作)
从源码中下载
这个目录,复制到
./lib/python2.7/site-packages/superset/下
自已翻译后需要将.po文件翻译成.mo文件:
pybabel compile -d translations

6.启动
# Start the web server on port 8088, use -p to bind to another port
superset runserver
开源BI分析工具 -- superset安装
# To start a development web server, use the -d switch# superset runserver -d
superset runserver
或者指定端口:
superset runserver -p 8388 &

登录:
# To start a development web server, use the -d switch# superset runserver -d
开源BI分析工具 -- superset安装
开源BI分析工具 -- superset安装