Loading

superset安装

superset安装部署

目录

​ 概述

​ 创建python环境

​ 安装minconda

​ 创建python3.6环境

​ 部署superset

​ 启动superset

​ 编写启动脚本

​ 鸣谢

一、概述

superset是一个开源的、现代的、轻量级BI分析工具,支持多种数据源、拥有丰富的图表展示形式、支持自定义仪表盘
superset能够对接常用的大数据分析工具,如Hive、Kylin、Durid等,支持自定义仪表盘,可作为数仓的可视化工具。

二、创建python环境

1、安装miniconda
conda是一个开源的包、环境管理器,可以用于在一个机器上安装不同python版本的软件包及其依赖,并且能够在不同的python环境之间切换。
Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等,Miniconda包括Conda、Python。我们不需要如此多的工具包,故选择MiniConda。

1)下载miniconda

注:最终super需要以普通用户启动,所以先切换到普通用户,以普通用户安装minconda

[root@znjc-ds-hxfwserv ~]# su hzyyg
[hzyyg@znjc-ds-hxfwserv root]$
[hzyyg@znjc-ds-hxfwserv root]$ cd 
[hzyyg@znjc-ds-hxfwserv ~]$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 
[hzyyg@znjc-ds-hxfwserv ~]$ bash Miniconda3-latest-Linux-x86_64.sh

视情况按回车或者输入yes

安装完成以后加载环境变量

注:启动会话窗口会进入到base环境,需要禁止激活base环境

[hzyyg@znjc-ds-hxfwserv ~]$ source ~/.bashrc
(base) [hzyyg@znjc-ds-hxfwserv ~]$ conda config --set auto_activate_base false
[hzyyg@znjc-ds-hxfwserv ~]$ 
2、创建python3.6环境

配置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

创建python3.6

conda create --name superset python=3.6

注:创建环境:conda create -n env_name python=3.6
查看所有环境:conda info --envs
删除一个环境:conda remove -n env_name --all

查看conda中环境信息,存在基础环境以及刚创建的superset环境

[hzyyg@znjc-ds-hxfwserv ~]$ python3 -V
Python 3.6.8
[hzyyg@znjc-ds-hxfwserv ~]$ conda info --envs
# conda environments:
#
base                  *  /home/hzyyg/miniconda3
superset                 /home/hzyyg/miniconda3/envs/superset

[hzyyg@znjc-ds-hxfwserv ~]$ 

切换到superset环境

[hzyyg@znjc-ds-hxfwserv ~]$ conda activate superset 
(superset) [hzyyg@znjc-ds-hxfwserv ~]$ 

以下用于退出miniconda环境

(superset) [hzyyg@znjc-ds-hxfwserv ~]$ conda deactivate
[hzyyg@znjc-ds-hxfwserv ~]$

三、部署superset

安装相关依赖包

(superset) [hzyyg@znjc-ds-hxfwserv ~]$  sudo yum install -y python-setuptools gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel

可以更新一下setuptools

pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/

安装superset

(superset) [hzyyg@znjc-ds-hxfwserv ~]$ pip install apache-superset -i https://pypi.douban.com/simple/
或者
(superset) [hzyyg@znjc-ds-hxfwserv ~]$ pip install apache-superset --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple

(superset) [hzyyg@znjc-ds-hxfwserv ~]$ pip3 install sqlalchemy==1.3.24 -i https://pypi.douban.com/simple/
(superset) [hzyyg@znjc-ds-hxfwserv ~]$ pip3 install dataclasses -i https://pypi.douban.com/simple/

初始化数据库

(superset) [hzyyg@znjc-ds-hxfwserv ~]$ superset db upgrade

创建管理员账号

注:superset使用的是flask,flask是一个python web框架

 (superset) [hzyyg@znjc-ds-hxfwserv ~]$ export FLASK_APP=superset
 (superset) [hzyyg@znjc-ds-hxfwserv ~]$ flask fab create-admin

注:有提示输入的地方直接回车跳过

初始化superset

 (superset) [hzyyg@znjc-ds-hxfwserv ~]$ superset init
启动superset

安装gunicorn

注:gunicorn是一个Python Web Server,可以和java中的TomCat类比

 (superset) [hzyyg@znjc-ds-hxfwserv ~]$ pip install gunicorn -i https://pypi.douban.com/simple/

启动superset

注:

  • –workers:指定进程个数
  • –timeout:worker进程超时时间,超时会自动重启
  • –bind:绑定本机地址,即为superset访问地址
  • –daemon:后台运行
 (superset) [hzyyg@znjc-ds-hxfwserv ~]$ gunicorn --workers 5 --timeout 120 --bind 192.168.1.133:8787  "superset.app:create_app()" --daemon

安装mysql驱动

注:驱动安装方式参考官网https://superset.apache.org/docs/databases/installing-database-drivers/

 (superset) [hzyyg@znjc-ds-hxfwserv ~]$ conda install mysqlclient

数据源url

注:例子

mysql://账号:密码@IP:端口/数据库名?charset=utf8
mysql://root:XXXXXXXXXX@192.168.1.110:3306/data?charset=utf8

image-20220823110834744

重启

[hzyyg@znjc-ds-hxfwserv ~]$ cd /home/hzyyg/miniconda3
[hzyyg@znjc-ds-hxfwserv miniconda3]$ ./superset.sh restart
启动脚本
[hzyyg@znjc-ds-hxfwserv miniconda3]$ vim superset.sh
[hzyyg@znjc-ds-hxfwserv miniconda3]$ chmod +x superset.sh
[hzyyg@znjc-ds-hxfwserv miniconda3]$ cat superset.sh 
#!/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(){
        # 该段内容取自~/.bashrc,所用是进行conda初始化
        # >>> conda initialize >>>
        # !! Contents within this block are managed by 'conda init' !!
        __conda_setup="$('/home/hzyyg/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
        if [ $? -eq 0 ]; then
            eval "$__conda_setup"
        else
            if [ -f "/home/hzyyg/miniconda3/etc/profile.d/conda.sh" ]; then
                . "/home/hzyyg/miniconda3/etc/profile.d/conda.sh"
            else
                export PATH="/home/hzyyg/miniconda3/bin:$PATH"
            fi
        fi
        unset __conda_setup
        # <<< conda initialize <<<
        superset_status >/dev/null 2>&1
        if [[ $? -eq 0 ]]; then
            conda activate superset ; gunicorn --workers 5 --timeout 120 --bind 192.168.1.133: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

鸣谢

Installing Database Drivers | Superset (apache.org)

https://blog.csdn.net/weixin_45417821/article/details/119908752

https://blog.csdn.net/BoomLee/article/details/124174214

posted @ 2022-08-23 14:44  萝卜青菜~  阅读(563)  评论(0编辑  收藏  举报