sentinel redis 集群部署+zabbix监控配置+性能测试+多实例自动配置脚本
admin
2023-03-17 13:21:20
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


相关内容

热门资讯

看人下菜碟,中国绝不当冤大头 2026年世界杯开赛在即,国际足联(FIFA)却向中国“狮子大开口”,要求支付巨额转播费用。国际足联...
特朗普还有一场硬仗 新华社北京5月9日电 美国民主、共和两党当前正推动有利本党的国会选区重划,并为此大打官司。弗吉尼亚州...
美国佛州发生疑似船只爆炸事故,... 当地时间5月9日,总台记者获悉,美国佛罗里达州迈阿密海滩附近一处热门水上聚会区域发生疑似船只爆炸事故...
【快看】涉及手机、电脑、电视等... 工业和信息化部、商务部、市场监管总局等部门近日联合启动实施《人工智能终端智能化分级》系列国家标准。 ...
中锂电取得锂电池安全保护装置专... 国家知识产权局信息显示,浙江中锂电科技有限公司取得一项名为“一种锂电池安全保护装置”的专利,授权公告...
奥特曼“官宣” OpenAI ... 文 | AI唱反调 今早,奥特曼发布了一条 X,几乎坐实了近半个月来的传闻。 X正文只有三个词:“...
普京:收到泽连斯基希望会晤的口... 俄罗斯总统普京当地时间5月9日晚召开记者会,回答相关提问。普京表示,此次红场阅兵未展示军事装备,并不...
将论文“写”在秦岭云端 5月7日,团队成员正在进行激光光谱分光测试实验。 “我们在太白山主峰架起自主研制的激光雷达,可以实时...
成都人工智能产业实力领跑西部,... 近日,工业和信息化部发布2025年先进计算赋能新质生产力典型应用案例名单,成都3家人工智能领域企业 ...
铭凡发布「智能体NAS」:第三... 如果说过去几年,NAS市场的关键词还是“私有云”“家庭存储”和“影音库”,那么现在的情况已经悄然发生...