Apache Superset 安装
一、版本选择
软件名称 | 版本 |
---|---|
Anaconda3 | Anaconda3-5.3.0-Linux-x86_64.sh |
Python | python3.9 |
Superset | 2.1.1 |
二、软件安装
Anaconda3
# 下载链接:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
Python
conda create -n superset_env python==3.9
Superset
(1)安装依赖
# CentOS7
yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel
(2)第一步:切换 superset_env 环境
[root@master bin]$ pwd
/opt/anaconda3/bin
[root@master bin]$
(base) [root@master bin]# source activate superset
(superset) [root@master bin]#
(superset) [root@master bin]# python -V
Python 3.9.0
(3)第二步:安装 superset包
pip install apache-superset==2.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
(4)第三步:安装|替换一些 python包
pip install Werkzeug==2.0.3
pip install typing_extensions==4.2.0
pip install pymysql
pip install Flask-LDAP
pip install marshmallow_enum
pip install pillow
pip install gunicorn
(5)创建配置文件
vim /opt/anaconda3/superset_config.py
from flask_appbuilder.security.manager import AUTH_DB, AUTH_LDAP
# 此参数必须设置,通过命令:【openssl rand -base64 42 】 获取
SECRET_KEY = 'NcTVZLnTIm0lVTYYIG17F41T66D+eShZTfNS2C9bLht2Fnyia2aMwuWZ'
# 默认数据是存在 sqlite里面,正式环境需要存在 mysql 里面,在这里配置
SQLALCHEMY_DATABASE_URI = 'mysql://superset:[email protected]/superset'
# Flask-WTF flag for CSRF
WTF_CSRF_ENABLED = False
# 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 = ''
# 这里配置页面菜单设置为中文
BABEL_DEFAULT_LOCALE = "zh"
# Your application default translation path
BABEL_DEFAULT_FOLDER = "superset/translations"
# The allowed translation for you app
LANGUAGES = {
"en": {"flag": "us", "name": "English"},
"es": {"flag": "es", "name": "Spanish"},
"it": {"flag": "it", "name": "Italian"},
"fr": {"flag": "fr", "name": "French"},
"zh": {"flag": "cn", "name": "Chinese"},
"ja": {"flag": "jp", "name": "Japanese"},
"de": {"flag": "de", "name": "German"},
"pt": {"flag": "pt", "name": "Portuguese"},
"pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
"ru": {"flag": "ru", "name": "Russian"},
"ko": {"flag": "kr", "name": "Korean"},
"sk": {"flag": "sk", "name": "Slovak"},
"sl": {"flag": "si", "name": "Slovenian"},
"nl": {"flag": "nl", "name": "Dutch"},
}
# Turning off i18n by default as translation in most languages are
# incomplete and not well maintained.
# Uncomment to setup Your App name
APP_NAME = "Superset"
# 这里自定义logo图标
# Specify the App icon
APP_ICON = "/static/assets/images/superset-logo-horiz_yszx.png"
# ----------------------------------------------------
# AUTHENTICATION CONFIG
# ----------------------------------------------------
# The authentication type
# AUTH_OID : Is for OpenID
# AUTH_DB : Is for database (username/password)
# AUTH_LDAP : Is for LDAP
# AUTH_REMOTE_USER : Is for using REMOTE_USER from web server
AUTH_TYPE = AUTH_LDAP
# Uncomment to setup Full admin role name
AUTH_ROLE_ADMIN = "Admin"
# Uncomment to setup Public role name, no authentication needed
AUTH_ROLE_PUBLIC = 'Public'
# Will allow user self registration
AUTH_USER_REGISTRATION = True
# The default user self registration role
AUTH_USER_REGISTRATION_ROLE = "Gamma"
# 接入ldap, 这里需要运维配合,提供这些参数
# When using LDAP Auth, setup the LDAP server
AUTH_LDAP_SERVER = "ldap://172.16.204.**:389"
AUTH_LDAP_BIND_USER = "uid=yunwei,ou=People,dc=elements,dc=org,dc=cn"
AUTH_LDAP_BIND_PASSWORD = "****"
AUTH_LDAP_SEARCH = "dc=elements,dc=org,dc=cn"
AUTH_LDAP_UID_FIELD="cn"
AUTH_LDAP_FIRSTNAME_FIELD="givenName"
AUTH_LDAP_LASTTNAME_FIELD="sn"
AUTH_LDAP_USE_TLS = False
# 配置,可以减少一些警告输出
CONTENT_SECURITY_POLICY_WARNING=False
(6)修改文件 sql_parse.py
vim /opt/anaconda3/envs/superset/lib/python3.9/site-packages/superset/sql_parse.py
# 注释掉67行,新增68行
64 sqlparse.keywords.SQL_REGEX.insert(
65 0,
66 (
67 # re.compile(r"'(''|\\\\|\\|[^'])*'", sqlparse.keywords.FLAGS).match,
68 re.compile(r"'(''|\\\\\\\\\\\\\\\\|\\\\\\\\|[^'])*'", (re.IGNORECASE | re.UNICODE)).match,
69 sqlparse.tokens.String.Single,
70 ),
71 )
72
(7)修改文件 mysql.py
vim /opt/anaconda3/envs/superset/lib/python3.9/site-packages/superset/db_engine_specs/mysql.py
# 修改 218 行 MySQLdb 为 pymysql
# 修改 220 行 MySQLdb 为 pymysql
213 @classmethod
214 def get_datatype(cls, type_code: Any) -> Optional[str]:
215 if not cls.type_code_map:
216 # only import and store if needed at least once
217 # pylint: disable=import-outside-toplevel
218 import pymysql # import MySQLdb
219
220 ft = pymysql.constants.FIELD_TYPE # ft = MySQLdb.constants.FIELD_TYPE
221 cls.type_code_map = {
222 getattr(ft, k): k for k in dir(ft) if not k.startswith("_")
223 }
224 datatype = type_code
225 if isinstance(type_code, int):
226 datatype = cls.type_code_map.get(type_code)
227 if datatype and isinstance(datatype, str) and datatype:
228 return datatype
229 return None
(8)修改文件 sql_lab.py
vim /opt/anaconda3/envs/superset/lib/python3.9/site-packages/superset/sql_lab.py
# 修改 363 行: 注释掉363行
# 修改 364 行: 如下
348 def _serialize_and_expand_data(
349 result_set: SupersetResultSet,
350 db_engine_spec: BaseEngineSpec,
351 use_msgpack: Optional[bool] = False,
352 expand_data: bool = False,
353 ) -> Tuple[Union[bytes, str], List[Any], List[Any], List[Any]]:
354 selected_columns = result_set.columns
355 all_columns: List[Any]
356 expanded_columns: List[Any]
357
358 if use_msgpack:
359 with stats_timing(
360 "sqllab.query.results_backend_pa_serialization", stats_logger
361 ):
362 data = (
363 #pa.default_serialization_context()
364 pa.serialize(result_set.pa_table)
365 .to_buffer()
366 .to_pybytes()
367 )
(9)修改文件 mysqldb.py
vim /opt/anaconda3/envs/superset/lib/python3.9/site-packages/sqlalchemy/dialects/mysql/mysqldb.py
# 修改 150 行 MySQLdb 改为 pymysql
148 @classmethod
149 def dbapi(cls):
150 return __import__("pymysql") # return __import__("MySQLdb")
(10)修改文件 lexer.py
vim /opt/anaconda3/envs/superset/lib/python3.9/site-packages/sqlparse/lexer.py
# 修改 79行 rx 改为 str(rx)
75 def set_SQL_REGEX(self, SQL_REGEX):
76 """Set the list of regex that will parse the SQL."""
77 FLAGS = re.IGNORECASE | re.UNICODE
78 self._SQL_REGEX = [
79 (re.compile(str(rx), FLAGS).match, tt)
80 for rx, tt in SQL_REGEX
81 ]
(11)设置环境变量
export PYTHONPATH="/opt/anaconda3/superset_config.py:$PYTHONPATH"
export FLASK_APP=superset
(12)生成mysql数据表
superset db upgrade
(13)创建管理员用户
superset fab create-admin
(14)初始化 Superset
superset init
(15)启动 Superset
gunicorn --workers 5 --timeout 120 --bind ip:8787 "superset.app:create_app()" --daemon
(16)浏览器登录
http://ip:8787/
标签:Superset,name,py,AUTH,flag,LDAP,Apache,superset,安装
From: https://www.cnblogs.com/yzyang/p/18211460