redis Archives - The Linux GURUS https://thelinuxgurus.com/tag/redis/ Learn Linux & DevOPS from THE LINUX GURUS Tue, 26 Jan 2021 15:43:49 +0000 en-US hourly 1 https://i0.wp.com/thelinuxgurus.com/wp-content/uploads/2020/01/cropped-thelinuxgurus_transparent_name.png?fit=32%2C32&ssl=1 redis Archives - The Linux GURUS https://thelinuxgurus.com/tag/redis/ 32 32 148921671 Simple guide to secure Redis Installation https://thelinuxgurus.com/simple-guide-to-secure-redis-installation/ https://thelinuxgurus.com/simple-guide-to-secure-redis-installation/#respond Tue, 26 Jan 2021 15:43:49 +0000 https://thelinuxgurus.com/?p=1307 In our previous tutorial, we learned how we can install Redis on the Ubuntu server & CentOS/RHEL server. But if we leave the installed Redis...

The post Simple guide to secure Redis Installation appeared first on The Linux GURUS.

]]>
In our previous tutorial, we learned how we can install Redis on the Ubuntu server & CentOS/RHEL server. But if we leave the installed Redis service to default state i.e. with default configurations, it might be susceptible to intrusions. So we should know how we can secure the Redis installation to avoid unauthorized access or operations on our Redis server.

There are a number of things we can do to secure the Redis installation. We will now list them down one by one.

Recommended Read: How to setup Redis replication in Linux

Also Read: How to Host Multiple Websites with Nginx in Linux


Secure Redis Installation

 

1- Create a password to connect to Redis

By default, we are not required to enter any password to connect to the Redis server. But we can create a password in order to connect to Redis instance. All we have to do is to open the Redis configuration file,

$ sudo vim /etc/redis/redis.conf

& then look for the commented section that says “requirepass”, uncomment it & mention a password after that, like

requirepass password@1234

Now save the file & restart the redis service to implement the changes made,

$ sudo systemctl restart redis

Now to connect to redis instance, we first need to run,

$ redis-cli

& then we have to run the following command,

127.0.0.1:6379> auth password@1234

Now we will be able to run the redis commands in the redis-cli.

 

2- Renaming some dangerous commands

There are certain commands that have extremely devastating results, like FLUSHDB, FLUSHALL, KEYS, DEL, CONFIG, SHUTDOWN, BGREWRITEAOF, BGSAVE, SAVE, RENAME, DEBUG, etc. There are many other commands but these can do some serious damage. 

So we can do two things here, if we are using a command regularly we can rename it something that will be hard to guess or we can just disable a command completely if it’s not required.

To rename a command, open configuration file,

$ sudo vi /etc/redis/redis.conf

& add the following line,

rename-command FLUSHALL “DELETEALL”

Now restart the redis service to make changes. Now the command ‘FLUSHALL’ command will not work at all & we will be required to use ‘DELETEALL’ to use that. 

Now to completely disable a command, open the configuration file & add the following line,

rename-command FLUSHALL “”

Restart the service to apply changes & after that, FLUSHALL command will be completely disabled.

 

3- Allow connections from localhost only

By default, redis connections from only local systems are allowed. So if you have not allowed connections from remote systems, then you are not needed to make any changes. But if you have allowed remote connections, you can make the following changes to revert that.

Open redis configuration file,

$ sudo vi /etc/redis/redis.conf

& change the section starting with ‘bind’ to,

bind 127.0.0.1

Restart the service to apply changes.

These were some changes we can make to secure the Redis installation. If you have any questions or concerns, you can connect to us using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Simple guide to secure Redis Installation appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/simple-guide-to-secure-redis-installation/feed/ 0 1307
How to setup Redis replication in Linux https://thelinuxgurus.com/how-to-setup-redis-replication-in-linux/ https://thelinuxgurus.com/how-to-setup-redis-replication-in-linux/#respond Wed, 06 Jan 2021 17:14:09 +0000 https://thelinuxgurus.com/?p=1289 One of the features that make REDIS a good caching application is the ability to configure a cluster with one master/primary & one or more...

The post How to setup Redis replication in Linux appeared first on The Linux GURUS.

]]>
One of the features that make REDIS a good caching application is the ability to configure a cluster with one master/primary & one or more slaves/secondary servers. In this tutorial, we will learn to set up redis replication in our Linux servers.

For the purpose of this tutorial, we will be creating a single Primary & a single secondary server. So let’s discuss the pre-requisites for setting up redis replication.

Recommended Read: How to create a free SSL certificate using Let’s Encrypt in Linux

Also Read: How to Schedule a Shutdown in Linux using Crontab?


Pre-Requisites

2 servers with Redis installed, one will act as the Primary server (10.10.10.10 IP address for our scenario) & another will act as the Secondary server (IP address 10.10.10.11 ).

You can read the following tutorials to install Redis in Ubuntu or in CentOS/RHEL. 

Now let’s move on to the configuration part.


Configuring the Redis replication

Primary Server

First, we will start with the Primary server & will configure it. Open the redis configuration file on the primary server. 

Depending on how you have installed it, the configuration file can be ‘/etc/redis/redis/conf’ or ‘/etc/redis/6379.conf’,

$ sudo vi /etc/redis/redis.conf

& look for ‘append’ & ‘appendfilename’, then change it to following,

appendonly yes

appendfilename “appendonly.aof​”

Now restart the redis service to implement the changes made,

$ sudo systemctl restart redis

OR

$ sudo systemctl restart redis_6379 

Now let’s move on to configuring the secondary server.


Secondary Server

Open the redis configuration file on the secondary server, 

$ sudo vi /etc/redis/redis.conf

& look for ‘slaveof’ & change it to following,

slaveof 10.10.10.10 6379

here, ‘10.10.10.10’ is the IP address for the Primary redis server. & ‘6379’ is the port number for redis on that server.  Once changes have been done, restart the service to implement changes,

$ sudo  systemctl restart redis

OR

$ sudo systemctl restart redis_6379

That’s it our setup for redis replication is complete, we will now verify it.


Checking the replication

To check if the master-slave setup is working, connect to the master redis instance using the following command,

$ redis-cli -h 10.10.10.10 -p 6379

 

& run command ‘info’,

10.10.10.10:6379> info

 

We will get the following output, here look for ‘replication’,

# Replication

role:master

connected_slaves:1

Slave0:

ip=10.10.10.11,

port=6379,

state=online,

offset=215,

lag=0

master_repl_offset:215

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:214

 

Here we can see the IP address for the secondary server i.e. 10.10.10.11, also it shows the number of secondary servers i.e. 1.  

We can also try adding a key on the Primary server, that will be replicated to the secondary server in real-time. To create a test key-value, login to redis instance & execute the following command,

10.10.10.10:6379> set test “testing”

 

now to check the key on the master, run command ‘get test’

10.10.10.10:6379> get test “testing”

 

Now, login to slave server & check if the key ‘test’ has been replicated or not,

$ redis-cli -h 10.10.10.11 -p 6379

 

& run ‘get test’ command,

10.10.10.11:6379> get test “testing”

 

This shows that the key has been replicated to the slave server as well & our master-slave data replication is working fine.


Promoting Secondary server as Primary

So in case, the Primary server fails or there is any other issue, we can promote the secondary server as the primary server. To do this connect to the redis instance of the secondary server,

$ redis-cli -h 10.10.10.11 -p 6379

& execute the following command,

10.10.10.11:6379> SLAVEOF NO ONE

Now the secondary server will act as the primary server. You will be required to update the IP address of redis to the application where you have configured it.

Also if there is more than one redis secondary server, then you are required to update the field,

slaveof 10.10.10.11 6379

on all the secondary servers to point to a new primary server.


Reconnecting to Original Primary server

Once the original primary server is up, we can then reconnect the secondary server to the primary server by the following method, connect to the redis instance of the secondary server,

$ redis-cli -h 10.10.10.11 -p 6379

& execute the following command,

10.10.10.11:6379> SLAVEOF 10.10.10.10 6379

That’s it, this was our tutorial on how setup Redis Replication in Linux. Please do send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to setup Redis replication in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-setup-redis-replication-in-linux/feed/ 0 1289
Install Redis on CentOS / RHEL https://thelinuxgurus.com/install-redis-on-centos-rhel/ https://thelinuxgurus.com/install-redis-on-centos-rhel/#respond Mon, 14 Dec 2020 15:42:45 +0000 https://thelinuxgurus.com/?p=1268 Redis is an open-source in-memory key-value data structure store that can be used as a cache server, message broker, etc. We can use a number...

The post Install Redis on CentOS / RHEL appeared first on The Linux GURUS.

]]>
Redis is an open-source in-memory key-value data structure store that can be used as a cache server, message broker, etc. We can use a number of data types with redis like strings, lists, maps, sets, sorted sets, HyperLogs, bitmaps, streams, and spatial indexes.

It also provides a number of features like,

  • Replication
  • data persistence
  • LRU eviction
  • High availability using sentinel
  • Publish / Subscribe support for data
  • Keys with limited TTL
  • Automatic Failover
  • LUA scripting, etc

Recommended Read: Install Redis on Ubuntu

Also Read: How to Host Multiple Websites with Nginx in Linux

So let’s start the process to install Redis on CentOS or RHEL.


Install Redis on CentOS

Redis packages are available on EPEL repository, so we are required to install the EPEL repository on our CentOS/ RHEL system first. Install it with the following command,

# yum install epel-release

Once the epel repository has been installed, we can install redis with the following command,

# yum install redis

Start service using the following command,

# systemctl start redis


Another method to install Redis on CentOS

With this method, we can install the latest version of redis or for that matter any version we need. We will installing the latest version at this time, i.e. 6.0.9.. Download the redis package with the following command,

# wget https://download.redis.io/releases/redis-6.0.9.tar.gz

Next extract the redis package,

# tar -xvf  redis-6.0.9.tar.gz

Now goto the extracted folder,

# cd redis-6.0.9

& then goto folder ‘deps’,

$ cd deps

next compile packages, ,

$ make hiredis lua jemalloc linenoise

$ make geohash-int

Next, we will move back to the main directory i.e. ‘redis-6.0.9’

$ cd ../

execute  ‘make’ & ‘make install’ commands

$ make

$ make installation

Once these commands have been executed, we will install the init scripts, init script will setup a redis service with port number, config file, log file & a data directory. To run run init script,

$ cd utils\

& run the install_server.sh script,

$ ./install_server.sh

We will now be asked with some information regarding redis server, as shown below,

Welcome to the redis service installer

This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]

Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]

Selected default – /etc/redis/6379.conf

Please select the redis log file name [/var/log/redis_6379.log]

Selected default – /var/log/redis_6379.log

Please select the data directory for this instance [/var/lib/redis/6379]

Selected default – /var/lib/redis/6379

Please select the redis executable path [/usr/local/bin/redis-server]

Selected config:

Port : 6379

Config file : /etc/redis/6379.conf

Log file : /var/log/redis_6379.log

Data dir : /var/lib/redis/6379

Executable : /usr/local/bin/redis-server

Cli Executable : /usr/local/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

Copied /tmp/6379.conf => /etc/init.d/redis_6379

Installing service…

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server…

Installation successful!

Modify any settings as per your requirements & can also install more than one redis instances by just changing the redis port number.

Now to start the redis service, command is a bit different as service name will be different,

# systemctl start redis_6379

So just change the port number to start only a single redis instance.


Testing Redis installation

We can now check if the redis has been installed by running the following command,

$ redis-cli –version

We can also connect to the installed redis server with the following command,

$ redis-cli

then check the response to ping command for redis,

redis > PING

In response, we should get PONG as output.


Allowing remote connections to Redis installation

By default, we can only connect to redis server from the local server. To allow connections to redis installation from remote machines, we need to make changes to redis configuration file,

$ sudo vi /etc/redis/redis.conf

then look for section that says ‘bind 127.0.0.1’ & change it

bind 0.0.0.0 

to allow connections from all remote servers or we can also mention single or multiple IP addresses to allow connections from those servers only, like

bind 10.10.10.10 192.168.1.10

here, connections will be allowed from two machines with IP addresses 10.10.10.10 & from 192.168.1.10.

Once the changes have been made, we need to restart the redis service to apply changes,

$ sudo systemctl restart redis

This completes our tutorial on how to install Redis on CentOS & RHEL. Please do send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Install Redis on CentOS / RHEL appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/install-redis-on-centos-rhel/feed/ 0 1268
How to install REDIS on Ubuntu https://thelinuxgurus.com/how-to-install-redis-on-ubuntu/ https://thelinuxgurus.com/how-to-install-redis-on-ubuntu/#respond Wed, 02 Dec 2020 14:56:26 +0000 https://thelinuxgurus.com/?p=1258 Redis is an open-source in-memory key-value data structure store that can be used as a cache server, message broker, etc. We can use a number...

The post How to install REDIS on Ubuntu appeared first on The Linux GURUS.

]]>
Redis is an open-source in-memory key-value data structure store that can be used as a cache server, message broker, etc. We can use a number of data types with redis like strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.

It also provides a number of features like,

  • Replication
  • data persistence
  • LRU eviction
  • High availability using sentinel
  • Publish / Subscribe support for data
  • Keys with limited TTL
  • Automatic Failover
  • LUA scripting, etc

In this tutorial, we will learn to install Redis on Ubuntu servers. So let’s get going,


Install Redis on Ubuntu

Redis server packages are available on default Ubuntu repositories, so we are not required to install any official or 3rd party repos on the system. So just perform a repos update,

$ sudo apt update

& then install redis on ubuntu with the following command,

$ sudo apt install redis

Once the redis has been installed on server, we can start the server with the following command,

$ sudo systemctl start redis


Testing Redis installation

We can now check if the redis has been installed by running the following command,

$ redis-cli –version

We can also connect to the installed redis server with the following command,

$ redis-cli

then check the response to ping command for redis,

redis > PING

In response, we should get PONG as output.


Allowing remote connections to redis installation

By default, we can only connect to redis server from the local server. To allow connections to redis installation from remote machines, we need to make changes to redis configuration file,

$ sudo vi /etc/redis/redis.conf

then look for section that says ‘bind 127.0.0.1’ & change it

bind 0.0.0.0 

to allow connections from all remote servers or we can also mention single or multiple IP addresses to allow connections from those servers only, like

bind 10.10.10.10 192.168.1.10

here, connections will be allowed from two machines with IP addresses 10.10.10.10 & from 192.168.1.10.

Once the changes have been made, we need to restart the redis service to apply changes,

$ sudo systemctl restart redis

This completes our tutorial on how to install Redis on Ubuntu. In our future tutorials, we will learn to create MASTER-SLAVE replication for redis & also how we can secure the redis installation. If you have any doubts or questions related to this tutorial, you can reach to us using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to install REDIS on Ubuntu appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-install-redis-on-ubuntu/feed/ 0 1258