文章目录
1. 环境准备
创建python环境
conda create -n superset python=3.9
安装依赖
yum install gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel
安装mysql客户端依赖
yum install mysql-devel
2. 安装 superset
pip install apache-superset==3.1.2
安装依赖
pip install mysqlclient #mysql客户端
pip install gunicorn #superset启动工具
pip install pillow
配置 superset
vim /data/webapp/python/superset/config/superset_config.py
import urllib.parse
ROW_LIMIT = 5000
SECRET_KEY = 'w0jv+cnI0WNs8+Dtw3eAzjhSeZJQB/Il0Je1FybE5Pdccw+vsIh5xyxR'
# 假设您的数据库用户名和密码中包含特殊字符
username = 'root'
password = 'AaafC43.#5'
database_url = 'mysql://'
# 对密码中的特殊字符进行编码
encoded_password = urllib.parse.quote(password, safe='')
database_url += f'{username}:{encoded_password}@localhost:3306/superset_db'
SQLALCHEMY_DATABASE_URI = database_url
WTF_CSRF_ENABLED = False
TALISMAN_ENABLED = False
BABEL_DEFAULT_LOCALE = "zh"
LANGUAGES = {
"zh": {"flag": "cn", "name": "简体中文"},
"en": {"flag": "us", "name": "English"},
}
PUBLIC_ROLE_LIKE_GAMMA = True
# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = True
# Add endpoints that need to be exempt from CSRF protection
WTF_CSRF_EXEMPT_LIST = []
# A CSRF token that expires in 1 year
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365
# Set this API key to enable Mapbox visualizations
MAPBOX_API_KEY = ''
生成 SECRET_KEY
superset re-encrypt-secrets
设置环境变量
vim /etc/profile.d/my_env.sh
export SUPERSET_CONFIG_PATH=/data/webapp/python/superset/config/superset_config.py
source /etc/profile.d/my_env.sh
设置 LD_PRELOAD
vim .bashrc
export LD_PRELOAD=/usr/lib/gcc/x86_64-redhat-linux/8/libstdc++.so:$LD_PRELOAD
source .bashrc
初始化数据库
export FLASK_APP=superset
superset db upgrade
设置账号
export FLASK_APP=superset
superset fab create-admin
系统初始化
superset init
3. 启动 superset
启动配置
vim /data/webapp/python/superset/config/gunicorn_config.py
import multiprocessing
bind = '0.0.0.0:8088' #绑定ip和端口号
backlog = 512 #监听队列
timeout = 120 #超时
#worker_class = 'gevent'
workers = 2
worker_connections = 1000
#threads = 2 #指定每个进程开启的线程数
loglevel = 'info' # 日志级别
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' #设置gunicorn访问日志格式,错误日志无法设置
pidfile = '/data/webapp/python/superset/superset.pid'
errorlog = '/data/logs/superset/error.log'
accesslog = '/data/logs/superset/access.log'
print("IP and PORT:"+bind)
print("pid_file:"+pidfile)
print("error_log:"+errorlog)
print("access_log:"+accesslog)
启动脚本
#!/bin/bash
source /data/server/miniconda3/etc/profile.d/conda.sh
conda activate superset
start(){
gunicorn -c /data/webapp/python/superset/config/gunicorn_config.py --daemon 'superset.app:create_app()' > /data/logs/superset/superset.log
}
stop(){
ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9
}
case $1 in
start )
echo "启动Superset"
start
;;
stop )
echo "停止Superset"
stop
;;
restart )
echo "重启Superset"
stop
start
esac