How to install Redash on CentOS 6

In this step-by-step guide, we will install and configure Redash on CentOS 6. Redash is an open source software which is used to query, visualize and share data. It can be connected to a number of sources (e.g. MySQL, PostgreSQL, MongoDB etc.) to collect data.

Why Redash?

Redash helps you to make your company data driven.  Using it, dashboard and charts can be created easily and shared across team. This helps to develop a culture inside company which depends on metrics and analytics. The catch here is not to analyse data ‘for sake of it’ and choose the right metrics for analysis.

In God We Trust, All Others Bring Data – W. Edwards Deming

Redash Installation on CentOS 6

Redash provides a provisioning script for Ubuntu 16.04. They also provide images for AWS, Google Compute Cloud and Docker. But, they have  discontinued Amazon Linux AMI support and no provisioning scripts are available for CentOS. If you are running a production environment, it is often advisable to get along with the platform supported by redash.

Since we too like to live dangerously, in this tutorial we will install redash on a newly created CentOS instance. 

Do you pine for the days when men were men and wrote their own device drivers? – Linus Torvalds

Why to install on CentOS 6 when it’s not a supported platform?

Ian: Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should. – Jurassic Park

In This Guide:

Quick Reference

Software versions used in this tutorial:

OSCentOS 6.10
redis4.0.11
postres9.5
python2.7.15
supervisor3.3.4
redash4.0.1.b4038

Architecture Diagram:

Quick Reference:

Redash Quick Reference 
Install Location/opt/redash
Settings File/opt/redash/.env
Starting/stopping Redash serverserver monitored by supervisor
sudo supervisorctl status

Step 1 – System Package Installation

We will install below software packages first:

sudo yum -y install epel-release
sudo yum -y install pwgen gcc-c++ libffi-devel openssl-devel xmlsec1 xmlsec1-openssl freetds freetds-devel
sudo yum -y install mysql-devel

 

Step 2 – Creating Redash User

sudo useradd redash -r -s /sbin/nologin

Step 3 – Redis Installation

sudo yum install -y tcl
cd /tmp/
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
tar xzf redis-4.0.11.tar.gz
cd redis-4.0.11
make
make test 
sudo make install

Execute install script to generate redis config file,  /etc/init.d script, install them and run redis server.

sudo REDIS_PORT=6379 \
     REDIS_CONFIG_FILE=/etc/redis/6379.conf \
     REDIS_LOG_FILE=/var/log/redis_6379.log \
     REDIS_DATA_DIR=/var/lib/redis/6379 \
     REDIS_EXECUTABLE=/usr/local/bin/redis-server ./utils/install_server.sh

Set overcommit_memory to 1 (always overcommit, never check)

sudo sysctl vm.overcommit_memory=1

# to make the change permanent
# open sysctl.conf for editing
sudo vim /etc/sysctl.conf

# add below line
vm.overcommit_memory=1

Redis guidances on why vm.overcommit_memory should be set to 1.

Step 4 – Postgres Installation

Install Postres using rpm :

sudo rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm
sudo yum -y install postgresql95-server postgresql95 libpqxx-devel postgresql-devel

Initialize database environment:

sudo service postgresql-9.5 initdb

Configure it to start at boot up and start the software:

sudo chkconfig postgresql-9.5 on
sudo service postgresql-9.5 start

Step 5 – Supervisor Installation

Python 2.7 installation

sudo yum -y install sqlite-devel zlib zlib-devel gcc httpd-devel bzip2-devel openssl openssl-devel
cd /tmp/
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar zxvf Python-2.7.15.tgz
cd Python-2.7.15
./configure --prefix=/usr/local --with-threads --enable-shared --with-zlib=/usr/include
make
sudo make altinstall

sudo sh -c "echo '/usr/local/lib' >> /etc/ld.so.conf.d/python2.7.conf"
sudo /sbin/ldconfig
sudo ln -sfn /usr/local/bin/python2.7 /usr/bin/python2.7

Pip installation for Python 2.7

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python2.7 get-pip.py
sudo ln -sfn /usr/local/bin/pip2.7 /usr/bin/pip2.7

Supervisor installation

sudo pip2.7 install supervisor

sudo ln -sfn /usr/local/bin/supervisord /usr/bin/supervisord
sudo ln -sfn /usr/local/bin/supervisorctl /usr/bin/supervisorctl

sudo mkdir -p /etc/supervisor/conf.d/

create configuration file

sudo sh -c "/usr/local/bin/echo_supervisord_conf > /etc/supervisord.conf"

config update

sudo vim /etc/supervisord.conf

add below lines:
[include]
files = /etc/supervisor/conf.d/*.conf

start supervisor

sudo /usr/bin/supervisord -c /etc/supervisord.conf

Step 6 – Creating Directories

sudo mkdir -p /opt/redash/
sudo chown redash /opt/redash/

sudo -u redash wget https://raw.githubusercontent.com/getredash/redash/master/setup/ubuntu/files/env -O /opt/redash/.env
COOKIE_SECRET=$(pwgen -1s 32)
sudo sh -c "echo 'export REDASH_COOKIE_SECRET=$COOKIE_SECRET' >> /opt/redash/.env"

Step 7 – Extracting Redash Source

# set variables for current shell
REDASH_BASE_PATH=/opt/redash
REDASH_VERSION=4.0.1.b4038
LATEST_URL="https://s3.amazonaws.com/redash-releases/redash.${REDASH_VERSION}.tar.gz"
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}"
REDASH_TARBALL=/tmp/redash.tar.gz

# run below commands for extracting redash source
sudo -u redash wget "$LATEST_URL" -O "$REDASH_TARBALL"
sudo -u redash mkdir "$VERSION_DIR"
sudo -u redash tar -C "$VERSION_DIR" -xvf "$REDASH_TARBALL"
sudo -u redash ln -nfs "$VERSION_DIR" $REDASH_BASE_PATH/current
sudo -u redash ln -nfs $REDASH_BASE_PATH/.env $REDASH_BASE_PATH/current/.env

Step 8 – Creating virtual environment

installing virtualenv

sudo pip2.7 install virtualenv
sudo ln -sfn /usr/local/bin/virtualenv /usr/bin/virtualenv2.7

creating virtual environment in redash version directory

REDASH_VERSION=4.0.1.b4038
sudo -u redash virtualenv2.7 --no-site-packages /opt/redash/redash.${REDASH_VERSION}/venv/

Step 9 – Installing Python Packages

We will install the python packages in virtual environment created in venv directory inside redash.

# set variable for current shell
REDASH_BASE_PATH=/opt/redash
REDASH_VERSION=4.0.1.b4038

# run below commands
sudo -u redash $REDASH_BASE_PATH/redash.$REDASH_VERSION/venv/bin/pip install --cache-dir $REDASH_BASE_PATH/cache/pip --upgrade pip
sudo -u redash $REDASH_BASE_PATH/redash.$REDASH_VERSION/venv/bin/pip install --cache-dir $REDASH_BASE_PATH/cache/pip setproctitle
sudo -u redash $REDASH_BASE_PATH/redash.$REDASH_VERSION/venv/bin/pip install --cache-dir $REDASH_BASE_PATH/cache/pip -r $REDASH_BASE_PATH/redash.$REDASH_VERSION/requirements.txt
sudo -u redash $REDASH_BASE_PATH/redash.$REDASH_VERSION/venv/bin/pip --cache-dir $REDASH_BASE_PATH/cache/pip install -r $REDASH_BASE_PATH/redash.$REDASH_VERSION/requirements_all_ds.txt

Step 10 – Creating Database

creating database

sudo -u postgres createuser redash --no-superuser --no-createdb --no-createrole
sudo -u postgres createdb redash --owner=redash

creating redash tables

sudo -u redash bash
cd /opt/redash/current
source venv/bin/activate
bin/run ./manage.py database create_tables
deactivate
exit

Step 11 – Supervisor Installation

# set variables for current shell
FILES_BASE_URL=https://raw.githubusercontent.com/getredash/redash/master/setup/ubuntu/files

# download config file
sudo wget -O /etc/supervisor/conf.d/redash.conf "$FILES_BASE_URL/supervisord.conf"

# change path for gunicorn and celery to /opt/redash/current/venv/bin/gunicorn and /opt/redash/current/venv/bin/celery (3 places)

# stop supervisor if already running
sudo supervisorctl shutdown

# start supervisor with new config
sudo supervisord -c /etc/supervisord.conf

# checking status
sudo supervisorctl status

Step 12 – nginx Installation & Configuration

installation

# nginx installation
sudo vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

sudo yum -y install nginx

starting nginx server

sudo service nginx start

adding configuration file for redash

# remove default nginx config file
sudo rm /etc/nginx/conf.d/default.conf

# set variables for current shell 
FILES_BASE_URL=https://raw.githubusercontent.com/getredash/redash/master/setup/ubuntu/files

# run below command to download config file from redash server
sudo wget -O /etc/nginx/conf.d/redash.conf "$FILES_BASE_URL/nginx_redash_site"
# restart nginx 
sudo service nginx restart

if you see 502 Bad Gateway erorr on accessing website, check error logs: /var/log/nginx/error.log

2018/09/14 22:50:23 [crit] 4323#4323: *1 connect() to 127.0.0.1:5000 failed 
(13: Permission denied) while connecting to upstream, client: 127.0.0.1, 
server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "localhost"

To fix this:

sudo setsebool -P httpd_can_network_connect 1

Access site again and it should show redash webpage now.

Upgrading Redash

Download latest version

# set variables for current shell 
# update REDASH_VERSION to latest that needs to be installed
REDASH_BASE_PATH=/opt/redash 
REDASH_VERSION=4.0.1.b4038 
LATEST_URL="https://s3.amazonaws.com/redash-releases/redash.${REDASH_VERSION}.tar.gz" 
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}" 
REDASH_TARBALL=/tmp/redash.tar.gz

# run below commands
sudo -u redash wget "$LATEST_URL" -O $REDASH_TARBALL
sudo -u redash mkdir $VERSION_DIR
sudo -u redash tar -C $VERSION_DIR -xvf $REDASH_TARBALL

create virtual environment

REDASH_BASE_PATH=/opt/redash 
REDASH_VERSION=4.0.1.b4038 
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}"

sudo -u redash virtualenv2.7 --no-site-packages $VERSION_DIR/venv/

install dependencies

# set variable for current shell
REDASH_BASE_PATH=/opt/redash
REDASH_VERSION=4.0.1.b4038
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}"

# run below commands
sudo -u redash $VERSION_DIR/venv/bin/pip install --cache-dir $REDASH_BASE_PATH/cache/pip --upgrade pip
sudo -u redash $VERSION_DIR/venv/bin/pip install --cache-dir $REDASH_BASE_PATH/cache/pip setproctitle
sudo -u redash $VERSION_DIR/venv/bin/pip install --cache-dir $REDASH_BASE_PATH/cache/pip -r $VERSION_DIR/requirements.txt
sudo -u redash $VERSION_DIR/venv/bin/pip --cache-dir $REDASH_BASE_PATH/cache/pip install -r $VERSION_DIR/requirements_all_ds.txt

link .env file

REDASH_BASE_PATH=/opt/redash 
REDASH_VERSION=4.0.1.b4038
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}"

sudo -u redash ln -nfs $REDASH_BASE_PATH/.env $VERSION_DIR/.env

run migrations (if any)

REDASH_BASE_PATH=/opt/redash 
REDASH_VERSION=4.0.1.b4038
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}"

sudo -u redash bash
cd $VERSION_DIR
source venv/bin/activate
bin/run ./manage.py db upgrade
deactivate
exit

update symlink

REDASH_BASE_PATH=/opt/redash 
REDASH_VERSION=4.0.1.b4038
VERSION_DIR="$REDASH_BASE_PATH/redash.${REDASH_VERSION}"

sudo -u redash ln -nfs $VERSION_DIR $REDASH_BASE_PATH/current

restart supervisor

sudo supervisorctl restart all

 

Few other resources and references:

Leave a Comment