Linux8安装Superset 4.0.2过程

官方教程:PyPI | Superset (apache.org)

查看Superset版本对应的python版本:apache-superset · PyPI,可见Superset最新版本为:4.0.2,对应支持python版本为:3.9 3.10 3.11

本次安装采用源码编译的python 3.11.0,编译前需提前安装以下包:

yum install sqlite-devel

yum install bzip2-devel 

然后再重新编译python源码,即可解决安装Superset时遇到的两个问题:

ModuleNotFoundError: No module named '_sqlite3'

ModuleNotFoundError: No module named '_bz2'


以下是编译python源码的步骤:

wget -c https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz

tar -zxvf Python-3.11.0.tgz

cd Python-3.11.0/

 ./configure --prefix=/usr/python3.11.0

make

make install

编译成功后,需要把原有系统的python更换成最新安装的版本

rm -rf /usr/bin/python
rm -rf /usr/bin/python3
rm -rf /usr/local/bin/pip
rm -rf /usr/local/bin/pip3
ln -s  /usr/python3.11.0/bin/python3 /usr/bin/python
ln -s  /usr/python3.11.0/bin/python3 /usr/bin/python3
python -V
ln -s /usr/python3.11.0/bin/pip3 /usr/local/bin/pip3
ln -s /usr/python3.11.0/bin/pip3 /usr/local/bin/pip
pip -V

至此python 3.11.0环境已经安装完毕,开始进入安装Superset的踩坑过程。以下是安装Superset的目标:

1)metadata需要安装在mysql上

2)官方examples需要安装在mysql上,并且需安装所有的examples

3)必须是Superset 4.0.2版本


以下是安装MySQL8,并创建superset metadata数据库及example数据库的步骤

从MYSQL官网下载免费的yum包:https://dev.mysql.com/downloads/repo/yum/

wget -c https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm

yum install mysql84-community-release-el8-1.noarch.rpm

yum install mysql-community-server

systemctl start mysqld

查看默认密码: grep "password" /var/log/mysqld.log

mysql -u root -p

SHOW VARIABLES LIKE 'validate_password%';

SET GLOBAL validate_password.length = 6;

SET GLOBAL validate_password.policy = 'LOW';

alter user 'root'@'localhost' IDENTIFIED BY '123456';

CREATE DATABASE superset4 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

CREATE DATABASE main DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;


1:Installing and Initializing Superset

pip install apache-superset==4.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/

很顺利的安装完成,此时需要安装pymysql,并修改配置文件把superset database修改为mysql

pip install pymysql

vi /usr/python3.11.0/lib/python3.11/site-packages/superset/config.py
修改此处内容:SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root@localhost/superset4'

注意请提前安装mysql数据库及创建database:superset4,然后开始执行初始化

superset db upgrade

如果此时重复出现上述 '_sqlite3' 及  '_bz2' ,可以手工的拷贝文件到python lib目录

cp /root/Python-3.11.0/build/lib.linux-x86_64-3.11/_bz2.cpython-311-x86_64-linux-gnu.so /usr/python3.11.0/lib/python3.11/lib-dynload/

再次执行初始化,又出现了新的问题:

A Default SECRET_KEY was detected, please use superset_config.py to override it.
Use a strong complex alphanumeric string and use a tool to help you generate 
a sufficiently random sequence, ex: openssl rand -base64 42

按照提示执行:openssl rand -base64 42 并把内容复制到一个新建的配置文件中:

vi /usr/python3.11.0/bin/superset_config.py

SECRET_KEY = 'n36bYFh40TLkH0PpYdq/CebkTxX1GxbEogdIbCQZ3IvScW96TK1+MYrN'

再次执行:superset db upgrade  成功了


2:Create an admin user in your metadata database

export FLASK_APP=superset
superset fab create-admin

3:导入官方examples

由于官方的案例数据是存放在GitHub上的,网络连接不稳定,经常性报错。所以必须去GitHub网站手动下载所有文件到本地:apache-superset/examples-data (github.com)

/root/examples-data-master

进入目录后,启动python自带的http服务,即可通过浏览器浏览案例文件:http://192.168.142.129:9999/

python3 -m http.server 9999


修改配置文件:/usr/python3.11.0/lib/python3.11/site-packages/superset/examples/helpers.py

BASE_URL = "http://192.168.142.129:9999/"

同时修改此目录的所有yaml文件内容,把data网址https://raw.githubusercontent.com/改成前面的本地地址,如

/usr/python3.11.0/lib/python3.11/site-packages/superset/examples/configs/datasets/examples

vi users_channels.csv

data: http://192.168.142.129:9999/datasets/examples/slack/users_channels.csv


创建mysql数据库名为:main,不知道为何必须是这个名字,否则会报以下错误:

(pymysql.err.OperationalError) (1049, "Unknown database 'main'")

再次修改配置文件,修改examples的数据库为mysql数据库

vi /usr/python3.11.0/lib/python3.11/site-packages/superset/config.py

SQLALCHEMY_EXAMPLES_URI = 'mysql+pymysql://root@localhost/main'


如果采用mysql数据库的话,superset连接mysql时会出现以下错误

ModuleNotFoundError: No module named 'MySQLdb'

需要安装pip install pymysql,并且修改文件

vi /usr/python3.11.0/lib/python3.11/site-packages/superset/db_engine_specs/mysql.py

在import MySQLdb前添加

import pymysql
pymysql.install_as_MySQLdb()

终于可以执行导入官方案例数据了,数据量比较多,需要耐心等待执行完成

superset load_examples

superset init


UserWarning: Using the in-memory storage for tracking rate limits as no storage was explicitly specified.

yum install redis

systemctl enable redis

systemctl start redis


vi /usr/python3.11.0/lib/python3.11/site-packages/superset/config.py

RATELIMIT_STORAGE_URI = "redis://localhost:6379"


4:To start a development web server on port 8088, use -p to bind to another port
superset run -h 0.0.0.0 -p 8088 --with-threads --reload --debugger


以下是官方的Dashboards: