BI工具Superset安装配置

配置

配置文件

要配置应用,需要创建superset_config.py文件并添加进PYTHONPATH中。在配置文件中可以定义的部分参数:

vim /data/superset/superset_config.py
# Superset specific config
ROW_LIMIT = 5000

SUPERSET_WEBSERVER_PORT = 8088

# Flask App Builder configuration
# Your App secret key
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'

# The SQLAlchemy connection string to your database backend
# This connection defines the path to the database that stores your
# superset metadata (slices, connections, tables, dashboards, ...).
# Note that the connection information to connect to the datasources
# you want to explore are managed directly in the web UI
SQLALCHEMY_DATABASE_URI = 'sqlite:////root/.superset/superset.db'

# 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 = ''

# Setup default language
BABEL_DEFAULT_LOCALE = "zh"

全部的参数和默认值可见https://github.com/apache/superset/blob/master/superset/config.py ,也就是supersest安装的本地 superset/lib/python3.9/site-packages/superset/config.py 文件,它们都可以在superset_config.py文件中设置。

运行WSGI HTTP

虽然可以在NGINX 或 Apache 上运行 Superset,但官方建议在异步模式下使用 Gunicorn。请参考您首选技术的文档,以在您的环境中运行良好的方式设置此 Flask WSGI 应用程序。 这是已知在生产中运行良好的异步设置:

pip install gevent
gunicorn -w 10 \
      -k gevent \
      --timeout 120 \
      -b  0.0.0.0:8888 \
      --limit-request-line 0 \
      --limit-request-field_size 0 \
      --statsd-host localhost:8125 \
      "superset.app:create_app()"

有关更多信息,请参阅 Gunicorn 文档。 请注意,开发 Web 服务器(superset run或flask run)不适用于生产用途。

如果您不使用 Gunicorn,您可能会在 superset_config.py 中设置COMPRESS_REGISTER = False 来禁用flask-compress。

设置为服务:

vim start-superset.sh
#!/bin/bash
# Author:Chris                          __On 2021/09/29
# =====================Description=====================
# [Features]: This is for start superset in gunicorn.
# [Usage]: Upload into /data/superset and Exec it:
# =====================================================

# <----------------------------Configure Start--------------------------->
Base=$(cd `dirname ${BASH_SOURCE}` ; pwd)
Config=${Base}/superset_config.py
# <----------------------------Configure  End---------------------------->
cd ${Base}
. bin/activate
[ -f "${Config}" ] && export PYTHONPATH=${Config}

exec gunicorn -w 10 -k gevent --timeout 120 -b  0.0.0.0:8888 --limit-request-line 0 --limit-request-field_size 0 "superset.app:create_app()"
chmod +x start-superset.sh
vim /usr/lib/systemd/system/superset.service
# systemd service file for Superset.
[Unit]
Description=Apache Superset
After=syslog.target
After=network.target
After=nss-lookup.target

[Install]
WantedBy=multi-user.target

[Service]
ExecStart=/data/superset/start-superset.sh
systemctl enable superset.service
systemctl start superset.service
systemctl status superset

配置Nginx

我使用的是Nginx来进行反向代理:

vim bi-tools.conf
# Nginx Second Configure File.
upstream superset {
        server {your-ss-ip}:{ss-port};
}
server {
        listen 80;
        listen 443 ssl;
        server_name superset.yourdomain.com;
        ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
        access_log logs/superset_access.log;
        error_log  logs/superset_error.log;
    location / {
        client_max_body_size 200m;
        proxy_pass http://superset;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
systemctl reload nginx

修改添加superset设置:

vim /data/superset/superset_config.py
...
# Use all X-Forwarded headers when ENABLE_PROXY_FIX is True.
ENABLE_PROXY_FIX = True
systemctl restart superset

 

连接数据库

默认superset只安装了一个自带的sqllite驱动。其它驱动还需要手动集成安装。

数据库驱动

安装所有其它驱动可参见官方文档。这里以常用的MySQL为示例进行安装:

需先编译安装mysql或install mysql-devel包。

cd /data/superset/
. bin/activate
pip install mysqlclient pymysql

重新打开添加数据库页面即可看到MySQL类型:

设置数据URI进行连接测试:

mysql+pymysql://zabbix:[email protected]:3306/zabbix?charset=utf8

发表评论

error: Content is protected !!