目录
Superset
Superset是什么
superset是airbnb孵化的数据可视化工具,apache基金会运营主要用于数据分析师进行数据可视化工作,前端是用react开发的,后端使用flask开发,权限管理完善,图形可定制性也比较高,github持续更新,集合了metabase的Dashboard和pivot的查询可定制性优点,部署相对麻烦
但是superset是最漂亮的
简单demo还没有细化 将就看😂
安装部署
Superset提供3种安装方式:
1)安装进Docker 2)直接安装进操作系统 3)安装进Python虚拟机。
第1种方式:docker会特别简单建议使用;第2种方式不推荐,因为Superset会依赖很多包,直接装进操作系统可能会和其他应用冲突;所以推荐使用Python虚拟机进行安装。以下是安装步骤。 官方文档
docker安装
1.拉取docker镜像
docker pull amancevice/superset
2.启动容器,将8088端口暴露到本机8088端口
docker run -d -p "8088:8088" --name superset amancevice/superset
3.初始化superset并设置管理员账号
docker exec -it superset superset-init
4.安装完成
浏览器打开 http://localhost:8088
5.docker 基础命令
查看存在的镜像:docker images
查看运行的容器:docker ps
或docker container ls
查看曾经启动过的容器:
docker ps -a
启动曾经启动过的容器:docker start 0fffc965b6a8
停止启动的容器:docker stop 0fffc965b6a8
进入容器终端:docker exec -it 0ff bash
退出容器终端:如果从这个 stdin 中 exit,不会导致容器的停止
docker exec 后边可以跟多个参数,这里主要说明 -i -t 参数。
只用 -i 参数时,由于没有分配伪终端,界面没有我们熟悉的 Linux 命令提示符,但命令执行结果仍然可以返回。
当 -i -t 参数一起使用时,则可以看到我们熟悉的 Linux 命令提示符。
superset在容器中的安装位置:
该技能可用来修改superset的核心配置文件config.py或者二次开发superset
mac 安装
来源于官方文档的要求:
Installation & Configuration
Getting Started
Superset has deprecated support for Python 2.*
and supports only ~=3.6
to take advantage of the newer Python features and reduce the burden of supporting previous versions. We run our test suite against 3.6
, but running on 3.7
should work as well.
确认你是否有Python3.6及以上版本,如果没有可以去Python官网下载并安装最新版
python3 --version
安装Python虚拟机visualenv
pip3 install virtualenv
创建和激活virtualenv:
# virtualenv is shipped in Python 3.6+ as venv instead of pyvenv.
# See https://docs.python.org/3.6/library/venv.html
python3 -m venv venv
. venv/bin/activate
一旦激活后你的所有操作都在Python虚拟机里面,要退出的话输入deactivate。
Python的配置工具和pip
pip3 install --upgrade setuptools pip
这条命令执行完因为网络原因可能会失败 重复几次执行就好了
Superset的安装和初始化
# Install superset
pip3 install superset
# Initialize the database
superset db upgrade
# Create an admin user (you will be prompted to set a username, first and last name before setting a password)
$ export FLASK_APP=superset
flask fab create-admin
按照提示输入登录账户密码等:
Username [admin]: # login name
User first name [admin]: # first name
User last name [user]: # lastname
Email [admin@fab.org]: # email, must unique
Password:
Repeat for confirmation:
# Load some data to play with
superset load_examples
# Create default roles and permissions
superset init
# To start a development web server on port 8088, use -p to bind to another port
superset run -p 8080 --with-threads --reload --debugger
pip3 install superset
执行后可能会有很多报错
nstalling collected packages: python-geohash, decorator, py, retry, urllib3, selenium, simplejson, sqlparse, wtforms-json, superset
Running setup.py install for python-geohash ... error
ERROR: Command errored out with exit status 1:
command: /Users/lianxiaobao/lianxiaobao/superset/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zj/mm7y6d6j0hqgcxlzy1l3xhd00000gn/T/pip-install-eyvkw8__/python-geohash/setup.py'"'"'; __file__='"'"'/private/var/folders/zj/mm7y6d6j0hqgcxlzy1l3xhd00000gn/T/pip-install-eyvkw8__/python-geohash/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/zj/mm7y6d6j0hqgcxlzy1l3xhd00000gn/T/pip-record-07j8pnho/install-record.txt --single-version-externally-managed --compile --install-headers /Users/lianxiaobao/lianxiaobao/superset/venv/include/site/python3.7/python-geohash
cwd: /private/var/folders/zj/mm7y6d6j0hqgcxlzy1l3xhd00000gn/T/pip-install-eyvkw8__/python-geohash/
Complete output (21 lines):
running install
running build
running build_py
creating build
creating build/lib.macosx-10.7-x86_64-3.7
copying geohash.py -> build/lib.macosx-10.7-x86_64-3.7
copying quadtree.py -> build/lib.macosx-10.7-x86_64-3.7
copying jpgrid.py -> build/lib.macosx-10.7-x86_64-3.7
copying jpiarea.py -> build/lib.macosx-10.7-x86_64-3.7
running build_ext
building '_geohash' extension
creating build/temp.macosx-10.7-x86_64-3.7
creating build/temp.macosx-10.7-x86_64-3.7/src
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/lianxiaobao/anaconda/anaconda3/include -arch x86_64 -I/Users/lianxiaobao/anaconda/anaconda3/include -arch x86_64 -DPYTHON_MODULE=1 -I/Users/lianxiaobao/lianxiaobao/superset/venv/include -I/Users/lianxiaobao/anaconda/anaconda3/include/python3.7m -c src/geohash.cpp -o build/temp.macosx-10.7-x86_64-3.7/src/geohash.o
解决办法如下:
安装gcc最新版本
brew info gcc@7
完成之后在重新安装superset包
CFLAGS=-stdlib=libc++ pip3 install superset
阿里云ecs安装
服务器版本:
(superset-py3) [root@xiaobaoblog logs]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
mysql:
(superset-py3) [root@xiaobaoblog logs]# mysql -V
mysql Ver 14.14 Distrib 5.6.45, for Linux (x86_64) using EditLine wrapper
python:
(superset-py3) [root@xiaobaoblog logs]# python --version
Python 3.7.3
1. 安装MySQL数据库
1.1. 更新操作系统
yum update #更新操作系统
1.2. 检查系统是否安装了mariadb,如果安装了mariadb则需要先卸载
yum list installed | grep mariadb #查看mariadb的安装状态
yum -y remove mariadb* #卸载mariadb
1.3. 建立目录并下载MySQL源包
cd /usr/local/src
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
1.4 安装MySQL源并通过yum安装MySQL数据库
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server
1.5 重新开启MySQL
systemctl start mysqld #启动MySQL
Mysql -uroot -p #登录MySQL
刚安装的 MySQL 是没有密码的,这时会出现: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO) 所以需要先停止数据库,然后以不检查权限的语句启动MySQL
1.6 关闭MySQL并以不检查权限的方式重新启动MySQL
systemctl stop mysqld #停止数据库
mysqld --user=root --skip-grant-tables &; #以不检查权限的语句启动MySQL
Mysql -uroot -p #登录数据库
1.7 更新数据库密码
UPDATE mysql.user SET Password=PASSWORD('123456') where USER='root'; #MySQL 5.7 以下版本
UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root'; #MySQL 5.7 版本
flush privileges; #刷新
exit; #退出
1.8 修改CentOS防火墙配置以便MySQL和Superset可以进行远程连接
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --permanent --zone=public --add-port=3306/udp
firewall-cmd --permanent --zone=public --add-port=8088/udp
firewall-cmd --permanent --zone=public --add-port=8088/tcp
firewall-cmd --reload
firewall-cmd --zone=public --permanent --add-service=mysql
systemctl restart firewalld
1.9 登录数据库开启远程访问
mysql -uroot -p #登录数据库
grant all privileges on *.* to root@"%" identified by '0'; #进行开启远程访问的操作
由于密码过于简单,所以会报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.’ 需要先更新密码,再进行grant all的操作
SET PASSWORD = PASSWORD(‘密码’); #更新数据库密码
grant all privileges on *.* to root@"%" identified by '0'; #进行开启远程访问的操作
flush privileges;
exit;
1.10 设置MySQL开机启动
systemctl enable mysqld
由于MySQL默认编码格式为latin1,中文的存储会变成问号,需要修改配置文件,将其改为utf8mb4
1.11 修改MySQL默认编码格式
systemctl stop mysqld #停止MySQL
vim /etc/my.cnf #编辑MySQL配置文件
在my.cnf文件中加入下面内容
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
1.12 重新启动MySQL
systemctl start mysqld #启动MySQL
systemctl status mysqld #检查MySQL服务状态
2. 安装Python3、PIP和VirtualENV
2.1 为安装python3环境准备所需的包
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.2 安装python3环境
cd /usr/local/src #进入源码文件夹
wget www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz #下载python文件
tar xf Python-3.7.3.tgz #解压缩
cd Python-3.7.3 #进入python 文件夹
./configure #配置
make && make install #安装
2.3 安装EPEL源并安装superset必备的包
yum install epel-release #安装epel源
yum install mysql-devel #安装MySQL开发包,属于pymysqlclient依赖
yum install gcc gcc-c++ libffi-devel python-devel python-wheel openssl-devel libsasl2-devel openldap-devel #安装依赖包
2.4 安装python3的virtualenv并建立superset的env
pip3 install virtualenv #安装virtualenv
python3 -m venv superset-py3 #建立superset的venv
source superset-py3/bin/activate #激活superset的venv
3. 安装Superset
3.1 在env中安装superset
pip3 install --upgrade pip #升级pip
pip3 install --upgrade setuptools pip #升级setuptools
pip3 install superset #安装superset
3.2 安装superset数据库包
pip3 install mysqlclient #安装mysql连接包
pip3 install pymssql #安装mssql连接包
3.3 配置superset
vim /home/lianxiaobao/data/xiaobaosuperset/superset-py3/lib/python3.7/site-packages/superset/config.py
修改superset配置文件,将默认的sqlite3数据库改为MySQL找到:
SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(DATA_DIR, "superset.db")
将其改为:
SQLALCHEMY_DATABASE_URI = ‘mysql://用户名:密码@IP地址/数据库名?charset=utf8’
3.4 在MySQL中创建superset数据库
mysql -uroot -p #登录MySQL
create database 数据库名; #建立superset数据库
3.5 初始化superset
# Create an admin user (you will be prompted to set a username, first and last name before setting a password)
$ export FLASK_APP=superset
flask fab create-admin #建立管理员账号
superset db upgrade
superset init #初始化superset数据库
superset run -p 8088 -h 0.0.0.0 #测试运行superset
3.6防止ssh关闭服务关闭的方式运行superset
nohup superset run -h 0.0.0.0 -p 8088 2>&1 > logs/superset.log &
3.7访问浏览器
3.8遇到最大的坑这里的web UI URL 按照官方文档
# To start a development web server on port 8088, use -p to bind to another port
superset run -p 8080 --with-threads --reload --debugger
会端口占用 将端口换成8088也会打不开奇怪的是在80端口打开了
# To start a development web server on port 8088, use -p to bind to another port
superset run -p 8088 --with-threads --reload --debugger
查看原因:
netstat -tnlp
解决办法 加参数:-h 0.0.0.0
OK👌
superset的使用咱以后再写,先这样水一篇咯。