Sentinel redis cluster deployment + zabbix monitoring configuration + performance testing + multi-instance automatic configuration script
1. Cluster architecture:
Second, server configuration:
Cpu:4 kernel
Memory: 16GB
Hard disk: 50g
3. Installation commands:
Cd / opt/redis/
Ls
Yum install tcl-y
Tar xf redis-3.2.9.tar.gz
Yum install gcc-y
Ls
Cd redis-3.2.9
Ls
Make
Make test
Ls
Mkdir / etc/redis # stores redis configuration files
Ln-s / opt/redis/redis-3.2.9/src/redis-cli / usr/sbin/redis-cli
Ln-s / opt/redis/redis-3.2.9/src/redis-server / usr/sbin/redis-server
Ln-s / opt/redis/redis-3.2.9/src/redis-sentinel / usr/sbin/redis-sentinel
4. Configuration file information:
1. Redis slave node configuration file information, save the file to the / etc/redis directory
Bind 0.0.0.0
Protected-mode no
Port 4379
Tcp-backlog 511
Timeout 300
Tcp-keepalive 300
# requirepass redis
Daemonize yes
Supervised no
Pidfile "/ var/run/redis_4379.pid"
Loglevel notice
Logfile ""
Databases 16
# save 900 1
# save 300 10
# save 60 10000
Stop-writes-on-bgsave-error yes
Rdbcompression yes
Rdbchecksum yes
Dbfilename "dump.rdb"
Dir "/ opt/redis-3.2.1"
Slave-serve-stale-data yes
Slave-read-only yes
Repl-diskless-sync no
Repl-diskless-sync-delay 5
Repl-disable-tcp-nodelay no
Slave-priority 100
Appendonly no
Appendfilename "appendonly.aof"
Appendfsync everysec
No-appendfsync-on-rewrite no
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64mb
Aof-load-truncated yes
Lua-time-limit 5000
Slowlog-log-slower-than 10000
Slowlog-max-len 128
Latency-monitor-threshold 0
Notify-keyspace-events ""
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
Activerehashing yes
Client-output-buffer-limit normal 0 0 0
Client-output-buffer-limit slave 256mb 64mb 60
Client-output-buffer-limit pubsub 32mb 8mb 60
Hz 10
Aof-rewrite-incremental-fsync yes
# Generated by CONFIG REWRITE
Maxmemory 200mb
Maxmemory-policy noeviction
Slaveof xx.xx.xx.xx 4379 # Master node comments out this line
2. Sentinel configuration file
Port 14379
Daemonize yes
Protected-mode no
Dir "/ opt/redis-3.2.1"
Logfile "/ var/log/sentinel.log"
Sentinel monitor r1 xx.xx.xx.xx 4379 2
Sentinel down-after-milliseconds r1 20000
Sentinel parallel-syncs r1 1
Sentinel failover-timeout r1 30000
# Generated by CONFIG REWRITE
3. Redis starts and closes the script, places the file in the / etc/init.d/ directory, and gives execution permission
#! / bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the / proc filesystem.
REDISPORT=4379
EXEC=/usr/sbin/redis-server
CLIEXEC=/usr/sbin/redis-cli
PIDFILE=/var/run/redis_$ {REDISPORT} .pid
CONF= "/ etc/redis/redis.conf"
Case "$1" in
Start)
If [- f $PIDFILE]
Then
Echo "$PIDFILE exists, process is already running or crashed"
Else
Echo "Starting Redis server..."
$EXEC $CONF
Fi
Stop)
If [!-f $PIDFILE]
Then
Echo "$PIDFILE does not exist, process is not running"
Else
PID=$ (cat $PIDFILE)
Echo "Stopping..."
$CLIEXEC-p $REDISPORT shutdown
While [- x / proc/$ {PID}]
Do
Echo "Waiting for Redis to shutdown..."
Sleep 1
Done
Echo "Redis stopped"
Fi
*)
Echo "Please use start or stop as first argument"
Esac
5. Start redis and sentinel:
/ etc/init.d/redis start
/ usr/sbin/redis-sentinel / etc/redis/sentinel.conf
6. Redis multi-instance automatic configuration script
#! / bin/bash
Set-e
# get the port number
[$#-ne 1] & & echo "Please enter the port number (For example:. / redis-add.sh 4379)" & & exit 1
# RP= `echo $1`
RP=$1
# check whether the configuration file exists
If [- f / etc/redis/redis_$RP.conf]; then
Echo "Warning:There are already exists / etc/redis/redis_$RP.conf,Please check" & & exit 1
Elif [- f / etc/redis/sentinel_$RP.conf]; then
Echo "Warning:There are already exists / etc/redis/sentinel_$RP.conf,Please check" & & exit 1
Elif [- f / etc/init.d/redis_$RP]; then
Echo "Warning:There are already exists / etc/init.d/redis_$RP,Please check" & & exit 1
Fi
# generate configuration file
/ bin/cp / etc/redis/bak/redis.conf.bak / etc/redis/redis_$RP.conf
/ bin/cp / etc/redis/bak/sentinel.conf.bak / etc/redis/sentinel_$RP.conf
/ bin/cp / etc/init.d/redis / etc/init.d/redis_$RP
# modify configuration file
SRP=$ (($RP + 10000))
# echo $SRP
Sed-is/ 4379/$RP/ / etc/redis/redis_$RP.conf
Sed-is/ 4379/$RP/ / etc/redis/sentinel_$RP.conf
Sed-is/ r1/r$RP/ / etc/redis/sentinel_$RP.conf
Sed-is/ sentinel.log/sentinel_$SRP.log/ / etc/redis/sentinel_$RP.conf
Sed-is/ 14379/$SRP/ / etc/redis/sentinel_$RP.conf
Sed-is / 4379/$RP/ / etc/init.d/redis_$RP
Sed-is / redis.conf/redis_$RP.conf/ / etc/init.d/redis_$RP
# start redis and sentinel
Echo "/ etc/init.d/redis_$RP start" > > / etc/rc.d/rc.local
Echo "/ usr/sbin/redis-sentinel / etc/redis/sentinel_$RP.conf" > > / etc/rc.d/rc.local
/ etc/init.d/redis_$RP start
Wait
/ usr/sbin/redis-sentinel / etc/redis/sentinel_$RP.conf
7. Zabbix monitoring script:
#! / bin/bash
HOST= "127.0.0.1"
PORT=$1
# testing redis performance
Function Clients {
/ usr/sbin/redis-cli-h $HOST-p $PORT info Clients | awk-favored rig''NR==2 {print $2}'
}
Function Memory {
Used_memory= `/ usr/sbin/redis-cli-h $HOST-p $PORT info Memory | awk-fanglu 'NR==2 {print $2}' | grep-o "[0-9]\ +"`
Max_memory= `/ usr/sbin/redis-cli-h $HOST-p $PORT info Memory | awk-fanglu 'NR==12 {print $2}' | grep-o "[0-9]\ +"`
Usage_memory= `expr $used_memory\ * 100 / $max_ expy`
Echo $usage_memory
}
Function Slowlog {
/ usr/sbin/redis-cli-h $HOST-p $PORT slowlog len | awk'{print $1}'
}
Function Info {
/ usr/sbin/redis-cli-h $HOST-p $PORT info Server & > / tmp/info.txt
INFO= `cat / tmp/info.txt | awk 'NR==1 {print $2}' | grep-o-I "[Amurz]\ +" `
If ["$INFO" = = "Server"]; then
INFO1=1
Else
INFO1=0
Fi
Echo $INFO1
}
# execute function
$2
8. Performance testing:
Cd / opt/redis/redis-3.2.9/src/
. / redis-benchmark-h xx.xx.xx.xx-p 6379-c 30-n 100000-Q > / opt/redis/log/30.log
Reference documents:
Http://www.cnblogs.com/janehoo/p/6118961.html