Skip to content

bugthesystem/redisetup

Repository files navigation

Table of Contents

Redis + Sentinel + Monit Setup

Redis + Sentinel + Monit Setup Scripts

This configuration is now using small and middle sized production environments. To use it in production is up to you.

Edited Version

Redis Primary/Replica

To Install Primary
Edit master.sh file to set configurations (redis version,instance name, port);

# Defaults
REDIS_VER=2.8.19
UPDATE_LINUX_PACKAGES=false
REDIS_INSTANCE_NAME=redis-server
REDIS_INSTANCE_PORT=6379
mkdir redisetup
cd redisetup
wget https://raw.githubusercontent.com/ziyasal/redisetup/master/master.sh

# Run install script
sudo sh master.sh 

To Install Replica
Edit member.sh file to set configurations (redis version,instance name, port, primary ip, primary port);

# Defaults
REDIS_VER=2.8.19
UPDATE_LINUX_PACKAGES=false      #true|false
REDIS_INSTANCE_NAME=redis-server
REDIS_INSTANCE_PORT=6379         #Set another one if master node is on the same host
REDIS_MASTER_IP=127.0.0.1
REDIS_MASTER_PORT=6379
mkdir redisetup
cd redisetup
wget https://raw.githubusercontent.com/ziyasal/redisetup/master/member.sh

# Run install script
sudo sh member.sh 

Set somaxconn

echo 65535 > /proc/sys/net/core/somaxconn

redis.conf for more detail

tcp-backlog 65535

# **TODO**
# To dump the dataset every 15 minutes (900 seconds) if at least one key changed, you can say:
# save 900 1
# **TODO**
# Redis instantly writes to the log file so even if your machine crashes, it can still recover and have the latest data. #Similar to RDB, AOF log is represented as a regular file at var/lib/redis called appendonly.aof (by default).
# appendonly yes

# **TODO**
# To tell OS to really really write the data to the disk, Redis needs to call the fsync() function right after the write call, #which can be slow.
# appendfsync everysec

/etc/init.d/redis-server

sudo sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
ulimit -n 65535
ulimit -n >> /var/log/ulimit.log #Not required!

Redis Sentinel

install

wget https://raw.githubusercontent.com/ziyasal/redisetup/master/sentinel.sh
sudo sh sentinel.sh  #Run install script

Monit

install

sudo apt-get install monit

update monit config file

nano /etc/monit/monitrc

Add or update httpd settings

set httpd port 8081 and
    use address localhost  # only accept connection from localhost
    allow localhost        # allow localhost to connect to the server and
    allow admin:monit      # require user "admin" with password "monit"

Apply Redis and Sentinel Configurations into Monit

Create redis.conf

nano /etc/monit/conf.d/redis.conf

Add following settings for more options monit documentation

#Default settings
#watch by pid
check process redis-server
    with pidfile "/var/run/redis.pid"
    start program = "/etc/init.d/redis-server start"
    stop program = "/etc/init.d/redis-server stop"
    if failed host 127.0.0.1 port 6379 then restart
    if 5 restarts within 5 cycles then timeout

Create sentinel.conf

nano /etc/monit/conf.d/redis-sentinel.conf

Add following lines

#watch by process name TODO: pid file
check process redis-sentinel
    matching "redis-sentinel"
    start program = "/etc/init.d/redis-sentinel start"
    stop program = "/etc/init.d/redis-sentinel stop"
    if failed host 127.0.0.1 port 26379 then restart
    if 5 restarts within 5 cycles then timeout

System Side Settings

sysctl.conf

vm.overcommit_memory=1                # Linux kernel overcommit memory setting
vm.swappiness=0                       # turn off swapping
net.ipv4.tcp_sack=1                   # enable selective acknowledgements
net.ipv4.tcp_timestamps=1             # needed for selective acknowledgements
net.ipv4.tcp_window_scaling=1         # scale the network window
net.ipv4.tcp_congestion_control=cubic # better congestion algorythm
net.ipv4.tcp_syncookies=1             # enable syn cookied
net.ipv4.tcp_tw_recycle=1             # recycle sockets quickly
net.ipv4.tcp_max_syn_backlog=65535    # backlog setting
net.core.somaxconn=65535              # up the number of connections per port
fs.file-max=65535

/etc/security/limits.conf

redis soft nofile 65535
redis hard nofile 65535

Add following line

session required pam_limits.so

to

/etc/pam.d/common-session
/etc/pam.d/common-session-noninteractive

Shortcuts

After executing the command shown below

monit monitor all

Now you can keep track of redis server and sentinel by monit

monit status

Get Primary/Replica replication information

redis-cli -p 6379 info replication

Get Sentinel information

redis-cli -p 26379 info sentinel

About

Redis setup scripts

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages