Apache Superset
是一个现代的数据探索和可视化平台。它功能强大且十分易用,可对接各种数据源,包括很多现代的大数据分析引擎,拥有丰富的图表展示形式,并且支持自定义仪表盘,且Superset
是由Python
语言编写的Web
应用,要求Python3.7
以上的环境
Superset官网地址: http://superset.apache.org/
bash Miniconda3-latest-Linux-x86_64.sh
## 安装解析
[root@hadoop102 software]# bash Miniconda3-latest-Linux-x86_64.sh
Welcome to Miniconda3 py39_4.12.0
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> (这里一直回车,直到出现询问你yes or no)
Do you accept the license terms? [yes|no]
[no] >>>
Please answer 'yes' or 'no':'
>>>
Please answer 'yes' or 'no':'
>>> (这里输入yes)yes
Miniconda3 will now be installed into this location:
/root/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/miniconda3] >>>(这里指定安装路径) /opt/module/miniconda3
Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> (这里选择yes) yes
## 安装成功标志
Thank you for installing Miniconda3!
## 加载环境变量使其生效
source ~/.bashrc
## 取消激活base环境
# Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。
conda config --set auto_activate_base false
## 创建Python3.8环境
# 配置conda国内镜像(此处可不配置,国外镜像比清华镜像更快,若配置了也可以删除)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --set show_channel_urls yes
# 查看conda的镜像channel配置
conda config --show channels
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- defaults
# 删除清华镜像,继续用默认的
conda config --remove-key channels
conda config --show channels
- defaults
# 创建Python3.8环境(安装过程选y即可)
conda create --name superset python=3.8.16
说明:conda环境管理常用命令
创建环境:conda create -n env_name
查看所有环境:conda info --envs
删除一个环境:conda remove -n env_name --all
## 激活superset环境
conda activate superset
## 激活成功结果
(superset) [root@hadoop102 software]#
## 执行python -V命令查看python版本(Python 3.8.16)
python -V
## 退出当前环境
conda deactivate
## 激活superset环境
conda activate superset
## 安装依赖
sudo yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel
## 安装Superset
# 更新pip
pip install --upgrade pip -i https://pypi.douban.com/simple/
# 安装Supetset
# 上传base.txt文件至任意路径
# 该文件可用于指定superset依赖组件及版本,下载地址如下:
https://raw.githubusercontent.com/apache/superset/2.0.0/requirements/base.txt
# 在base.txt所在目录下执行如下命令,安装SuperSet
pip install apache-superset==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple -r /opt/module/miniconda3/base.txt
# 说明:
-i 的作用是指定镜像,这里选择国内镜像
-r 的作用是指定superset依赖组件及相应版本,指向base.txt文件即可
## 配置Superset元数据库
# Superset的元数据支持MySQL、PostgreSQL,此处采用MySQL。
# 在MySQL中创建superset元数据库
mysql -u root -p000000
CREATE DATABASE superset DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
create user superset@'%' identified WITH mysql_native_password BY 'superset';
grant all privileges on *.* to superset@'%' with grant option;
flush privileges;
exit;
# 修改superset配置文件 => 修改内容如下:(184、185行)
vim /opt/module/miniconda3/envs/superset/lib/python3.8/site-packages/superset/config.py
# SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(DATA_DIR, "superset.db")
SQLALCHEMY_DATABASE_URI = 'mysql://superset:superset@hadoop102:3306/superset?charset=utf8'
# 安装python msyql驱动
conda install mysqlclient
# 初始化superset元数据(一定要在根目录下初始化)/opt/module/miniconda3/envs/superset
export FLASK_APP=superset
superset db upgrade
## SupersetSet初始化
# 创建管理员用户(自己随意设置信息)
superset fab create-admin
# 初始化superset
superset init
## 安装gunicorn --gunicorn是一个Python Web Server,可以和java中的TomCat类比
pip install gunicorn -i https://pypi.douban.com/simple/
## 启动Superset
# 确保当前conda环境为superset,及下图所示
# 启动
gunicorn --workers 5 --timeout 120 --bind hadoop102:8787 "superset.app:create_app()" --daemon
说明:
--workers:指定进程个数
--timeout:worker进程超时时间,超时会自动重启
--bind:绑定本机地址,即为Superset访问地址
--daemon:后台运行
# 登录Superset -- 使用你自己创建的管理员账号进行登录
**访问:** http://hadoop102:8787
vim superset.sh
# 加权限
chmod 777 ./superset.sh
# 使用
superset.sh start
superset.sh stop
#!/bin/bash
superset_status(){
result=`ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | wc -l`
if [[ $result -eq 0 ]]; then
return 0
else
return 1
fi
}
superset_start(){
source ~/.bashrc
superset_status >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
conda activate superset ; gunicorn --workers 5 --timeout 120 --bind hadoop102:8787 --daemon 'superset.app:create_app()'
else
echo "superset正在运行"
fi
}
superset_stop(){
superset_status >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "superset未在运行"
else
ps -ef | awk '/gunicorn/ && !/awk/{print $2}' | xargs kill -9
fi
}
case $1 in
start )
echo "启动Superset"
superset_start
;;
stop )
echo "停止Superset"
superset_stop
;;
restart )
echo "重启Superset"
superset_stop
superset_start
;;
status )
superset_status >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "superset未在运行"
else
echo "superset正在运行"
fi
esac
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。