溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

sentinel redis 集群部署+zabbix監(jiān)控配置+性能測(cè)試+多實(shí)例自動(dòng)配置腳本

發(fā)布時(shí)間:2020-07-23 17:01:54 來源:網(wǎng)絡(luò) 閱讀:2158 作者:lrtao2010 欄目:建站服務(wù)器

一、集群架構(gòu):

sentinel redis 集群部署+zabbix監(jiān)控配置+性能測(cè)試+多實(shí)例自動(dòng)配置腳本


二、服務(wù)器配置:

cpu:4核

內(nèi)存: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 從節(jié)點(diǎn)配置文件信息,將該文件保存到/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       #主節(jié)點(diǎn)將這一行注釋掉



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 啟動(dòng)、關(guān)閉腳本,將該文件放到/etc/init.d/目錄下,并給與執(zhí)行權(quán)限

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


五、啟動(dòng)redis和sentinel:

/etc/init.d/redis start

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


六、redis多實(shí)例自動(dòng)配置腳本

#!/bin/bash

set -e


#獲取端口號(hào)


[ $# -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


#啟動(dòng)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監(jiān)控腳本:


#!/bin/bash

HOST="127.0.0.1"


PORT=$1


# 檢測(cè)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

}


# 執(zhí)行function

$2


八、性能測(cè)試:


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監(jiān)控配置+性能測(cè)試+多實(shí)例自動(dòng)配置腳本


九、參考文檔:

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


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI