Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voxx/855f68039c8e3891e9df21bf8bcd3d5d to your computer and use it in GitHub Desktop.
Save voxx/855f68039c8e3891e9df21bf8bcd3d5d to your computer and use it in GitHub Desktop.
Run multiple Redis v4.x+ pools on the same RHEL 7.x+ server (NON SENTINEL)

Create a new redis .conf file for each additional redis instance.

$ sudo cp /etc/redis.conf /etc/redis-xxx.conf

Edit the /etc/redis-xxx.conf as illustrated below.

$ sudo nano /etc/redis-xxx.conf

...
bind [xxx.xxx.xx.xxx] 127.0.0.1

...
#port 6379
port 6380

...
#pidfile /var/run/redis/redis_6379.pid
pidfile /var/run/redis/redis_6380.pid

...
#logfile /var/log/redis/redis.log
logfile /var/log/redis/redis-xxx.log

...
#dir /var/lib/redis
dir /var/lib/redis-xxx

...
# maxmemory <bytes>
maxmemory 4G

Set proper ownership of this new config file to avoid permission errors.

$ sudo chown redis:root /etc/redis-xxx.conf

Make a new directory for this redis instance ~ /var/lib/redis-xxx

$ sudo mkdir -p /var/lib/redis-xxx

Set proper ownership of this new redis dir to avoid permission errors.

$ sudo chown redis:redis /var/lib/redis-xxx

RHEL 7+ uses systemd instead of init.d ~ so copy the existing redis service to a new one.

$ sudo cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis-xxx.service

Modify the new service script as follows:

$ sudo nano /usr/lib/systemd/system/redis-xxx.service

...
[Service]
#ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
ExecStart=/usr/bin/redis-server /etc/redis-xxx.conf --supervised systemd
#ExecStop=/usr/libexec/redis-shutdown
ExecStop=/usr/libexec/redis-shutdown redis-xxx
...

Start the new services:

$ sudo systemctl start redis-xxx

Check the new service status:

$ sudo systemctl status redis-xxx

Stop the new service:

$ sudo systemctl stop redis-xxx

Restart the new service:

$ sudo systemctl restart redis-xxx

Enable it to run at boot:

$ sudo systemctl enable redis-xxx
Created symlink from /etc/systemd/system/multi-user.target.wants/redis-xxx.service to /usr/lib/systemd/system/redis-xxx.service.

TROUBLESHOOTING COMMON ERRORS

If you see "WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.":

$ sudo nano /etc/sysctl.d/100-redis.conf

...
net.core.somaxconn = 511
...

If you see "WARNING overcommit_memory is set to 0!":

$ sudo nano /etc/sysctl.d/100-redis.conf

...
vm.overcommit_memory = 1
...

If you see "WARNING you have Transparent Huge Pages (THP) support enabled in your kernel.":

$ sudo nano /etc/systemd/system/disable-thp.service

[Unit]
Description=Disable Transparent Huge Pages (THP)

[Service]
Type=simple
ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"

[Install]
WantedBy=multi-user.target

Enable the new service to start at boot

$ sudo systemctl enable disable-thp
Created symlink from /etc/systemd/system/multi-user.target.wants/disable-thp.service to /etc/systemd/system/disable-thp.service.

Reboot

$ sudo reboot
@voxx
Copy link
Author

voxx commented Jun 17, 2018

Modified for RHEL 7.x + Redis 4.x

@voxx
Copy link
Author

voxx commented Jul 25, 2018

CHECK IF THP ENABLED

$ cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never

CREATE SERVICE TO DISABLE THP AT BOOT

$ sudo nano /etc/systemd/system/disable-thp.service

[Unit]
Description=Disable Transparent Huge Pages (THP)

[Service]
Type=simple
ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"

[Install]
WantedBy=multi-user.target

Save the file and reload the daemon

$ sudo systemctl daemon-reload

Start the service and configure to run at boot

$ sudo systemctl start disable-thp
$ sudo systemctl enable disable-thp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment