zhmg23

我们是如此的不同
资深运维工程师互荐群: 102123162

CentOS下安装Superset

说明:Superset 是 Airbnb (知名在线房屋短租公司)开源的数据探查与可视化平台(曾用名 Panoramix、Caravel ),该工具在可视化、易用性和交互性上非常有特色,用户可以轻松对数据进行可视化分析。

核心功能:

快速创建数据可视化互动仪表盘

丰富的可视化图表模板,灵活可扩展

细粒度高可扩展性的安全访问模型,支持主要的认证供应商(数据库、OpenID、LDAP、OAuth 等)

简洁的语义层,可以控制数据资源在 UI 的展现方式

与 Druid 深度集成,可以快速解析大规模数据集

 

安装大致分为以下几步,升级python环境、安装pip、安装superset、

1、升级ptyhon

1.1 升级ptyhon至2.7

tar zxvf Python-2.7.12.tgz

cd Python-2.7.12

 ./configure

make

make install

 

mv /usr/bin/python /usr/bin/python.bak

ln -s /usr/local/bin/python2.7  /usr/bin/python

 

编辑/usr/bin/yum文件,把!#/usr/bin/python修改为!#/usr/bin/python2.6

vi  /usr/bin/yum

!#/usr/bin/python2.6

 

2、安装pip

安装pip前需要先安装easyinstall

这个可以从官网下载(https://pypi.python.org/pypi/setuptools

wget https://bootstrap.pypa.io/ez_setup.py

python ez_setup.py

easy_install pip

 

# pip -V

pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

 

3、安装superset3.1 安装需要的相关库文件及依赖包

sudo yum install gcc libffi-devel python-devel python-pip python-wheel openssl-devel libsasl2-devel openldap-devel

3.2 建立superset数据目录

mkdir /data/superset

cd  /data/superset

pip install virtualenv

virtualenv venv

. ./venv/bin/activate

pip install --upgrade setuptools pip

 

注:这里 virtualenv是用来为一个应用创建一套“隔离”的Python运行环境,安装好virtualenv后,要切换到virtualenv环境下,进行superset安装

 

3.3利用pip安装superset

 

# 安装 superset

pip install superset

 

创建配置文件,新建如下配置文件

# vim  /data/superset/venv/lib/python2.7/site-packages/superset_config.py

内容如下

#---------------------------------------------------------

# Superset specific config

#---------------------------------------------------------

ROW_LIMIT = 5000

SUPERSET_WORKERS = 4

 

SUPERSET_WEBSERVER_PORT = 8088

#---------------------------------------------------------

 

#---------------------------------------------------------

# Flask App Builder configuration

#---------------------------------------------------------

# Your App secret key

SECRET_KEY = '324872319jhdfasdhcx@!#!@'

 

# The SQLAlchemy connection string to yourdatabase backend

# This connection defines the path to thedatabase that stores your

# superset metadata (slices, connections,tables, dashboards, ...).

# Note that the connection information toconnect to the datasources

# you want to explore are managed directlyin the web UI

SQLALCHEMY_DATABASE_URI = 'mysql://dbuser:dbpasswd@192.168.1.158:3306/spdbname?charset=utf8'

 

# Flask-WTF flag for CSRF

CSRF_ENABLED = True

 

# Set this API key to enable Mapboxvisualizations

MAPBOX_API_KEY = ''

~     



# 创建一个管理员用户(您将在设置密码之前提示用户设置用户名、姓氏和姓氏)

fabmanager create-admin --app superset

 

# 初始化数据库

superset db upgrade

 

# 加载一些数据

superset load_examples

 

# 创建默认角色和权限

superset init

 

#后台启动

nohup superset runserver -p 8088 &

 

如果以上操作都没问题的话,那么恭喜,安装完成,在浏览器中,我们访问http://ip:8088就能看到superset登陆界面了。



  

    

  

 怎么样,数据展示效果不错吧!

以上就是CentOS下安装Superset,安装时,python版本必须在Python 2.7 and Python 3.4+,当然,如果环境允许,也可以在docker中安装,那样可能更简单!


 

4、安装问题踩坑 

 

问题一: 

/usr/local/lib/python2.7/site-packages/flask_migrate/__init__.py:4:ExtDeprecationWarning: Importing flask.ext.script is deprecated, useflask_script instead.

from flask.ext.script import Manager

Was unable to import superset Error:/usr/local/lib/python2.7/site-packages/pysqlite2/_sqlite.so: undefined symbol:sqlite3_stmt_readonly

解决办法:

cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/_sqlite3.so  

 

 

问题二:Can't create admin user on Python 2.7.12

/home/dt_www/venv/lib/python2.7/site-packages/flask_migrate/__init__.py:4:ExtDeprecationWarning: Importing flask.ext.script is deprecated, useflask_script instead.

from flask.ext.script import Manager

/home/dt_www/venv/lib/python2.7/site-packages/flask_cache/__init__.py:152:UserWarning: Flask-Cache: CACHE_TYPE is set to null, caching is effectivelydisabled.

warnings.warn("Flask-Cache: CACHE_TYPE is set to null, "

/home/dt_www/venv/lib/python2.7/site-packages/flask_cache/jinja2ext.py:33:ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cacheinstead.

from flask.ext.cache import make_template_fragment_key

/home/dt_www/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py:298:SAWarning: Exception attempting to detect unicode returns: OperationalError('(sqlite3.OperationalError)near"\xf1\x90\x81\x93\xf1\x90\x81\x8c\xf5\x80\x81\x83\xf0\xb0\x80\xa0\xf4\xb0\x81\x81\xfa\x80\x81\x94\xfd\x80\x80\xa7\xfc\xb0\x81\xa5\xf8\x80\x81\xb4\xfb\x80\x81\xb0\xfa\x90\x81\xa1\xf8\x80\x81\xae\xf9\x90\x81\xb2\xfd\x90\x81\xb4\xfb\xa0\x81\xb2\xf9\xb0\x81\xb3\xf0\x90\x80\xa0\xf8\x80\x81\x93\xf0\x90\x81\x96\xf0\xb0\x81\x92\xf0\x90\x81\x88\xfa\x80\x81\x92\xfc\x80\x80\xb6\xfa\x90\x80\xa9\xf0\x90\x80\xa0\xf8\x80\x81\x93\xfb\xa0\x81\xa1\xfb\xa0\x81\xaf\xfc\x90\x81\x9f":syntax error',)

 "detect unicode returns: %r" % de)

/home/dt_www/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py:298:SAWarning: Exception attempting to detect unicode returns:OperationalError('(sqlite3.OperationalError) near "\xf1\x90\x81\x93\xf1\x90\x81\x8c\xf5\x80\x81\x83\xf0\xb0\x80\xa0\xf4\xb0\x81\x81\xfa\x80\x81\x94\xfd\x80\x80\xa7\xfc\xb0\x81\xa5\xf8\x80\x81\xb4\xfb\xa0\x81\xb5\xf8\xb0\x81\xa9\xf9\x80\x81\xaf\xf8\x80\x81\xa5\xf9\x90\x81\xb2\xfd\x90\x81\xb4\xfb\xa0\x81\xb2\xf9\xb0\x81\xb3\xf0\x90\x80\xa0\xf8\x80\x81\x93\xf0\x90\x81\x96\xf0\xb0\x81\x92\xf0\x90\x81\x88\xfa\x80\x81\x92\xfc\x80\x80\xb6\xfa\x90\x80\xa9\xf0\x90\x80\xa0\xf8\x80\x81\x93\xfb\xa0\x81\xa1\xfb\xa0\x81\xaf\xfc\x90\x81\x9f":syntax error',)

 "detect unicode returns: %r" % de)

Traceback (most recent call last):

File "/usr/local/lib/python2.7/logging/__init__.py", line 861,in emit

   msg = self.format(record)

File "/usr/local/lib/python2.7/logging/__init__.py", line 734,in format

   return fmt.format(record)

  File"/usr/local/lib/python2.7/logging/__init__.py", line 476, in format

   raise e

UnicodeDecodeError: 'ascii' codec can'tdecode byte 0xf1 in position 72: ordinal not in range(128)

Logged from file manager.py, line 81

 

原因就是Python的str默认是ascii编码,和unicode编码冲突,就会报这个标题错误

因为Python2.7的默认str编码是ascii,它与unicode冲突

python3区分unicode str和byte arrary,默认编码不再是ascii

 

import sys

reload(sys)

sys.setdefaultencoding('utf8')

https://github.com/airbnb/superset/issues/1687

 

此方法我没有解决,最终避规了这个错误,采用mysql做为元数据源

 

问题三: 

/usr/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:30:ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, useflask_sqlalchemy instead.

from flask.ext.sqlalchemy._compat import iteritems, itervalues, xrange,\

/usr/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:30:ExtDeprecationWarning: Importing flask.ext.sqlalchemy._compat is deprecated,use flask_sqlalchemy._compat instead.

from flask.ext.sqlalchemy._compat import iteritems, itervalues, xrange,\

解决办法:这只是一个警告,最新版本已经修复此问题

https://github.com/airbnb/superset/issues/808

 

 

问题四: 

使用pip 安装mysqlclient,报错:

# pip install mysqlclient

Collecting mysqlclient

Using cached mysqlclient-1.3.10.tar.gz

   Complete output from command python setup.py egg_info:

   /bin/sh: mysql_config: command not found

   Traceback (most recent call last):

     File "<string>", line 1, in <module>

     File "/tmp/pip-build-3o8m5epm/mysqlclient/setup.py", line 17,in <module>

       metadata, options = get_config()

     File "/tmp/pip-build-3o8m5epm/mysqlclient/setup_posix.py",line 44, in get_config

       libs = mysql_config("libs_r")

     File "/tmp/pip-build-3o8m5epm/mysqlclient/setup_posix.py",line 26, in mysql_config

       raise EnvironmentError("%s not found" % (mysql_config.path,))

   OSError: mysql_config not found

    

   ----------------------------------------

Command "python setup.pyegg_info" failed with error code 1 in /tmp/pip-build-3o8m5epm/mysqlclient/

 

解决办法:

yum install mysql-devel

 

 


如下为官方参考文档:

http://airbnb.io/superset/installation.html

https://github.com/airbnb/superset


 

 

评论