sentinel redis 集群部署+zabbix监控配置+性能测试+多实例自动配置脚本

发布时间:2020-07-23 17:01:54 作者:lrtao2010
阅读:2162
开发者专用服务器限时活动,0元免费领! 查看>>

一、集群架构:

sentinel redis 集群部署+zabbix监控配置+性能测试+多实例自动配置脚本

二、服务器配置:

cpu:4核

内存:16G

硬盘:50G

三、安装命令:

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     #存放redis配置文件

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

四、配置文件信息:

1、redis 从节点配置文件信息,将该文件保存到/etc/redis目录下

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       #主节点将这一行注释掉

2、sentinel 配置文件

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 启动、关闭脚本,将该文件放到/etc/init.d/目录下,并给与执行权限

#!/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

五、启动redis和sentinel:

/etc/init.d/redis start

/usr/sbin/redis-sentinel /etc/redis/sentinel.conf

六、redis多实例自动配置脚本

#!/bin/bash

set -e

#获取端口号

[ $# -ne 1 ] && echo "Please enter the port number (For example: ./redis-add.sh 4379)" && exit 1

#RP=`echo $1`

RP=$1

#查看配置文件是否存在

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

#生成配置文件

/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

#修改配置文件

SRP=$(( $RP + 10000 ))

#echo $SRP

sed -i s/4379/$RP/ /etc/redis/redis_$RP.conf

sed -i s/4379/$RP/ /etc/redis/sentinel_$RP.conf

sed -i s/r1/r$RP/ /etc/redis/sentinel_$RP.conf

sed -i s/sentinel.log/sentinel_$SRP.log/ /etc/redis/sentinel_$RP.conf

sed -i s/14379/$SRP/ /etc/redis/sentinel_$RP.conf

sed -i s/4379/$RP/ /etc/init.d/redis_$RP

sed -i s/redis.conf/redis_$RP.conf/ /etc/init.d/redis_$RP

#启动redis和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

七、zabbix监控脚本:

#!/bin/bash

HOST="127.0.0.1"

PORT=$1

# 检测redis性能

 function Clients {

    /usr/sbin/redis-cli -h $HOST -p $PORT info Clients | awk -F':' 'NR==2{print $2}'

}

 function Memory {

    used_memory=`/usr/sbin/redis-cli -h $HOST -p $PORT info Memory | awk -F':' 'NR==2{print $2}'| grep -o "[0-9]\+"`

    max_memory=`/usr/sbin/redis-cli -h $HOST -p $PORT info Memory | awk -F':' 'NR==12{print $2}'| grep -o "[0-9]\+"`

    usage_memory=`expr $used_memory \* 100 / $max_memory`

    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 "[a-z]\+"`

    if [ "$INFO" == "Server" ];then

           INFO1=1

    else 

           INFO1=0

    fi

    echo $INFO1

}

# 执行function

$2

八、性能测试:

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

sentinel redis 集群部署+zabbix监控配置+性能测试+多实例自动配置脚本

九、参考文档:

http://www.cnblogs.com/janehoo/p/6118961.html

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:
  1. redis主从+sentinel方式配置
  2. Redis高可用方案哨兵机制------ 配置文件sentinel.conf详解

开发者交流群:

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

redis sentinel 集群配置 配置脚本 edi

上一篇:微信小程序开发如何获取用户手机号码

下一篇:什么是数据表视图中可以进行的操作

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
开发者交流群×