Superset installation and use
Superset official website address: http://superset.apache.org/
1 Install the Python environment
Superset is a web application written in Python language and requires Python 3.6 environment.
1.1 Install Miniconda
Conda is an open source package and environment manager that can be used to install packages of different Python versions and their dependencies on the same machine, and switch between different Python environments. Anaconda includes Conda, Python, and a bunch of them. Installed toolkits, such as: numpy, pandas, etc. Miniconda includes Conda, Python.
Here, we don't need so many kits, so choose MiniConda.
1) Download Miniconda (Python3 version)
Download address: https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
2) Install Miniconda
(1) Execute the following command to install, and follow the prompts until the installation is complete.
bash Miniconda3-latest-Linux-x86_64.sh
(2) During the installation process, when the following prompt appears, you can specify the installation path
(3) When the following words appear, the installation is complete
3) Load the environment variable configuration file to make it effective
source ~/.bashrc
4) Deactivate the base environment
After Miniconda is installed, its default base environment will be activated every time you open the terminal. We can disable the activation of the default base environment through the following command.
conda config --set auto_activate_base false
1.2 Create a Python3.6 environment
1) Configure conda domestic mirror
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) Create a Python3.6 environment
conda create --name superset python=3.6
Description: Common commands for conda environment management
Create an environment: conda create -n env_name
View all environments: conda info --envs
Remove an environment: conda remove -n env_name --all
3) Activate the superset environment
conda activate superset
After activation, the effect is as shown in the following figure
Description: Exit the current environment
conda deactivate
4) Execute the python command to check the python version
2 Superset deployment
2.1 Install dependencies
Before installing Superset, you need to install the following required dependencies
(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 Install Superset
1) Install (update) setuptools and pip
(superset) [root@hadoop102 bin]# pip install --upgrade setuptools pip -i https://pypi.douban.com/simple/
Description: pip is a package management tool for python, which can be compared to yum in centos
2) Install Supetset
(superset) [root@hadoop102 bin]# pip install apache-superset -i https://pypi.douban.com/simple/
Description: The role of -i is to specify the mirror, here is the domestic mirror
3) Initialize the Supetset database
(superset) [root@hadoop102 bin]# superset db upgrade
4) Create admin user
(superset) [root@hadoop102 bin]# export FLASK_APP=superset
(superset) [root@hadoop102 ~]$ flask fab create-admin
Description: flask is a python web framework, Superset uses 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 initialization
(superset) [root@hadoop102 ~]$ superset init
2.3 Start Supterset
1) Install gunicorn
(superset) [root@hadoop102 ~]$ pip install gunicorn -i https://pypi.douban.com/simple/
Description: gunicorn is a Python Web Server, which can be compared to TomCat in java
2) Start Superset
Step 1: Make sure that the current conda environment is superset, as shown in the following figure
Step 2: Start
(superset) [root@hadoop102 ~]$ gunicorn --workers 5 --timeout 120 --bind hadoop102:8787 "superset.app:create_app()" --daemon
illustrate:
--workers: specify the number of processes
--timeout: the timeout period of the worker process, the timeout will automatically restart
–bind: bind the local address, which is the Superset access address
--daemon: run in the background
3) stop superset
Stop the gunicorn process
(superset) [root@hadoop102 ~]$ ps -ef | awk '/superset/ && !/awk/{print $2}' | xargs kill -9
Exit the superset environment
(superset) [root@hadoop102 ~]$ conda deactivate
4) superset start and stop script
(1) Create the superset.sh file
[root@hadoop102 bin]$ vim superset.sh
The content is as follows
#!/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) Add execute permission
[root@hadoop102 bin]$ chmod +x superset.sh
(3) Test
start superset
[root@hadoop102 bin]$ superset.sh start
stop superset
[root@hadoop102 bin]$ superset.sh stop
4) Log in to Superset
Visit http://hadoop102:8787 and log in with the administrator account created in step 4 in Section 2.2.