Step-by-Step Guide
- Update the Package Index
Open a terminal and update the package index to ensure you have the latest information about available packages:
sudo yum update -y
- Enable the EPEL Repository
Redis is available in the EPEL (Extra Packages for Enterprise Linux) repository. Enable it using the following command:
sudo yum install epel-release -y
- Install Redis
Install Redis using theyum
package manager:
sudo yum install redis -y
- Start and Enable Redis
Start the Redis service:
sudo systemctl start redis
Enable Redis to start on boot:
sudo systemctl enable redis
- Verify Redis Installation
Check the Redis service status to ensure it is running:
sudo systemctl status redis
If Redis is running, you should see an active (running) status.
- Test Redis Installation
To test the Redis installation, use the Redis CLI to connect to the Redis server:
redis-cli
Once connected, you can test Redis by setting and getting a key:
SET mykey "Hello, Redis!"
GET mykey
You should see the response “Hello, Redis!”.
- Secure Redis (Optional)
For additional security, consider setting a password. Open the Redis configuration file for editing:
sudo nano /etc/redis.conf
Uncomment the requirepass
directive and set a strong password:
requirepass your_password
Save and close the file. Restart Redis to apply the changes:
sudo systemctl restart redis
- Enable Persistence (Optional)
Redis supports two forms of persistence: RDB snapshots and AOF (Append Only File). To enable RDB snapshots, ensure the following lines are present in the Redis configuration file:
save 900 1
save 300 10
save 60 10000
To enable AOF, uncomment and set the appendonly
directive to yes:
appendonly yes
Save and close the file. Restart Redis to apply the changes:
sudo systemctl restart redis
- Configure Redis to Bind to Specific IP Address (Optional)
By default, Redis listens on all available IP addresses. To restrict access, open the Redis configuration file:
sudo nano /etc/redis.conf
Find the bind
directive and set it to your server’s IP address:
bind 127.0.0.1
Save and close the file. Restart Redis to apply the changes:
sudo systemctl restart redis
- Monitor Redis
You can monitor Redis performance and statistics using theredis-cli
with theINFO
command:bash redis-cli INFO