supperset (python 2.7.12 + mysql)记录

网上看到superset,比较感兴趣,虚机上搭一下,记录操作过程。

版本信息:CentOS 6.6 + python 2.7.12 + mysql 5.1.73 + setuptools 36.5.0 + pip-9.0.1

一、安装superset

1、升级Python

安装虚机操作CentOS6.6的系统环境,过程略,运行如下脚本(替换yum源、升级Python、安装Python setuptools、pip)

#!/bin/bash
#####################################################################################
#基础设置:
#    启用163yum源
#    升级Python
#    
#
#####################################################################################
v_down_tools=~/down_loads

yum -y gcc gcc-c++ make cmake openssl openssl-devel zlib zlib-devel

[[ ! -d ${v_down_tools} ]] && mkdir -p ${v_down_tools}

###################################启用163yum源######################################
yum_upgrade_163(){
    cd ${v_down_tools}
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    if `grep -q 'release 5' /etc/redhat-release` ; then
        OS_version='CentOS5'
    elif  `grep -q 'release 6' /etc/redhat-release` ; then
        OS_version='CentOS6'
    elif  `grep -q 'release 7' /etc/redhat-release` ; then
        OS_version='CentOS7'
    fi
    wget -N http://mirrors.163.com/.help/${OS_version}-Base-163.repo
    mv ${OS_version}-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
    yum clean all
    yum makecache
}

##################################升级Python###########################################
python_upgrade(){
    # 安装Python包
    cd ${v_down_tools}
    wget -N  https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
    tar -xf Python-2.7.12.tar.xz
    if [ -d Python-2.7.12 ]
    then
        cd Python-2.7.12
        ./configure --prefix=/usr/local/python-2.7.12
        make && make install
        mv /usr/bin/python /usr/bin/python_backup
        #ln -s /usr/local/python-2.7.12 /usr/local/python
        ln -s /usr/local/python-2.7.12/bin/python /usr/bin/python2.7
        ln -s /usr/local/python-2.7.12/bin/python /usr/bin/python
        ln -s /usr/local/python-2.7.12/lib/python2.7 /usr/lib/python2.7
        ln -s /usr/local/python-2.7.12/lib/python2.7 /usr/lib/python
        ln -s /usr/local/python-2.7.12/lib/python2.7 /usr/lib64/python2.7
        ln -s /usr/local/python-2.7.12/lib/python2.7 /usr/lib64/python
    fi
    ##设置yum,注意sed的分隔符这里用了|
    sed -i "s|#!/usr/bin/python|#!/usr/bin/python2.6|g" /usr/bin/yum 
    ##添加环境变量
    echo 'export PYTHON_HOME=/usr/local/python-2.7.12' >> /etc/profile
    echo 'export PATH=$PATH:$PYTHON_HOME/bin' >> /etc/profile
    source /etc/profile

}

python_setuptools_pip{
    cd ${v_down_tools}
    ##安装setuptools,注意先安装setuptools才能再安装pip
    wget https://pypi.python.org/packages/a4/c8/9a7a47f683d54d83f648d37c3e180317f80dc126a304c45dc6663246233a/setuptools-36.5.0.zip#md5=704f500dd55f4bd0be905444f3ba892c
    unzip setuptools-36.5.0.zip 
    cd setuptools-36.5.0
    #python setup.py --help
    python setup.py build 
    python setup.py install

    cd ${v_down_tools}
    ##安装pip
    wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
    tar -xf pip-9.0.1.tar.gz 
    cd pip-9.0.1
    #python setup.py -h
    python setup.py build
    python setup.py install

    ##升级
    #pip install --upgrade setuptools pip

}


main(){
    yum_upgrade_163
    python_upgrade
    python_setuptools_pip
}
main
View Code

注:Python setuptools和pip从这里获取:PyPI - the Python Package Index : Python Package Index  https://pypi.python.org/pypi

这里选择的是最新版的,脚本运行完毕,正常情况下已经安装好pip了,可以执行命令查看一下是否安装成功。

2、安装、设置MySQL

(1)安装

# yum -y install mysql-server mysql-client mysql-devel    ##一定要安装mysql-devel,否则安装MySQL-python会报错

(2)启动、初始化服务

# service mysqld start
# /usr/bin/mysql_secure_installation    #设置用户、密码等后,创建supersetdb数据库

具体过程根据提示进行就可以。

3、部署superset

(1)安装并使用virtualenv部署superset工程

pip install virtualenv #安装
virtualenv env      #创建虚拟环境
source env/bin/activate #进入虚拟环境
pip install superset    #安装supperset
pip install MySQL-python  #安装驱动

(2)设置supperset的连接参数

vim env/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'
SQLALCHEMY_DATABASE_URI = 'mysql://root:123456@192.168.116.130:3306/supersetdb?charset=utf8'
 

# Flask-WTF flag for CSRF

CSRF_ENABLED = True

 

# Set this API key to enable Mapboxvisualizations

MAPBOX_API_KEY = ''
View Code

(3)初始化superset并启动服务

依次执行如下命令

# fabmanager create-admin --app superset # 创建一个管理员用户(您将在设置密码之前提示用户设置用户名、姓氏和姓氏)
# superset db upgrade                   # 初始化数据库
# superset load_examples                # 加载样例数据
# superset init                         # 创建默认角色和权限
# nohup superset runserver -p 8088 &    #后台启动

打开浏览器,访问配置的地址,ok,其中一个页面截图如下:

 4、汉化

这里只能做到部分汉化,不完整

(1)编辑配置文件superset_config.py

编辑上面的superset_config.py配置文件,在末尾添加如下配置

# ---------------------------------------------------
# Babel config for translations
# ---------------------------------------------------
# Setup default language
BABEL_DEFAULT_LOCALE = 'zh'
# Your application default translation path
BABEL_DEFAULT_FOLDER = 'babel/translations'
# The allowed translation for you app
LANGUAGES = {
    'en': {'flag': 'us', 'name': 'English'},
    #'it': {'flag': 'it', 'name': 'Italian'},
    #'fr': {'flag': 'fr', 'name': 'French'},
    'zh': {'flag': 'cn', 'name': 'Chinese'},
}

(2)安装mo文件

cd 【superset安装目录】/lib/python2.7/site-packages/flask_appbuilder/translations/zh/LC_MESSAGES   ##目录不存在,则 mkdir -p 创建
wget
https://raw.githubusercontent.com/apache/incubator-superset/master/superset/translations/zh/LC_MESSAGES/messages.mo

重启服务

(3)刷新浏览器

汉化效果如下:

 

 补充:若使用默认的sqlite数据库

    ##先安装sqlite,再安装pysqlite
    yum -y install sqlite sqlite-devel

    ##安装pysqlite (默认使用pysqlite)
    wget https://pypi.python.org/packages/42/02/981b6703e3c83c5b25a829c6e77aad059f9481b0bbacb47e6e8ca12bd731/pysqlite-2.8.3.tar.gz#md5=033f17b8644577715aee55e8832ac9fc
    tar -xf pysqlite-2.8.3.tar.gz
    cd pysqlite-2.8.3
    #python setup.py -h
python setup.py build
python setup.py install

 

参考:

SQLite和PySqlite的使用 - 101010 - 博客园 http://www.cnblogs.com/fortwo/archive/2013/04/22/3035691.html (默认使用sqlite数据库,若用sqlite可参考)

Python的虚拟环境virtualenv_王志_新浪博客 http://blog.sina.com.cn/s/blog_4ddef8f80101eu0w.html

CentOS下安装Superset-zhmg23 http://zhmgz.lofter.com/post/90909_e745201

 Superset安装部署 - duncan - CSDN博客  http://blog.csdn.net/dzjun/article/details/62421718

官方文档:https://superset.incubator.apache.org/installation.html

posted @ 2017-09-27 22:47  VNX  阅读(1820)  评论(0编辑  收藏  举报