Skip to content

Instantly share code, notes, and snippets.

@dpneumo
Created January 2, 2019 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpneumo/74a184eb67922492230fcb65786f199b to your computer and use it in GitHub Desktop.
Save dpneumo/74a184eb67922492230fcb65786f199b to your computer and use it in GitHub Desktop.
Multi-instance Redis on one host (Centos7)
# Redis sysctl configuration
vm.overcommit_memory = 1
# In order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
################################## INCLUDES ###################################
# Redis always uses the last processed line
# as value of a configuration directive.
# include /path/to/local.conf
# include /path/to/other.conf
################################## MODULES #####################################
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
################################## NETWORK #####################################
bind 127.0.0.1
port 6379
protected-mode yes
tcp-backlog 511
# Unix socket.
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
daemonize no
pidfile /var/run/redis.pid
# Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
supervised no
loglevel notice
logfile /var/log/redis.log
# syslog-enabled no
# syslog-ident redis
# syslog-facility local0
databases 16
always-show-logo yes
################################ SNAPSHOTTING ################################
#
# Save the DB on disk:
#
# save <seconds> <changes>
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
# The filename where to dump the DB
dbfilename dump.rdb
# The working directory.
dir /var/redis/
################################# REPLICATION #################################
# replicaof <masterip> <masterport>
# masterauth <master-password>
replica-serve-stale-data yes
replica-read-only yes
# Replication SYNC strategy: disk or socket.
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# -------------------------------------------------------
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-replica-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
replica-priority 100
# min-replicas-to-write 0
# min-replicas-max-lag 10
# replica-announce-ip 5.5.5.5
# replica-announce-port 1234
################################## SECURITY ###################################
# requirepass foobared
# rename-command CONFIG ""
################################### CLIENTS ####################################
# maxclients 10000
############################## MEMORY MANAGEMENT ################################
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
# replica-ignore-maxmemory yes
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
############################## APPEND ONLY MODE ###############################
# Please check http://redis.io/topics/persistence for more information.
appendonly no
appendfilename "appendonly.aof"
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000
# cluster-replica-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes
# cluster-replica-no-failover no
# In order to setup your cluster make sure to read the documentation
# available at http://redis.io web site.
########################## CLUSTER DOCKER/NAT support ########################
# cluster-announce-ip 10.1.1.5
# cluster-announce-port 6379
# cluster-announce-bus-port 6380
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
# Redis can notify Pub/Sub clients about events happening in the key space.
# This feature is documented at http://redis.io/topics/notifications
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# client-query-buffer-limit 1gb
# proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
printf "========= Install Redis ===========================\n"
wget -c http://download.redis.io/redis-stable.tar.gz
tar -xvzf redis-stable.tar.gz
cd redis-stable
make
make test
sudo make install
# redis_cache configuration
################################## INCLUDES ###################################
# include /etc/redis/base.conf
################################## NETWORK #####################################
bind 127.0.0.1
port 6380
# unixsocket /tmp/redis_cache.sock
################################# GENERAL #####################################
daemonize no
pidfile /var/run/redis_cache.pid
supervised systemd
loglevel notice
logfile /var/log/redis/redis_cache.log
# syslog-enabled no
# syslog-ident redis_cache
# syslog-facility local0
################################ SNAPSHOTTING ################################
dbfilename dump.rdb
dir /var/redis/redis_cache/
############################## APPEND ONLY MODE ###############################
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
[Unit]
Description=Redis_Cache In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis_cache.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
# Create redis user:
sudo adduser --system --no-create-home redis
# Create folders:
sudo mkdir /etc/redis
sudo mkdir -p /var/redis/redis_sidekiq/
sudo mkdir -p /var/redis/redis_cache/
# Copy the redis_*.conf files to /etc/redis/
# Copy the *.service files to /etc/systemd/system/
# Copy the 40-redis.conf file to /usr/lib/sysctl.d/
# Set ownership and permissions:
## Configuration files
sudo chown redis:redis /etc/redis/*.conf
sudo chmod 644 /etc/redis/*.conf
## Data folders
sudo chown redis:redis /var/redis/redis_*/
sudo chmod 770 /var/redis/redis_*/
## Redis sysctl
sudo chmod 644 /usr/lib/sysctl.d/40-redis.conf
## Systemd services
sudo chown root:root /etc/systemd/system/redis_*.service
sudo chmod 644 /etc/systemd/system/redis_*.service
# Start vm.overcommit_memory now
sudo sysctl vm.overcommit_memory=1
# Start and enable start at boot up:
sudo systemctl start redis_sidekiq
sudo systemctl enable redis_sidekiq
sudo systemctl start redis_cache
sudo systemctl enable redis_cache
# redis_sidekiq configuration
################################## INCLUDES ###################################
# include /etc/redis/base.conf
################################## NETWORK #####################################
bind 127.0.0.1
port 6379
# unixsocket /tmp/redis_sidekiq.sock
################################# GENERAL #####################################
daemonize no
pidfile /var/run/redis_sidekiq.pid
supervised systemd
loglevel notice
logfile /var/log/redis/redis_sidekiq.log
# syslog-enabled no
# syslog-ident redis_sidekiq
# syslog-facility local0
################################ SNAPSHOTTING ################################
dbfilename dump.rdb
dir /var/redis/redis_sidekiq/
############################## APPEND ONLY MODE ###############################
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
[Unit]
Description=Redis_Sidekiq In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis_sidekiq.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment