Install Redis on RHEL/CentOS
- Install Redis from the EPEL repositories
- Managing the Redis service/process
- Verify that Redis is working
- Set file descriptor limits
- Configure Sensu
Install Redis from the EPEL repositories
Because Redis is not available by default in all RHEL and CentOS distribution repositories, you will need to install the corresponding EPEL repository for your CentOS/RHEL release (supported platforms are RHEL 5, RHEL 6, and RHEL 7).
-
Install EPEL on RHEL/CentOS 6:
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
-
Install Redis (>= 1.3.14) from the EPEL repository:
sudo yum install redis
Managing the Redis service/process
Start/stop Redis services
Start and stop Redis using the redis
init scripts:
NOTE: The service
command will not work on CentOS 5, the sysvinit
script must be used, e.g. sudo /etc/init.d/redis start
sudo service redis start
sudo service redis stop
sudo service redis-sentinel start
sudo service redis-sentinel stop
NOTE: redis-sentinel
service scripts are not installed by default and should
only be used with highly available Redis configurations.
Enable/disable Redis start on system boot
Enable and disable the Redis init scripts using the chkconfig
utility:
sudo /sbin/chkconfig redis on
sudo /sbin/chkconfig redis off
sudo /sbin/chkconfig redis-sentinel on
sudo /sbin/chkconfig redis-sentinel off
NOTE: redis-sentinel
service scripts are not installed by default and should
only be used with highly available Redis configurations.
Verify that Redis is working
Once you have installed and started the Redis service, you should be able to
confirm that Redis is ready to use by running the command: redis-cli
ping. If you get a PONG
response, you are ready to move on to the next
step in the guide.
Set file descriptor limits
NOTE: for the most part, Redis should “just work” without needing to tune Linux file descriptor limits, however this configuration may become necessary in cases where Redis is being used as the Sensu transport or in other high performance environments. Even with tuning, Redis Transport is NOT recommended in production!
By default, most Linux operating systems will limit the maximum number of file
handles a single process is allowed to have open to 1024
. We recommend
adjusting this number to 65536
for running Redis in production systems, and at
least 4096
for development environments.
According to the Redis documentation on client handling, regarding the maximum number of client connections allowed:
In Redis 2.4 there was an hard-coded limit about the maximum number of clients that was possible to handle simultaneously. In Redis 2.6 this limit is dynamic: by default is set to 10000 clients, unless otherwise stated by the
maxclients
directive in/etc/redis/redis.conf
. However Redis checks with the kernel what is the maximum number of file descriptors that we are able to open (the soft limit is checked), if the limit is smaller than the maximum number of clients we want to handle, plus 32 (that is the number of file descriptors Redis reserves for internal uses), then the number of maximum clients is modified by Redis to match the amount of clients we are really able to handle under the current operating system limit.When Redis is configured in order to handle a specific number of clients it is a good idea to make sure that the operating system limit to the maximum number of file descriptors per process is also set accordingly.
To adjust this limit, please edit the configuration file found at
/etc/default/redis
by uncommenting the last line in the file, and
adjusting the ulimit
value accordingly.
# redis configure options
#
# ULIMIT: Call ulimit -n with this argument prior to invoking Redis itself.
# This may be required for high-concurrency environments. Redis itself cannot
# alter its limits as it is not being run as root. (default: do not call
# ulimit)
#
ULIMIT=65536
When the configured number of maximum clients can not be honored, the condition is logged at startup…
[41422] 23 Jan 11:28:33.179 # Unable to set the max number of files limit to 100032 (Invalid argument), setting the max clients configuration to 10112.
Configure Sensu
The following Sensu configuration files are provided as examples. Please review the Redis reference documentation for additional information on configuring Sensu to communicate with Redis, and the reference documentation on Sensu configuration for more information on how Sensu loads configuration.
Example Standalone Configuration
- Copy the following contents to a configuration file located at
/etc/sensu/conf.d/redis.json
:{ "redis": { "host": "127.0.0.1", "port": 6379 } }
"localhost"
instead of127.0.0.1
for thehost
configuration on systems that support IPv6 may result in an IPv6 “localhost” resolution (i.e.::1
) rather than an IPv4 “localhost” resolution (i.e.127.0.0.1
). This is not incorrect behavior because Sensu does support IPv6, however if Redis is not configured to listen on IPv6, this will result in a connection error and log entries indicating a “redis connection error” with an “unable to connect to redis server” error message.
Example Distributed Configuration
-
Obtain the IP address of the system where Redis is installed. For the purpose of this guide, we will use
10.0.1.5
as our example IP address. -
Create a configuration file with the following contents at
/etc/sensu/conf.d/redis.json
on the Sensu server and API system(s), and all systems running the Sensu client:{ "redis": { "host": "10.0.1.5", "port": 6379, "auto_reconnect": true } }
sensu-client
process does not require Redis configuration unless Redis is being used as the Sensu Transport. If you’re not planning on using Redis as the Sensu Transport, you do not need to create a Redis configuration file on systems where the Sensu client is installed.
Using Redis as the Sensu Transport
- If you are planning to use Redis as your Sensu Transport, please
copy the following contents to a configuration file located at
/etc/sensu/conf.d/transport.json
:{ "transport": { "name": "redis", "reconnect_on_error": true } }