Enviroment Preparation
Server Layout
| Hostname | IP | Instances | Ports |
|---|---|---|---|
| redis-node-0 | 10.10.101.29 | 2 | 6379, 6380 |
| redis-node-1 | 10.10.101.30 | 2 | 6379, 6380 |
| redis-node-2 | 10.10.101.31 | 2 | 6379, 6380 |
Build Dependencies
# Enable GCC 9
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
Ruby 2.3.5 (for redis-trib.rb)
yum -y install gcc gcc-c++
cd /usr/local/src
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.gz
tar xf ruby-2.3.5.tar.gz
cd ruby-2.3.5
./configure --prefix=/opt/ruby
make -j$(nproc) && make install
ln -sf /opt/ruby/bin/ruby /usr/bin/ruby
ln -sf /opt/ruby/bin/gem /usr/bin/gem
Installing Redis
cd /usr/local/src
wget https://download.redis.io/releases/redis-5.0.0.tar.gz
tar xf redis-5.0.0.tar.gz
mv redis-5.0.0 /opt/redis-src
cd /opt/redis-src
make -j$(nproc) && make install PREFIX=/opt/redis
Per-Isntance Configuration
Create a dedicated directory for every instance:
for h in 29 30 31; do
for p in 6379 6380; do
mkdir -p /data/redis/10.10.101.${h}/${p}
done
done
Example redis-6379.conf (repeat for 6380):
bind 0.0.0.0
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
dir /data/redis/$(hostname -I | awk '{print $1}')/6379
logfile /data/redis/$(hostname -I | awk '{print $1}')/6379/redis.log
requirepass Sup3rSecret
# Cluster
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 30000
cluster-require-full-coverage yes
systemd Service Units
/etc/systemd/system/redis@.service
[Unit]
Description=Redis %i
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_%i.pid
ExecStart=/opt/redis/bin/redis-server /data/redis/%H/%i/redis-%i.conf
ExecReload=/bin/kill -USR1 $MAINPID
ExecStop=/bin/kill -QUIT $MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
Enable and start both instances on every node:
systemctl daemon-reload
systemctl enable --now redis@6379 redis@6380
Forming the Cluster
redis-cli --cluster create \
10.10.101.29:6379 10.10.101.29:6380 \
10.10.101.30:6379 10.10.101.30:6380 \
10.10.101.31:6379 10.10.101.31:6380 \
--cluster-replicas 1 -a Sup3rSecret
Confirm the topology:
redis-cli -a Sup3rSecret -c -h 10.10.101.29 -p 6379 cluster nodes
Adding the Bloom Filter Module
cd /usr/local/src
wget https://github.com/RedisBloom/RedisBloom/archive/v2.2.4.tar.gz
tar xf v2.2.4.tar.gz
cd RedisBloom-2.2.4
make
Copy the compiled module to a shared location:
mkdir -p /opt/redis/modules
cp redisbloom.so /opt/redis/modules/
Append to every redis-*.conf:
loadmodule /opt/redis/modules/redisbloom.so
Restart all instances:
systemctl restart redis@6379 redis@6380
Verify the module is loaded:
redis-cli -a Sup3rSecret -c -h 10.10.101.29 -p 6379 MODULE LIST
Quick smoke test:
redis-cli -a Sup3rSecret -c -h 10.10.101.29 -p 6379 \
BF.ADD myfilter user123
redis-cli -a Sup3rSecret -c -h 10.10.101.29 -p 6379 \
BF.EXISTS myfilter user123