首页 > 数据库技术 > 详细

supperset (python 2.7.12 + mysql)记录

时间:2017-09-27 22:53:02      阅读:802      评论:0      收藏:0      [点我收藏+]

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

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

1、安装虚机操作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
    ##CentOS 7
    #http://mirrors.163.com/.help/CentOS7-Base-163.repo
    ##CentOS 6
    #http://mirrors.163.com/.help/CentOS6-Base-163.repo
    ##CentOS 5
    #http://mirrors.163.com/.help/CentOS5-Base-163.repo
    wget -N http://mirrors.163.com/.help/CentOS6-Base-163.repo
    
    mv CentOS6-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.14/Python-2.7.14.tar.xz
    tar -xf Python-2.7.14.tar.xz
    if [ -d Python-2.7.14 ]
    then
        cd Python-2.7.14
        ./configure --prefix=/usr/local/python-2.7.14
        make && make install
        mv /usr/bin/python /usr/bin/python_backup
        #ln -s /usr/local/python-2.7.14 /usr/local/python
        ln -s /usr/local/python-2.7.14/bin/python /usr/bin/python2.7
        ln -s /usr/local/python-2.7.14/bin/python /usr/bin/python
        ln -s /usr/local/python-2.7.14/lib/python2.7 /usr/lib/python2.7
        ln -s /usr/local/python-2.7.14/lib/python2.7 /usr/lib/python
        ln -s /usr/local/python-2.7.14/lib/python2.7 /usr/lib64/python2.7
        ln -s /usr/local/python-2.7.14/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.14 >> /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、安装并使用virtualenv部署superset工程

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

设置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

然后,依次执行如下命令

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

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

技术分享

 

 补充:若使用默认的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

 

supperset (python 2.7.12 + mysql)记录

原文:http://www.cnblogs.com/chinas/p/7603288.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!