November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

How To Configure a Redis Cluster on CentOS 7

yum install gcc make
cd ~
mkdir init
wget http://download.redis.io/releases/redis-3.2.3.tar.gz
tar -zxvf redis-3.2.3.tar.gz 
cd redis-3.2.3
make 
make install

#cd utils
#./install_server.sh

cd src/
cp redis-server redis-cli /usr/local/bin
cp redis-sentinel redis-benchmark redis-check-aof redis-check-dump /usr/local/bin

mkdir /etc/redis
mkdir -p /var/lib/redis/6379

Set the vm.overcommit_memory to 1, which means always, this will avoid data to be truncated, take a look here for more.

sysctl -w vm.overcommit_memory=1

Change the maximum of backlog connections some value higher than the value on tcp-backlog option of redis.conf, which defaults to 511. You can find more on sysctl based ip networking “tunning” on kernel.org website.

sysctl -w net.core.somaxconn=512

Disable transparent huge pages support, that is known to cause latency and memory access issues with Redis.

echo never > /sys/kernel/mm/transparent_hugepage/enabled

Redis.conf is the Redis configuration file, however you will see the file named as 6379.conf here, where the number is the same as the network port is listening to. This name is recommended if you are going to run more than one Redis instance.

cp redis.conf /etc/redis/6379.conf
vim /etc/redis/6379.conf

daemonize yes #note
pidfile /var/run/redis_6379.pid
port 6379
loglevel notice
logfile /var/log/redis_6379.log
dir /var/lib/redis/6379

Starting at boot

cp utils/redis_init_script /etc/init.d/redis_6379
vim /etc/systemd/system/redis_6379.service

[Unit]
Description=Redis on port 6379

[Service]
Type=forking
ExecStart=/etc/init.d/redis_6379 start
ExecStop=/etc/init.d/redis_6379 stop

[Install]
WantedBy=multi-user.target

vim /etc/sysctl.conf

vm.overcommit_memory = 1
net.core.somaxconn=512

For the transparent huge pages support there is no sysctl directive, so you can put the command at the end of /etc/rc.local

echo never > /sys/kernel/mm/transparent_hugepage/enabled

 

Configure Redis Master

vi /etc/redis.conf

daemonize yes #note
tcp-keepalive 60
#bind 127.0.0.1
requirepass your_redis_master_password
maxmemory-policy noeviction
appendonly yes
appendfilename "appendonly.aof"

restart if makeinstall
redis-server /etc/redis/6379.conf

Configure Redis Slave

daemonize yes #note
#bind 127.0.0.1
requirepass your_redis_slave_password
slaveof your_redis_master_ip 6379
masterauth your_redis_master_password

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>