It is important to create atleast 1 replica for each Redis primary node for failover. Execute all steps on all 3 cluster nodes to create one replica for each primary node.
Procedure
- Copy redis.conf file under /etc directory as redis-6380.conf, by invoking below command:
cp /etc/redis.conf /etc/redis-6380.conf
- Change owner of /etc/redis-6380.conf to redis by using command:
chown redis:root /etc/redis-6380.conf
- Edit /etc/redis/redis-6380.conf file with below configurations:
- Change "bind 127.0.0.1" to "bind <IPAddress>"
- Change "port 6379" to "port 6380"
- Change 'logfile /var/log/redis/redis.log' to 'logfile /var/log/redis/redis-6380.log'
- Change "dbfilename dump.rdb" to "dbfilename dump-6380.rdb"
- Change "pidfile /var/run/redis_6379.pid" to "pidfile /var/run/redis_6380.pid". Change only in RHEL 7.5 or 7.6.
- Change '# cluster-enabled yes' to 'cluster-enabled yes'
- Change '# cluster-config-file nodes-6379.conf' to 'cluster-config-file redis-6380.conf'
- Change '# cluster-node-timeout 15000' to 'cluster-node-timeout 5000'
- Change 'requirepass' to 'requirepass <password>'
- Change '# masterauth <master-password>' to 'masterauth <password>'
- For RHEL 7.5 or 7.6, create /usr/lib/systemd/system/redis-6380.service file:
- Copy /usr/lib/systemd/system/redis.service to /usr/lib/systemd/system/redis-6380.service and, edit /usr/lib/systemd/system/redis-6380.service file.
- Replace 'ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd' with 'ExecStart=/usr/bin/redis-server /etc/redis-6380.conf --supervised systemd'
- Replace 'ExecStop=/usr/libexec/redis-shutdown' with 'ExecStop=/usr/libexec/redis-shutdown redis-6380'
For RHEL 6.9 or 6.10, create /etc/init.d/redis-6380 service file:- Copy /etc/init.d/redis to /etc/init.d/redis-6380 and, edit /etc/init.d/redis-6380 file
- Replace 'shut="/usr/libexec/redis-shutdown"' with 'shut="/usr/libexec/redis-shutdown redis-6380"'
- Replace 'pidfile="/var/run/redis/redis.pid"' with 'pidfile="/var/run/redis/redis-6380.pid"'
- Replace 'REDIS_CONFIG="/etc/redis.conf"' with 'REDIS_CONFIG="/etc/redis-6380.conf"'
- Replace '[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis' with '[ -e /etc/sysconfig/redis-6380 ] && . /etc/sysconfig/redis-6380'
- Replace 'lockfile=/var/lock/subsys/redis' with 'lockfile=/var/lock/subsys/redis-6380'
- Replace '[ -x $shut ] && $shut' with '$shut'
- Enable the service:
- For RHEL 7.5 or 7.6 command is: systemctl enable redis-6379
- For RHEL 6.9 or 6.10 command is :
chkconfig --add redis-6379 chkconfig redis-6379 on
- Start the service:
- For RHEL 7.5 or 7.6 command is : systemctl start redis-6379
- For RHEL 6.9 or 6.10 command is : service redis-6379 start
- Verify service status:
- For RHEL 7.5 or 7.6 command is : systemctl status redis-6379 (service should be running)
- For RHEL 6.9 or 6.10 command is : service redis-6379 status (service should be running)
- Check the redis logs /var/log/redis/redis-6379.log. The log must contains "Ready to accept connections".
- Execute step 1 to 8 on all 3 cluster nodes.
- Add each redis process running on 6380 port as replicas to each primary running on 6379 port, by using commands:
redis-cli -a <password> --cluster add-node <IP2>:6380 <IP1>:6379 --cluster-slave redis-cli -a <password> --cluster add-node <IP3>:6380 <IP2>:6379 --cluster-slave redis-cli -a <password> --cluster add-node <IP1>:6380 <IP3>:6379 --cluster-slave
Note: Before executing above command, ensure that steps 1-9 are executed on each node in the cluster. Aove commands can be executed from any one cluster node.Expected output after executing each command:[OK] New node added correctly.
- Validate redis primary and replication nodes by running below command:
redis-cli -a <password> -h <IP> -p 6379 cluster nodesOutput: Must show both the primary and secondary nodes along with primary to secondary mapping information.Other useful commands:
- Command to list all keys in redis cluster: redis-cli -a <password> -h <IP1/IP2/IP3> -p <6379/6380> keys "*"
- Command to see content/value of any particular keys: redis-cli -a <password> -h <IP1/IP2/IP3> -p <6379/6380> HGETALL "key"
- Command to reset redis cluster:
redis-cli -a <password> -h <IP1/IP2/IP3> -p <6379/6380> IP:Port> flushall IP:Port> cluster reset IP:Port> exit