Wednesday, 21 June 2017

Setting up Redis Sentinel as a service in Ubuntu


There are plenty of excellent documents on how to set up a Redis Master/Slave system, but very little on Sentinel.

Once you have Sentinel running reliably on the commend line, you will want to get Sentinel working as a service.

First, open up a new file:
vim /etc/systemd/system/sentinel.service

In there you probably want something like:

[Unit]
Description=Sentinel for Redis
After=network.target

[Service]
LimitNOFILE=64000
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-sentinel /etc/redis/<your configuration file>.conf --daemonize no

[Install]
WantedBy=multi-user.target

You then need to make sure that the user you are using to run the service (in this case redis) has permissions for both the configuration file 

chown redis:redis /etc/redis/<your configuration file>.conf

and the log files you have set up in your configuration file

chown redis:redis /var/log/redis/<your log file>.log

Test everything works as expected by:

systemctl start sentinel

then 

systemctl status sentinel

You should get something that looks like:

If you do, then everything is good and you can set your service to start automatically with:

systemctl enable sentinel