Redis – Predixy Proxy Auto Setup

Here is a shell script I wrote to automate the setup of Predixy Proxy in Centos 7.

This script will work if you have a single endpoint (i.e. AWS Elasticache cluster configuration endpoint or a standalone Elasticache endpoint).

#!/bin/bash

# Created By  : Enrique Valencia 
# Script Name : predixy_auto_setup.sh
# Description : Predixy Automatic Setup

################################################################################################################
# Usage	          : ./auto_predixy_setup.sh <configuration_end_point>"
# Example         : ./auto_predixy_setup.sh dba-redis-test01.bbssxp.clustercfg.apse1.cache.amazonaws.com:6379"
# To Check Status : systemctl status predixy 
# To Start	      : systemctl start predixy
# To Stop		  : systemctl stop predixy
# To Restart	  : systemctl restart predixy
################################################################################################################

################################################################################################################
##### Validate Usage
################################################################################################################

if [ $# -ne 1 ]
then
  echo ""
  echo "************************************************************************************************************"
  echo "Usage:   ./predixy_auto_setup.sh <configuration_end_point>"
  echo ""
  echo "Example: ./predixy_auto_setup.sh dba-redis-test01.bbssxp.clustercfg.apse1.cache.amazonaws.com:6379"
  echo "************************************************************************************************************"
  echo ""
  exit 1
fi

################################################################################################################
##### Variable
################################################################################################################

ENDPOINT=$1

################################################################################################################
##### Install Predixy
################################################################################################################

InstallPredixy(){
	mkdir /predixy_data
	cd /predixy_data
	sudo yum install git -y
	sudo yum install libstdc++-static -y
	yum -y install gcc
	yum -y install gcc-c++ 
	sudo git clone https://github.com/joyieldInc/predixy.git
	cd predixy
	sudo make
	mkdir -p /predixy_data/predixy/log
}

################################################################################################################
##### Cluster
################################################################################################################

cluster(){

cat >> /predixy_data/predixy/conf/cluster.conf << EOF
ClusterServerPool {
	MasterReadPriority 100  # 100 
	# Password sjwkk123456 # redis 
	StaticSlaveReadPriority 0  #  redis slave redis 0
	DynamicSlaveReadPriority 0 #  redis sentinel 0
	RefreshInterval 1 # predixy redis sentinel 1 
	ServerTimeout 1 #  predixy/redis predixy redis blpop 0 redis 0
	ServerFailureLimit 10 #  redis 10
	ServerRetryTimeout 1 #  redis 1 
	KeepAlive 120 #predixy redis tcp keepalive 0 0
	Servers {
	##  
		+ $ENDPOINT
	}
}
EOF

	sed -i 's/Auth "#a complex password#" {/Auth "123456" {/' auth.conf
	sed -i 's/WorkerThreads 1/WorkerThreads 4/' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/# Log .\/predixy.log/Log \/predixy_data\/predixy\/log\/predixy.log/' /predixy_data/predixy/conf/predixy.conf
	sed -i '/# LogRotate 1d 2G/d' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/# LogRotate 1d/LogRotate 1d/' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/Include try.conf/# Include try.conf/' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/# Include cluster.conf/Include cluster.conf/' /predixy_data/predixy/conf/predixy.conf
}


################################################################################################################
##### Standalone
################################################################################################################

standalone(){
	
cat >> /predixy_data/predixy/conf/standalone.conf << EOF

StandaloneServerPool {
	RefreshMethod fixed
	Group shard001 {
		+ $ENDPOINT
	}
}
EOF

	sed -i 's/Auth "#a complex password#" {/Auth "123456" {/' auth.conf
	sed -i 's/WorkerThreads 1/WorkerThreads 4/' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/# Log .\/predixy.log/Log \/predixy_data\/predixy\/log\/predixy.log/' /predixy_data/predixy/conf/predixy.conf
	sed -i '/# LogRotate 1d 2G/d' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/# LogRotate 1d/LogRotate 1d/' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/Include try.conf/# Include try.conf/' /predixy_data/predixy/conf/predixy.conf
	sed -i 's/# Include sentinel.conf/Include standalone.conf/' /predixy_data/predixy/conf/predixy.conf
}

################################################################################################################
##### Setup Predixy as a Systemd Service
################################################################################################################

systemd(){
	echo "/predixy_data/predixy/src/predixy /predixy_data/predixy/conf/predixy.conf" > /usr/sbin/predixy_start.sh

	cat > /etc/systemd/system/predixy.service <<-EOF
	[Unit]
	Description=Predixy

	[Service]
	ExecStart=/bin/bash /usr/sbin/predixy_start.sh


	[Install]
	WantedBy=multi-user.target
	EOF

	sudo chmod 640 /etc/systemd/system/predixy.service
	sudo systemctl daemon-reload
	sudo systemctl enable predixy
}


################################################################################################################
##### Check Predixy Status
################################################################################################################

CheckStatus() {
	if [ `ps -ef | grep predixy.conf | grep -v grep | wc -l` -gt 0 ]; then
		echo ""
		echo "************************************************************************"
		echo "Predixy Setup Completed."
		echo "************************************************************************"
		echo ""
	else
		echo ""
		echo "************************************************************************"
		echo "Predixy Proxy is unable to start. Please check."
		echo "************************************************************************"
		echo ""
		exit 1
	fi
}

################################################################################################################
##### MAIN
################################################################################################################

echo -ne "
Menu: 
=====

1) cluster
2) standalone
3) Exit

Please choose: "

read -r choice

case $choice in

1)
	echo ""
	echo "************************************************************************"
	echo "You chose 1 - Cluster. Starting Predixy Setup."
	echo "************************************************************************"
	echo ""
	sleep 3
	InstallPredixy
	cluster
	systemd
	systemctl start predixy
	sleep 3
	CheckStatus
	;;

2)
	echo ""
	echo "************************************************************************"
	echo "You chose 2 - Standalone. Starting Predixy Setup."
	echo "************************************************************************"
	echo ""
	sleep 3
	InstallPredixy
	standalone
	systemd
	systemctl start predixy
	sleep 3
	CheckStatus
	;;
	
3)
	echo ""
	echo "*********"
	echo "再见"
	echo "*********"
	echo ""
	exit 1
	;;
*)
	echo ""
	echo "************************************************************************"
	echo "Invalid Option. Please try again."
	echo "************************************************************************"
	echo ""
	exit 1
esac

Cheers!

Knowledge worth sharing...Share on linkedin
Linkedin
Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter

Redis – Monitor Redis Using Grafana

In this blog post, I will outline the steps to set up Grafana to monitor your Redis database.

Install Grafana

Go to Grafana website download page.

Example: For Red Hat, CentOS, RHEL, and Fedora(64 Bit).

Execute the following commands to make Grafana start automatically when the server is booted up.

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service

Install Redis Plugin

The Redis Data Source for Grafana is a plugin that allows users to connect to any Redis database On-Premises and in the Cloud. It provides out-of-the-box predefined dashboards and lets you build customized dashboards to monitor Redis and application data.

grafana-cli plugins install redis-datasource

Start Grafana

Start Grafana.

sudo systemctl start grafana-server.service

Check Grafana Status.

sudo systemctl status grafana-server.service

Access Grafana Monitor Dashboard

Paste the server’s IP, plus port 3000 on your web browser to access Grafana Dashboar<Ipd.

<ServerIPaddress>:3000

The initial username and password is admin/admin.

Configure Data source

Go to Configuration > Data sources.

Add data source.

Search for “Redis“, then select the data source below.

Enter a name and address in the following format.

redis://your-redis-endpoint.ng.0001.sae1.cache.amazonaws.com:6379

Click Save and test and verify that the data source is working as expected.

Import Dashboard

This step will be performed one time only.

Go to Dashboards. Then click Import for both Redis and Redis Streaming.

View Dashboard

Go to Dashboard > Manage.

Choose Redis or Redis Streaming.

Knowledge worth sharing...Share on linkedin
Linkedin
Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter