Using Redis cache in ELMA
System requirements
- ELMA 3.9.22, 3.10.12, 3.11.2 or higher
- At least three Redis cache cluster servers with Unix OS (Linux, OSX, OpenBSD, NetBSD, FreeBSD and derived OS).
Installing a Redis package on the Ubuntu OS as an example
In general, the installation procedure is as follows:
- Updating the information on available software (repository).
sudo apt-get update
- Installing redis-server.
sudo apt install redis-server
- Checking service availability.
service redis-server status (if necessary, start service redis-server start).
Check if it is possible to connect to the service
- Start the control console redis-cli.
redis-cli
Command line view will change to 127.0.0.1:6379>.
- Enter ping, after that the PONG value will be returned:
127.0.0.1:6379>ping
PONG
- Enter exit or press Ctrl+C to exit the redis-cli console.
Assembling and installing a Redis package
You can download the latest version of Redis from the official website: https://redis.io/download (use the Stable version).
Generally, the 'make' command is used for assembling.
Installation guide (Ubuntu 14/16 is used as an example).
1. Install additional packages, required for assembling a Redis package. In case of Ubuntu, those are build-essentials and tcl 8.5 (or higher):
- sudo apt-get update
- sudo apt-get install build-essential
- sudo apt-get install tcl8.5
2. Download the Redis package to any folder (e.g. /home/<user>). You can do it manually or with a command:
wget http://download.redis.io/releases/redis-stable.tar.gz (get a URL on the page https://redis.io/download).
3. Unzip the package (the name of the downloaded package may be different):
tar xzf redis-stable.tar.gz
4. Open the folder with the unzipped package (the name may also be different):
cd redis-stable
5. Assemble the package using the command:
make
6. Check the assembled package using the command:
make test
7. Install the package and register it for running, consequently using the commands:
make install
cd utils
./install_server.sh (this command is interactive; when requesting parameters you can use default values).
After running these commands, the binary files redis-cli and redis-server will be installed to /usr/local/bin. Additionally, the service with the parameters specified in install_server.sh will be registered.
8. To start the service, use the command:
sudo service redis_6379 start (the server name may be different, depending on the values, specified in the install_server.sh command; to stop the service, type 'stop' instead of 'start').
Configuring the Redis cluster
Official documentation is available here: https://redis.io/topics/cluster-tutorial
Official documentation on configuring a high-availability solution: https://redis.io/topics/sentinel
Unofficial (simplified cluster with one master): https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-ubuntu-14-04
Simplified configuration option
The first server is Master, the second and consequent are Slave.
Configuration involves editing the /etc/redis/redis.conf file on each server:
- Make the server available for all the IP addresses of this server:
- Disable data backup copying to the disk (to ensure maximum performance). To do so:
- comment out all the lines starting with 'save' (e.g. #save 900 1).
- set appendonly no
To configure Master:
- Set the parameter:
tcp-keepalive 60
- Set the Master access password:
requirepass
your_redis_password
- If necessary, set the used memory limit (upon reaching the threshold, some values will be removed depending on the maxmemory-policy strategy, defined in the parameter):
maxmemory
<bytes> (specify the maximum volume in bytes or leave the line commented)
maxmemory-policy
volatile-lru (or another value, specified in the comments in this file)
maxmemory-policy
noeviction (if using a limit is not required)
To configure Slave:
- Specify the Slave access password (for the correct functioning of ELMA, specify the same password, as for the Master):
requirepass
your_redis_password
- Specify the Master address and port:
slaveof
your_redis_master_ip 6379
- Specify the Master password:
masterauth
your_redis_password
Restart all the servers (first Master, then Slaves):
sudo service redis_6379 restart
Configuration settings in ELMA
- In <configSections>, add:
<section name="RedisCacheProviderSettings" type="EleWise.ELMA.Cache.Redis.RedisCacheProviderSettings, EleWise.ELMA.Cache.Redis"/> <section name="cacheService" type="EleWise.ELMA.Configuration.GenericProviderFeatureSection`1[[EleWise.ELMA.Cache.CacheServiceManager, EleWise.ELMA.SDK]], EleWise.ELMA.SDK" />
- In the root <configuration> add a settings block (with the list of Redis cache machine names and their access passwords):
<cacheService defaultProvider="Redis"> <providers> <clear /> <add name="Redis" type="EleWise.ELMA.Cache.Redis.ElmaCacheService, EleWise.ELMA.Cache.Redis "/> </providers> </cacheService> <RedisCacheProviderSettings connectionString="machine1:6379,machine2:6379,machine3:6379,password=your_redis_password" />