Superset系列2-CentOS7安装Superset

一. 安装miniconda3

Superset安装需要Python 3.7及以上版本,而CentOS自带的是Python 2.7版本, yum需要使用Python 2.7,所以需要同时安装Python 3版本和Python 2版本。此时可以借助miniconda3来同时安装Python 3版本和Python 2版本。

1.1 下载及安装miniconda3

下载

cd /home/software
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

安装

bash Miniconda3-latest-Linux-x86_64.sh
  1. 直接按回车


    image.png
  2. 出现More 情况 ,按空格


    image.png
  3. 输入yes


    image.png
  4. 在安装过程中,出现以下提示时,可以指定安装路径,不指定会默认安装到自己用户下的目录
    下面这个目录不能是已存在的目录


    image.png
  5. 输入yes


    image.png
  6. 出现如下,代表安装成功


    image.png

1.2 加载环境变量

source ~/.bashrc

之后会出现如下字样 ,发现命令行前面有个base


image.png

如果你不希望conda的基本环境在启动时被激活,设置auto_activate_base参数为false:
命令如下:

conda config --set auto_activate_base false

之后再次重新打开一个端口
则解决


image.png

二. 创建 Python3.7 环境

一般来讲使用base 环境是直接可以操作python3.7的,为了学习一下conda国内镜像,

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

2)创建 Python3.7 环境

conda create --name superset python=3.7

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

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

3)激活 superset 环境

conda activate superset
  1. 执行 python 命令查看 python 版本


    image.png

三. 安装Superset

  1. 安装依赖
yum install -y gcc gcc-c++ libffi-devel python-devel python-pip python-wheel python-setuptools openssl-devel cyrus-sasl-devel openldap-devel
  1. 安装(更新)setuptools 和 pip
pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
image.png
  1. 安装 Supetset
pip install apache-superset -i https://pypi.douban.com/simple/
  1. 初始化 Supetset 数据库
superset db upgrade
  1. 创建管理员账号
export FLASK_APP=superset
superset fab create-admin
image.png
  1. Superset 初始化
superset init
image.png

四. Superset 启动

  1. 安装 gunicorn
pip install gunicorn -i https://pypi.douban.com/simple/
image.png

2)启动

gunicorn --workers 5 --timeout 120 --bind 10.31.1.119:8787 "superset.app:create_app()" --daemon

说明:
–workers:指定进程个数
–timeout:worker 进程超时时间,超时会自动重启
–bind:绑定本机地址,即为 Superset 访问地址
–daemon:后台运行

访问 http://10.31.1.119:8787/ 并使用 安装直接的管理员账号密码进入即可


image.png

image.png
  1. 停止 superset
    停掉 gunicorn 进程
ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9

退出 superset 环境

conda deactivate

五.superset 启停脚本

5.1 脚本内容

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() {
    source ~/.bashrc
    superset_status >/dev/null 2>&1
    if [[ $? -eq 0 ]]; then
        conda activate superset; gunicorn --workers 5 --timeout 120 --bind 10.31.1.119: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

5.2 加执行权限

chmod +x superset.sh

5.3 测试

sh superset.sh start
sh superset.sh stop

参考:

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

你可能感兴趣的:(Superset系列2-CentOS7安装Superset)