Requirements-

  • Linux Machine with CentOS 6/7 with Root Permissions
  • Internet Connection

 

Procedure to Compile Redis from Source -

 

1. Install some required packages (needs root permissions)

sudo yum install wget make gcc tcl -y

 

2. Download the latest stable source for Redis from official release directory.

wget http://download.redis.io/releases/redis-stable.tar.gz

 

3. Extract tarball

tar -xvf redis-stable.tar.gz

 

4. Run the following commands one by one to compile Redis from source. Please note that make commands below will take some time to complete, so keep patience

cd redis-stable
cd deps
make hiredis lua jemalloc linenoise
cd ..
make
make test 

 

5. If make test commands show output as below then you have successfully compiled Redis.

 

6. If you want to install for all users on your machine run the following command or else skip it (root permissions required)

sudo make install

 

Install init Script

 

We need init configuration so that redis-server should start itself on boot and no manual commands are needed by the user.

Note – We need root to create init Script

 

1. Goto your redis-stable directory where you have compiled Redis from source using the above steps

cd /full/path/redis-stable

cd src

 

2. Run the following command to get full path of your Redis dir, which I needed when creating init Script

pwd

 

As is above photo for me full path is /home/username/redis-stable

 

3. Goto utils directory in redis-stable

cd utils

 

4. Run install_server.sh script as root

sudo ./install_server.sh

 

It will ask you some details while creating init script. To keep default just press ENTER 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 [] /home/username/redis-stable/src/redis-server

 

In my config, I have used everything default and have customized only the ‘redis executable path’, which means that we have to define the path where we have compiled the Redis ourselves.

So, now we will use the full path of redis-stable dir generated in Step #2 above and for me redis is compiled inside ‘src’ dir so for me redis executable path is /home/username/redis-stable/src/redis-server

Press enter after entering the correct path and it will show you the selected configuration, just cross check and press ENTER to confirm.

Note- Users who have installed it as root don’t need to change the ‘redis executable path’

 

5. If everything goes correct then install_server script will show success message on your terminal window.

 

6. Now we have to start the service created by init script which needs root permissions

 

For CentOS 6 run

service redis_6379 start

 

For CentOS 7 run

systemctl start redis_6379

 

Note –  If you have used custom port then your service name should be different.

 

Create alias for redis-cli

 

This is only needed if you have installed for the specific user and not as root

 

1. Edit .bashrc file for alias

 

nano ~/.bashrc

 

2. Paste the following lines at the end

 

alias redis-cli=~/redis-stable/src/redis-cli
alias redis-server=~/redis-stable/src/redis-server

 

Note- Please adjust if your redis-stable dir in not in root of your user.

 

3. Apply .bashrc changessource ~/.bashrc

 

 

Test redis

 

1. Run redis-cli using following command and run proceeding commands to test redis.

 

redis-cli
> set welcome “Hello from RootAdminz”
> get welcome

 

So, we have finished the Installation for Redis on CentOS Machine.

 

Was this answer helpful? 1 Users Found This Useful (1 Votes)