Install and Config Redis Server on CentOS Linux
Install and Config Redis Server Intro:
In this tutorial, we will look into the Installation and configuration of Redis NoSQL Server ( Install and Config Redis Server ). We will also discuss running Redis on External interfaces and Connect external Applications to Redis server and Whitelist the External IP addresses using IP Tables.
Lets start with the installation of Redis server, Then we will go through the config process of Redis.
REDIS Installation:
Redis Server is available under EPEL repositories, So, first of all, add the EPEL repository to CentOS.
1 |
yum install epel-release |
Now update the yum cache and install the REDIS Server using the following yum command.
1 2 |
yum update yum install redis |
Redis Configuration File is located at /etc/redis.conf
Starting and Stopping the REDIS server :
Starting :
1 |
systemctl start redis.service |
Stopping:
1 |
systemctl stop redis.service |
Restarting :
1 |
systemctl restart redis.service |
Test the Installation:
Let’s check if the Redis server is up and running using following ps command.
1 |
ps -ef | grep redis |
Output :
1 2 3 4 |
[root@test test]# ps -ef | grep redis redis 7516 1 0 13:35 ? 00:00:00 /usr/bin/redis-server 0.0.0.0:6379 root 7523 1227 0 13:35 pts/0 00:00:00 grep --color=auto redis [root@test test]# |
We can also test the Redis server connection using redis-cli ( Redis Command line interface client )
The following command will send the ping message to REDIS server. If the server responds with PONG ., Then your installation is successful.
1 2 |
redis-cli ping PONG |
Running Redis on External IP Address or on All Interfaces :
1 2 3 |
vim /etc/redis.conf bind XXX.XXX.XXX.XXX |
Change the bind IP Address to whatever IP you want or Simply specify 0.0.0.0 to listen on all interfaces.
Connect to Remote Redis on IP Address :
1 |
redis-cli -h 19.9.3.11 -p 6379 |
Redis Allow remote connections from SINGLE IP ADDRESS :
Following commands will add one IPTables rule to whitelist the Specified IP Address.
Before doing this, We need to make sure Redis is running on External IP address. So make the following changes in /etc/redis.conf
1 2 3 4 5 6 |
vim /etc/redis.conf #change the bind to 0.0.0.0 ---> to listen on all Interfaces bind 0.0.0.0 # Change the following parameter to no from yes protected-mode no |
Now whitelist the external IP address using the following command.
1 2 3 4 5 6 7 8 9 10 |
ALLOW_IP_ADDRESS=19.9.3.39 REDIS_PORT=6379 # create a new chain iptables -N redis-protection # allow your IP iptables -A redis-protection --src $ALLOW_IP_ADDRESS -j ACCEPT # drop everyone else iptables -A redis-protection -j DROP # use chain xxx for packets coming to TCP port $REDIS_PORT iptables -I INPUT -m tcp -p tcp --dport $REDIS_PORT -j redis-protection |
Testing Redis Server connection from Remote client :
To connect to the remote Redis Server we need to install the Redis-CLI. Redis-CLI is available under the redis-tools package. So go ahead and install the redis-tools package using the following command.
Ubuntu and Debian users :
1 |
sudo apt-get install redis-tools |
Now Connect to the Remote Redis using the following command.
1 |
redis-cli -h REMOTE_REDIS_SERVER_IP -p PORT |
Example Connection :
1 2 3 4 5 6 |
redis-cli -h 19.59.7.11 19.59.7.11:6379> set venkey Macha OK 19.59.7.11:6379> del venkey (integer) 1 19.59.7.11:6379> |
Conclusion:
We have disussed about the install and config of Redis server and how to configure and run Redis Server on external interface and We also looked at how to connect to Redis NoSQL server from the Remote host.