centos7 安装 superset4.0.2 教程
一、安装教程
2024年8月27日00:57:27,由于目前superset已经更新到superset4.0.2版本了,所以想要利用centos安装最新版的superset测试一下其效果
python3.12不行,会有个bug,这是python3.12自身原因造成的:
File "/tmp/pip-build-env-3t3zxodv/overlay/lib/python3.12/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/tmp/pip-build-env-3t3zxodv/overlay/lib/python3.12/site-packages/pkg_resources/__init__.py", line 2172, in <module>
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
[end of output]
1. 下载Miniconda(Python3版本)
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
2. 安装Miniconda
bash Miniconda3-latest-Linux-x86_64.sh
在安装过程中,出现以下提示时,可以指定安装路径
[/root/miniconda3] >>> /opt/module/miniconda3
出现complete 字样,即为安装完成
3. 加载环境变量配置文件,使之生效
source ~/.bashrc
4. 取消激活base环境
Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。
conda config --set auto_activate_base false
二、安装python3.10
1.配置conda国内镜像
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
2. 创建superset环境并指定Python3.10
[root@*************** software]# conda create --name superset python=3.10
说明:conda环境管理常用命令
创建环境:conda create -n env_name
查看所有环境:conda info --envs
删除一个环境:conda remove -n env_name --all
3. 激活superset环境
conda activate superset
4 .退出当前环境
(superset) [root@*************** software]# conda deactivate
三、安装superset
1. 安装依赖(之后操作均在superset环境下)
(superset) [root@*************** software]$ sudo yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel
# mysqlclient 依赖 (python3-devel mysql-devel pkgconfig), 没有的话安装下
yum install mysql-devel
# pip 安装
conda install mysqlclient
pip install redis
# (可选)其它一些必要的包
pip install pillow thrift thrift_sasl
2. 安装(更新)setuptools和pip
pip install --upgrade setuptools pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
3. 安装superset
pip install apache-superset==4.0.2 -i https://pypi.douban.com/simple/
4. 修改配置文件
生成成SECRET_KEY
openssl rand -base64 42
修改配置文件
vim /opt/module/miniconda3/envs/superset/lib/python3.10/site-packages/superset/config.py
# Superset specific config
ROW_LIMIT = 5000
SECRET_KEY = 'W26oCWUu49V66dfgMQ8mzMTl4oCJKnhWOZVuBXLjBAEdo3PtNkwlE3UA'
# 数据库配置
SQLALCHEMY_DATABASE_URI = 'mysql://user:passwd@127.0.0.1:3306/superset'
# 暂不清除,先关掉
WTF_CSRF_ENABLED = False
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
# Cache配置
FILTER_STATE_CACHE_CONFIG = {
'CACHE_TYPE': 'RedisCache',
'CACHE_DEFAULT_TIMEOUT': 86400,
'CACHE_KEY_PREFIX': 'superset_filter_cache',
'CACHE_REDIS_URL': 'redis://127.0.0.1:6379/1'
}
参考:https://blog.csdn.net/weixin_38908403/article/details/138286078
5. 配置环境变量
export SUPERSET_CONFIG_PATH=/opt/software/superset/superset_config.py
# 配置superset环境变量,否则找不到superset命令
export FLASK_APP=superset
export LD_PRELOAD=/lib64/libstdc++.so.6
6.初始化数据库
- 在MySQL中创建superset数据库
create database superset;
- 初始化数据库
superset db upgrade
- 创建管理员用户
python superset fab create-admin
报错:
File "/opt/module/miniconda3/envs/superset/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 375, in warn
return fn(*args, **kwargs)
File "/opt/module/miniconda3/envs/superset/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 544, in create_e
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/opt/module/miniconda3/envs/superset/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 150, in
return __import__("MySQLdb")
File "/opt/module/miniconda3/envs/superset/lib/python3.10/site-packages/MySQLdb/__init__.py", line 17, in <module>
from . import _mysql
ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /opt/module/miniconda3/envs/superset/lib/./../libmysqlclient.so.23)
检查是否存在GLIBCXX_3.4.20
参考:https://blog.csdn.net/gdkyxy2013/article/details/111191043
strings /lib64/libstdc++.so.6 | grep GLIBCXX
查询 miniconda 路径是否存在
find /opt/module/miniconda3/ -name 'libstdc++.so.6*'
将 miniconda 存在的文件复制到 /lib64 路径下
sudo cp /opt/module/miniconda3/lib/libstdc++.so.6.0.29 /lib64/
删除 /lib64 路径下 libstdc++.so.6
sudo rm -rf /lib64/libstdc++.so.6
创建软链接
sudo ln -s /lib64/libstdc++.so.6.0.29 /lib64/libstdc++.so.6
再执行管理员创建命令
python superset fab create-admin
- superset 初始化
superset init
报错各种表不存在
File "/opt/module/miniconda3/envs/superset/lib/python3.10/site-packages/MySQLdb/connections.py", line 261, in query
_mysql.connection.query(self, query)
sqlalchemy.exc.ProgrammingError: (MySQLdb.ProgrammingError) (1146, "Table 'superset.tables' doesn't exist")
[SQL: SELECT tables.uuid AS tables_uuid, tables.created_on AS tables_created_on, tables.changed_on AS tables_changed_on, tabln AS tables_description, tables.default_endpoint AS tables_default_endpoint, tables.is_featured AS tables_is_featured, tableser_select_enabled, tables.offset AS tables_offset, tables.cache_timeout AS tables_cache_timeout, tables.params AS tables_paras.schema_perm AS tables_schema_perm, tables.is_managed_externally AS tables_is_managed_externally, tables.external_url AS tabS tables_table_name, tables.main_dttm_col AS tables_main_dttm_col, tables.database_id AS tables_database_id, tables.fetch_valpredicate, tables.`schema` AS tables_schema, tables.`sql` AS tables_sql, tables.is_sqllab_view AS tables_is_sqllab_view, tabl_params, tables.extra AS tables_extra, tables.normalize_columns AS tables_normalize_columns, tables.always_filter_main_dttm Ales.created_by_fk AS tables_created_by_fk, tables.changed_by_fk AS tables_changed_by_fk
找了很久,都没有解决方案,尝试重新执行了命令
superset db upgrade
发现已经在执行各种SQL了
重新跑初始化代码
superset init
6. 启动和停止superset
- 启动superset
gunicorn --workers 5 --timeout 120 --bind 172.16.11.144:8787 "superset.app:create_app()" --daemon
- 停止superset
ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9