Installing and Configuring Redis on Linux Systems
Building Redis from Source
Begin by downloading the latest stable release directly from the Redis repository:
$ wget http://download.redis.io/releases/redis-stable.tar.gz
$ tar xzf redis-stable.tar.gz
$ cd redis-stable
$ make
After compilation completes, create a dedicated directory for the Redis binaries and copy the necessary executables:
sudo mkdir -p /opt/redis/runtime/
cd src
sudo cp redis-benchmark redis-check-aof redis-cli redis-server redis-sentinel /opt/redis/runtime/
Initial Service Configuration
Edit the configuration file to specify the data directory. Locate the dir parameter and set it to an appropriate path:
dir /var/lib/redis/data
Start the Redis server with your configuration file:
$ cd /opt/redis/runtime/
$ ./redis-server redis.conf
To run Redis as a background daemon, modify the daemonize setting in redis.conf:
daemonize yes
Stopping the Redis Service
Gracefully shut down the Redis server using the command-line interface:
$ redis-cli shutdown
If you encounter permission errors during shutdown, verify that the Redis process has appropriate read and write access to its data directory:
sudo chmod -R 755 /var/lib/redis/
Enabling External Network Access
By default, Redis only accepts connections from localhost. To allow remote connections, make the following modifications to redis.conf:
First, change the bind directive to listen on all network interfaces:
bind 0.0.0.0
Second, disable protected mode:
protected-mode no
Restart the Redis service to apply these changes:
./redis-server redis.conf
To connect remotely, use the following syntax:
$ redis-cli -h hostname -p port -a password
Local Command-Line Access
Connect to a locally running Redis instance:
$ redis-cli
Test the connection with the PING command:
127.0.0.1:6379> PING
PONG
Securing Remote Connections
To properly configure Redis for remote access with security:
- Set the bind address in redis.conf:
bind 0.0.0.0 - Configure a strong authentication password:
requirepass your_secure_password_here - Restart the Redis server to apply the new configuration
Connect remotely with authentication:
$ redis-cli -h hostname -p port -a password
Configuring Automatic Startup
To have Redis start automatically when the system boots, add the startup command to your system's initialization scripts. To systems using rc.local:
$ sudo vi /etc/rc.local
Add the following line before the exit statement:
/opt/redis/runtime/redis-server /path/to/redis.conf
Alternatively, for systemd-based distributions, create a proper service unit file in /etc/systemd/system/.
Using Redis Desktop Manager
Redis Desktop Manager provides a graphical interface for managing Redis databases. The pre-compiled binaries require a paid license, but the source code is freely available. To obtain the latest version, compile from the official repository:
Refer to the official documentation at http://docs.redisdesktop.com/en/latest/install/ for detailed build instructions.