Superset安装教程

Superset安装及使用

Superset官网地址:http://superset.apache.org/

1 安装Python环境

Superset是由Python语言编写的Web应用,要求Python3.6的环境。

1.1 安装Miniconda

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

此处,我们不需要如此多的工具包,故选择MiniConda。

1)下载Miniconda(Python3版本)

下载地址:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

2)安装Miniconda

(1)执行以下命令进行安装,并按照提示操作,直到安装完成。

bash Miniconda3-latest-Linux-x86_64.sh

(2)在安装过程中,出现以下提示时,可以指定安装路径

image-20210212164642787

(3)出现以下字样,即为安装完成

image-20210212164655598

3)加载环境变量配置文件,使之生效

source ~/.bashrc

4)取消激活base环境

Miniconda安装完成后,每次打开终端都会激活其默认的base环境,我们可通过以下命令,禁止激活默认base环境。

conda config --set auto_activate_base false

1.2 创建Python3.6环境

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

2)创建Python3.6环境

conda create --name superset python=3.6

说明:conda环境管理常用命令

创建环境:conda create -n env_name

查看所有环境:conda info --envs

删除一个环境:conda remove -n env_name --all

3)激活superset环境

conda activate superset

激活后效果如下图所示

image-20210212164945988

说明:退出当前环境

conda deactivate

4)执行python命令查看python版本

image-20210212165029277

2 Superset部署

2.1 安装依赖

安装Superset之前,需安装以下所需依赖

(superset) [root@hadoop102 bin]# yum install -y python-setuptools
(superset) [root@hadoop102 bin]# yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel cyrus-sasl-devel openldap-devel

2.2 安装Superset

1)安装(更新)setuptools和pip

(superset) [root@hadoop102 bin]# pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/

说明:pip是python的包管理工具,可以和centos中的yum类比

2)安装Supetset

(superset) [root@hadoop102 bin]# pip install apache-superset -i https://pypi.douban.com/simple/

说明:-i的作用是指定镜像,这里选择国内镜像

3)初始化Supetset数据库

(superset) [root@hadoop102 bin]# superset db upgrade

4)创建管理员用户

(superset) [root@hadoop102 bin]# export FLASK_APP=superset
(superset) [root@hadoop102 ~]$ flask fab create-admin

说明:flask是一个python web框架,Superset使用的就是flask

(superset) [root@hadoop102 bin]# flask fab create-admin
Username [admin]: root    --设置用户名
User first name [admin]: --直接回车
User last name [user]: --直接回车
Email [[email protected]]: --直接回车
Password: --设置密码
Repeat for confirmation: --再次确认密码

5)Superset初始化

(superset) [root@hadoop102 ~]$ superset init

2.3 启动Supterset

1)安装gunicorn

(superset) [root@hadoop102 ~]$ pip install gunicorn -i https://pypi.douban.com/simple/

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

2)启动Superset

第一步:确保当前conda环境为superset,及下图所示

image-20210212165815546

第二步:启动

(superset) [root@hadoop102 ~]$ gunicorn --workers 5 --timeout 120 --bind hadoop102:8787  "superset.app:create_app()" --daemon 

说明:

–workers:指定进程个数

–timeout:worker进程超时时间,超时会自动重启

–bind:绑定本机地址,即为Superset访问地址

–daemon:后台运行

3)停止superset

停掉gunicorn进程

(superset) [root@hadoop102 ~]$ ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9

退出superset环境

(superset) [root@hadoop102 ~]$ conda deactivate

4)superset启停脚本

(1)创建superset.sh文件

[root@hadoop102 bin]$ vim 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="$('/opt/module/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
        if [ $? -eq 0 ]; then
            eval "$__conda_setup"
        else
            if [ -f "/opt/module/miniconda3/etc/profile.d/conda.sh" ]; then
                . "/opt/module/miniconda3/etc/profile.d/conda.sh"
            else
                export PATH="/opt/module/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 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

(2)加执行权限

[root@hadoop102 bin]$ chmod +x superset.sh

(3)测试

启动superset

[root@hadoop102 bin]$ superset.sh start

停止superset

[root@hadoop102 bin]$ superset.sh stop

4)登录Superset

访问http://hadoop102:8787,并使用2.2节中第4步创建的管理员账号进行登录。

image-20210212170142251

猜你喜欢

转载自blog.csdn.net/zmzdmx/article/details/113795591