Sunday, December 22, 2024

Guide on How to Install and Configure Redis on CentOS 9 Stream

Share

Looking for a step-by-step guide to installing and configuring Redis on CentOS 9 Stream? You’ve landed on the right page. This comprehensive guide covers everything you need to know.

What is Redis?

Redis is an open-source, in-memory data structure store. It can be used as a database, cache, and message broker. Its versatility makes it an excellent choice for fast, high-performance applications.

Prerequisites

Before we begin, make sure you have:

  • A CentOS 9 Stream machine (get it from the CentOS official website)
  • A user account with sudo privileges
  • Access to a terminal or command line interface
  • An active internet connection

Step 1: Update System Packages

Always begin by updating the system packages. Use the following command:

sudo dnf update -y

Step 2: Install Redis

Next, we will install Redis from the CentOS repository using the dnf package manager. Execute the command below:

sudo dnf install redis -y

Step 3: Start and Enable Redis

After the installation, start the Redis service using this command:

sudo systemctl start redis

To ensure Redis starts on system boot, enable it with the following command:

sudo systemctl enable redis

Step 4: Configure Redis

The Redis configuration file is located at /etc/redis.conf. You can open this file with any text editor. For example:

sudo nano /etc/redis.conf

Some key settings to pay attention to include:

  • bind: Set this to the IP address you want Redis to listen on.
  • protected-mode: If you want to disable protection mode and allow external connections, set this to ‘no’.
  • port: The default port is 6379. Change this if necessary.

Use this Configuration:

Here’s a sample full configuration for /etc/redis.conf for Redis in a WordPress setup:

# Redis configuration for WordPress

# Specify the IP address to bind to (localhost)
bind 127.0.0.1

# Specify the port to listen on
port 6379

# Maximum memory allocation for Redis
maxmemory 256mb

# Memory eviction policy (LRU - Least Recently Used)
maxmemory-policy allkeys-lru

# Enable Redis as a cache
cache yes

# Disable Redis as a database
save ""

# Disable Redis as a pub-sub channel
notify-keyspace-events ""

# Set a password for authentication (optional)
# requirepass yourpassword

# Enable Redis persistence (optional)
# appendonly yes
# appendfilename "appendonly.aof"

# Specify the log file path
logfile "/var/log/redis/redis-server.log"

# Specify the log level (optional, default is "notice")
# loglevel notice

# Specify the database directory (optional)
# dir /var/lib/redis

# Specify the pid file path (optional)
# pidfile /var/run/redis/redis-server.pid

# Specify the replication settings (optional)
# slaveof <masterip> <masterport>
# masterauth <masterpassword>

# Disable protected mode (only for local development)
# protected-mode no

# Enable TCP keepalive (optional)
tcp-keepalive 300

# Slow log settings (optional)
# slowlog-log-slower-than 10000
# slowlog-max-len 128

# Set the client timeout (optional)
# timeout 0

# Set the number of Redis databases (optional, default is 16)
# databases 16

# Specify the maximum number of clients (optional)
# maxclients 10000

# Enable AOF rewrite (optional)
# auto-aof-rewrite-percentage 100
# auto-aof-rewrite-min-size 64mb

Please note that the above configuration is a sample, and you may need to adjust certain parameters based on your specific requirements and environment. It’s recommended to consult the Redis documentation and consider the best practices for your production deployment.

Remember to save your changes and close the file. Then restart Redis:

sudo systemctl restart redis

Step 5: Test Redis Installation

Finally, confirm that Redis is working correctly by running:

redis-cli ping

If everything is okay, you should see the output PONG.

Conclusion on Installing Redis

Congratulations! You’ve successfully installed and configured Redis on CentOS 9 Stream. Keep exploring this powerful in-memory data structure store and take your applications to new heights!

Related Articles

Read more

Local News