kylin可视化工具:superset安装

安装方式:

  • docker安装
  • pip安装:在线/离线

a, superset与关系型数据库

使用superset连接mysql, oracle, sqlserver , hive,hbase

#1, mysql
yum install -y mysql-devel
pip install mysqlclient pymysql 
SQLAlchemy URI ⇒ mysql+pymsql://user:passwd@ip:3306/test

# 2, sqlserver
yum install freetds freetds-devel python-devel
pip install pymssql
yum install unixODBC-devel
pip install pyodbc
SQLAlchemy URI ⇒ mssql+pymssql://user:passwd@ip:1433/test

# 3, oracle 
#安装客户端: instantclient-basic-linux.x64-11.2.0.4.0.zip
#解压zip包, cp * /usr/lib64, 配置export LD_LIBRARY_PATH=/usr/lib64/:$LD_LIBRARY_PATH
https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html
pip install cx_Oracle
SQLAlchemy URI ⇒ oracle+cx_oracle://test:[email protected]:1521/orcl

# 4, hive
pip install pyhive
SQLAlchemy URI ⇒ hive://ip:10000

# 5,hbase
pip install  pyPhoenix phoenixdb
SQLAlchemy URI ⇒ phoenix://ip:8765

b, superset权限控制

I, public权限

图表嵌入html中报权限错误:{“error”: “This endpoint requires the datasource birth_names, database or\n all_datasource_access permission”}

⇒ 解决: 在 superset/config.py 配置GAMMA权限,并且登陆web控制台(安全–>角色列表–> 选择public: 编辑记录–> 搜索all_datasource_access, 添加相关的选项,保存退出即可)

# ---------------------------------------------------
# Roles config
# ---------------------------------------------------
# Grant public role the same set of permissions as for the GAMMA role.
# This is useful if one wants to enable anonymous users to view
# dashboards. Explicit grant on specific datasets is still required.
PUBLIC_ROLE_LIKE_GAMMA = TRUE

II, 查看dashboard权限

安全—> 角色列表–>找到对应的角色: 添加权限

can dashboard on Superset   
can explore json on Superset

1,centos 6: pip在线安装

参照官网:http://superset.apache.org/installation.html, 前提中有说明pyton3.6最合适

# 1,安装依赖包
sudo yum upgrade python-setuptools
sudo yum install gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel libsasl2-devel openldap-devel

# 2, 安装python3
###################
 或使用python2安装pip: 
 curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
 python get-pip.py
###################
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
tar vxf Python-3.6.1.tgz
cd Python-3.6.1
./configure --prefix=/usr/local/python3  
make && make install
echo  'export PATH=$PATH:/usr/local/python3/bin'>>/etc/profile
source /etc/profile
pip3 install kylinpy 					#防止后面连接kylin报错

# 3,安装python虚拟环境
pip3 install virtualenv
python3 -m venv venv
source venv/bin/activate

# 4, 升级pip, setuptools 
pip3 install --upgrade setuptools pip

# 5, 安装superset
pip3 install superset
fabmanager create-admin --app superset  # 创建管理员账号

# 6, 配置元数据库
########## a, 使用mysql做元数据库
#编辑 python2.7/site-packages/superset/config.py
# 注释掉原配置:
#SQLCHEMY_DATABASE_URL = 'sqlite:///' + os.path.join(DATA_DIR,'superset.db')
#将SQLALCHEMY_DATABASE_URI参数改为mysql连接信息:
#SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@localhost/dbname'
########## b,安装python对mysql的依赖,解决报错No module named 'MySQLdb'
# pip3 install pymysql

# 7,启动服务
superset db upgrade       				# 更新数据库
superset load_examples 					# 加载官方提供的样例数据
superset init      					    # 创建/更新角色,权限
superset runserver -d  					# 默认使用 8088端口, 使用 -p 覆盖默认的端口

# 8, 添加kylin数据源
数据库连接url:  kylin://ADMIN:KYLIN@ip:7070/project

服务启动后,访问serverip:8088/, 登陆,配置kylin数据源,报错如下:

ERROR: {"error": "Connection failed!\n\nThe error message returned was:\nCan't load plugin: sqlalchemy.dialects:kylin"}
#解决 : pip3 install kylinpy

把superset的图表嵌入html中报错: HTTP_HEADERS = {‘X-Frame-Options’: ‘SAMEORIGIN’}
解决:需要修改配置 superset/config.py 配置

#修改配置,允许嵌入到其他页面
# vi /usr/local/python3/lib/python3.6/site-packages/superset/config.py: 内容如下
# vi /root/venv/lib/python3.6/site-packages/superset/config.py
#HTTP_HEADERS = {'X-Frame-Options': 'SAMEORIGIN'}# 这是默认的配置,需要注释,解开下面的配置
# If you need to allow iframes from other domains (and are
# aware of the risks), you can disable this header:
HTTP_HEADERS = {}

#退出编辑,使得更改生效
superset init   #服务不用重启,再次访问页面即可显示正常

1.2 常见报错:_sqlite3, '_maybe_box_datetimelike,Can’t determine which FROM clause to join from, there are multiple FROMS

Error: No module named '_sqlite3
解决:
1、yum -y install sqlite-devel
2、cd  Python-3.5.2       (python源码安装文件解压后的文件夹)
3、./configure --enable-loadable-sqlite-extensions --prefix=/usr/local/python3
4、 make && make install
--------------------- 

Error: cannot import name '_maybe_box_datetimelike'
解决:
# 查看当前 pandas 版本
pip list | grep pandas
pandas  0.24.2
# 安装低版本 pandas
pip install pandas==0.23.4

Can't determine which FROM clause to join from, there are multiple FROMS 
解决:
pip install SQLAlchemy==1.2  

2,centos6 离线安装

在上面提到的在线安装完成后,就可以把pip的安装包,打包转移为离线安装了,具体操作涉及python 的pip 语法:

# 1, 转移python3.6的环境: 拷贝打包后的my-python3.6.tar到新的机器上:/usr/local/python3
tar -cvf ~/my-python3.6.tar  /usr/local/python3

# 2,查看pip安装的软件,并把安装包下载到指定目录: 拷贝到新机器上
pip3 freeze  >require.txt
pip3 download -d superset-packs  -r require.txt   

# 3, 在新的机器上,使用pip 安装拷贝过来的并且解压后的包
pip3 install --no-index --find-links= superset-packs   -r require.txt

#pip3 download -d  sqlal-packs  SQLAlchemy==1.2.18 # 这里需要覆盖这个包,否则后面superset  db upgrade  会报错can't determine which from clause to join from
#pip3 install --no-index --find-links= sqlal-packs  SQLAlchemy==1.2.18 #覆盖最新的安装包,避免报错

3, centos 7: docker安装

由于centos6运行docker不稳定,所以只能在centos7 上可以使用docker快速安装使用superset
官网提供以下命令来编译docker镜像

git clone https://github.com/apache/incubator-superset/
cd incubator-superset/contrib/docker
# prefix with SUPERSET_LOAD_EXAMPLES=yes to load examples:
docker-compose run --rm superset ./docker-init.sh
# you can run this command everytime you need to start superset now:
docker-compose up

但是一直编译报错,在Dockerfile中有一行报错,所以还是直接到dockerhup上搜索编译好的镜像比较方便:https://hub.docker.com/r/amancevice/superset

# 1,拉取镜像
docker pull docker.io/amancevice/superset
# 2,启动容器
docker volume create superset 
docker run -d -p 8088:8088  -v superset:/home/superset  --name superset-new    amancevice/superset
# 3, 进入容器,初始化superset:权限,数据库
# Upgrade the DB
docker exec superset-new superset db upgrade
# Sync the base permissions
docker exec superset-new superset init
##连接kylin会包错,没有安装kylinpy, 使用root用户登陆,安装软件
# docker exec superset-new  -it  -u root  bash 
#进入后,apt 安装pip, pip 安装kylinpy, 最后有必要的话commit这个容器为新的镜像

你可能感兴趣的:(kylin)