Introduction

In this tutorial we will learn, how to install Redis server on CentOS 7 / RHEL 7 . The abbreviation of Redis is “Remote Dictionary Server”. It is one the of the most popular open source, advanced key-value cache and store.

Project Website: Redis

Install Redis Server

Follow the given below steps to install redis server on CentOS 7 and Red Hat Enterprise Linux 7.

Install wget utility

Install wget command

yum install wget

Install EPEL repo

First we will install the EPEL repo. For more detail on EPEL repo, we suggest you to read our this post.

Because our system has x86_64 Operating System architecture, we will use only epel repo package for x86_64 . Search epel repo package as per your Operating System architecture(EPEL URL)

wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/e/

rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-*.rpm

It will create two epel’s repo file inside /etc/yum.repos.d
These are –
1. epel.repo
2.epel-testing.repo

[root@localhost ~]# ls -l /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 1612 Jul 4 07:00 CentOS-Base.repo
-rw-r--r--. 1 root root 640 Jul 4 07:00 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 1331 Jul 4 07:00 CentOS-Sources.repo
-rw-r--r--. 1 root root 156 Jul 4 07:00 CentOS-Vault.repo
-rw-r--r--. 1 root root 957 Sep 2 12:14 epel.repo
-rw-r--r--. 1 root root 1056 Sep 2 12:14 epel-testing.repo
[root@localhost ~]#

Install redis server

Now use yum command to install redis server

yum install redis

Two important redis server configuration file’s path
1. /etc/redis.conf
2. /etc/redis-sentinel.conf

Now start the redis server after this.

systemctl start redis.service

Check the running status of redis server

systemctl status redis.service

To test the installation of Redis, use below given command

redis-cli ping

If the response output is PONG, it means installation is completed successfully.

[root@localhost ~]# redis-cli ping
PONG
[root@localhost ~]#

Start/Stop/Restart/Status and Enable redis server

To start redis server

systemctl start redis.service

To stop redis server

systemctl stop redis.service

To restart redis server

systemctl restart redis.service

To get running status of redis server

systemctl status redis.service

To enable redis server at system’s booting time.

systemctl enable redis.service

To disable redis server at system’s booting time.

systemctl disable redis.service

Check Listening Port Of Redis Server

Redis Server listens by default at port number 6379. Use below given ss command. (To learn more about ss command)

[root@localhost ~]# ss -nlp|grep redis
tcp LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",19706,4))
[root@localhost ~]#

Note: On minimal installed CentOS 7/ RHEL 7,you wont get netstat command. Instead of netstat command, use ss command which is by default available on system.

Read Some More Articles

13 Comments

  1. hi everyone ,

    I have installed redis 3.2.12 centos 7.2 in Linux AWS server. 100 GB storage
    2 GB RAM 100 GB Storage. SSD. am using a EC2
    so the storage is EC2 Storage.

    please help me what’s the next step should be done once the installation of redis been done is linux aws server ?

  2. Thank you for this very useful tutorial. People on the web are so kind.

    Would you mind sharing your expertise with me for a couple of things:

    1. We want our Redis to run on some other port. Not the default. Is there a redis.conf we can change?

    2. Secondly, we only want Redis to be accessible from inside our server. So only 127.0.0.1 can access it. Is there any simple command for IPTABLES that can block redis completely from outsiders, and only allow from inside the machine?

    Thank you!

    1. Hi PK Hunter,

      1. We want our Redis to run on some other port. Not the default. Is there a redis.conf we can change?
      Answer: To change the port no. edit the redis.conf file and find this line “port 6379” , replace the port no. 6379 as per your wish.

      2. Secondly, we only want Redis to be accessible from inside our server. So only 127.0.0.1 can access it. Is there any simple command for IPTABLES that can block redis completely from outsiders, and only allow from inside the machine?
      Answer:
      (a) In redis.conf file , find this line “bind ” . The ‘bind’ option helps to listen the service on particular ip address. Hence, if you want the redis port should only listen from localhost’s loopback ip address, then change it to “bind 127.0.0.1”
      As asked, given below is IPTABLES rule should be checked in test machine first.

      Change 6379 with custom redis port number.

      $redis_port=6379
      iptables -A OUTPUT -p tcp -d 0.0.0.0/0 --dport $redis_port -j DROP
      service iptables save
      

      In CentOS 7, good to use firewalld. Please check it once from your end do you want to use iptables or firewalld.

      Regards
      Sharad

  3. [root@mail init.d]# systemctl status redis_6379
    ● redis_6379.service – LSB: start and stop redis_6379
    Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
    Active: active (exited) since Wed 2017-02-08 00:09:47 CET; 8s ago
    Docs: man:systemd-sysv-generator(8)
    Process: 28924 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS)

    Feb 08 00:09:46 mail.lodewijkict.nl systemd[1]: Starting LSB: start and stop redis_6379…
    Feb 08 00:09:46 mail.lodewijkict.nl redis_6379[28924]: Starting Redis server…
    Feb 08 00:09:47 mail.lodewijkict.nl systemd[1]: Started LSB: start and stop redis_6379.
    [root@mail init.d]# systemctl status redis-server
    Unit redis-server.service could not be found.
    [root@mail init.d]# redis-cli -v
    redis-cli 3.2.7
    [root@mail init.d]# systemctl status redis.service
    ● redis.service – Redis persistent key-value database
    Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/redis.service.d
    └─limit.conf
    Active: active (running) since Tue 2017-02-07 05:01:33 CET; 19h ago
    Main PID: 907 (redis-server)
    CGroup: /system.slice/redis.service
    └─907 /usr/bin/redis-server 127.0.0.1:6379

    Feb 07 05:01:33 mail.lodewijkict.nl systemd[1]: Started Redis persistent key-value database.
    Feb 07 05:01:33 mail.lodewijkict.nl systemd[1]: Starting Redis persistent key-value database…
    [root@mail init.d]#

    1. Hi Theo,

      In case you are looking for latest Redis server then suggest you to compile the tar ball of redis.
      You can get the latest Redis tar ball from its official website. I have written this post for it.

      You can take backup and restore the redis database in new redis server version.

      Regards
      Sharad

      1. still redis-cli -v
        redis-cli 2.8.19

        please reply upgrade after this installation not an new installation, now we got a double redis server! we have restored the server to the snapshot after dty it but it is not a solution the link that you send.

        Please a correct upgrade or how to remove the current and install the new one?

        Greetings Theo

        1. Hi Theo,

          Installing via yum and compilation is different method as well as the files get distributes in system is also different.
          I am sure you have not removed your old redis server through yum command. Then you should go for compilation. Get latest Redis package from redis official website and follow the method.

          Regards
          Sharad

          1. Hi Theo,

            In this blog not written about this because many readers have different sets of environment and OS. But which I have replied that is the same logic I professionally applied.
            I will try if in this weekend I manage to get time for this post. I have to quickly search for some sample DB also in between.

            Regards
            Sharad

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.