1 redis集群配置模板

vi /opt/cachecloud/conf/redis-cluster-template.conf

daemonize yes

tcp-backlog 511

timeout 0

tcp-keepalive 60

loglevel notice

databases 16

dir /opt/cachecloud/data

stop-writes-on-bgsave-error no

repl-timeout 60

repl-ping-slave-period 10

repl-disable-tcp-nodelay no

repl-backlog-size 10Mb

repl-backlog-ttl 7200

slave-serve-stale-data yes

slave-read-only yes

slave-priority 100

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 512mb 128mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

port {:port}

maxmemory {:maxmemory}mb

maxmemory-policy allkeys-lru

appendonly no

appendfsync everysec

appendfilename appendonly-{:port}.aof

dbfilename dump-{:port}.rdb

aof-rewrite-incremental-fsync yes

no-appendfsync-on-rewrite yes

auto-aof-rewrite-min-size 4000000kb

auto-aof-rewrite-percentage 88

rdbcompression yes

rdbchecksum yes

repl-diskless-sync no

repl-diskless-sync-delay 5

maxclients 10000

hll-sparse-max-bytes 3000

min-slaves-to-write 0

min-slaves-max-lag 10

aof-load-truncated yes

notify-keyspace-events ""

protected-mode no

cluster-enabled yes

cluster-node-timeout 15000

cluster-slave-validity-factor 10

cluster-migration-barrier 1

cluster-config-file nodes-{:port}.conf

cluster-require-full-coverage no

2 一键配置脚本

vi redisCluster.sh

CONF_DIR="/opt/cachecloud/conf/";

LOG_DIR="/opt/cachecloud/logs/";

REDIS_SRC_DIR="/opt/cachecloud/redis/src/";

REDIS_CLUSTER_TEMPLATE="/opt/cachecloud/conf/redis-cluster-template.conf"

SLOT_SIZE=16384

PORTS=(6961 6962 6963 6964 6965 6966)

MAX_MEMORY=100

function _createConfigFile()

{

local isAllExists=1

local i=0

local port=0

local configFile=''

for(( i=0;i

do

port=${PORTS[i]}

configFile=$CONF_DIR"redis-cluster-"$port".conf"

if [ ! -f $configFile ]; then

isAllExists=0

break

fi

done

if [ $isAllExists -eq 1 ];then

return 0

fi

for(( i=0;i

do

port=${PORTS[i]}

configFile=$CONF_DIR"redis-cluster-"$port".conf"

cp $REDIS_CLUSTER_TEMPLATE $configFile -f

sed -i 's/{:port}/'$port'/g' $configFile

sed -i 's/{:maxmemory}/'$MAX_MEMORY'/g' $configFile

done

}

function _runRedisServer()

{

local port=0

local configFile=''

local redisServerCmd=''

local logFile=''

local curDateTime=''

local res=''

for(( i=0;i

do

port=${PORTS[i]}

configFile=$CONF_DIR"redis-cluster-"$port".conf"

redisServerCmd=$REDIS_SRC_DIR"redis-server"

curDateTime=`date +%Y%m%d%H%M`

logFile=$LOG_DIR"redis-"$port"-"$curDateTime".log"

cmd=$redisServerCmd" "$configFile

res=`$cmd > $logFile 2>&1 &`

done

}

function _meet()

{

local firstPort=${PORTS[0]}

local port=0

local res=''

local i=0

for(( i=0;i

do

port=${PORTS[i]}

cmd=$REDIS_SRC_DIR"redis-cli -p "$firstPort" --raw cluster meet 127.0.0.1 "$port

res=`$cmd > /dev/null 2>&1`

done

}

function _slotadd()

{

local count=${#PORTS[@]}

local masterCount=`expr $count / 2`

local pageSize=`expr $SLOT_SIZE / $masterCount`

local index=0

local tmpStart=0

local tmpEnd=0

local slot=0

local slotList=()

local i=0

local endSlot=`expr $SLOT_SIZE - 1`

local page=0

local key=''

for(( i=0;i

do

let index=index+1;

if [[ $index -gt $pageSize || $i -eq endSlot ]];then

tmpEnd=$i

key=$tmpStart":"$tmpEnd

slotList[$page]=$key

let tmpStart=tmpEnd+1

let page=page+1

index=0

fi

done

local slotIndex=0

local remainder=0

local res=''

for(( i=0;i

do

remainder=$(( $i % 2 ))

if [ $remainder -eq 1 ] ; then

continue

fi

start=${slotList[$slotIndex]%:*}

end=${slotList[$slotIndex]#*:}

port=${PORTS[i]}

# redis-cli -p 6961 cluster addslots {0..5461}

# redis-cli -p 6963 cluster addslots {5462..10923}

# redis-cli -p 6965 cluster addslots {10924..16383}

cmd=$REDIS_SRC_DIR"redis-cli -p "$port" cluster addslots {"$start".."$end"}"

python -c "import os;os.system('$cmd')" > /dev/null

let slotIndex=slotIndex+1

done

}

function _slave()

{

local cmd=$REDIS_SRC_DIR"redis-cli -p "${PORTS[0]}" cluster nodes"

local nodesMap=`$cmd | awk '{start =index($2,":"); end = index($2,"@"); port = substr($2,start + 1,end - start -1);key = (port":"$1);print key}'`

local portArr=()

local nodeIdArr=()

local index=0

local item=''

for item in $nodesMap

do

portArr[$index]=${item%:*}

nodeIdArr[$index]=${item#*:}

let index=index+1;

done;

local nodeIdArrOrder=()

local i=0

local j=0

for(( i=0;i

do

for(( j=0;j

do

if [ ${PORTS[$i]} -eq ${portArr[$j]} ] ;then

nodeIdArrOrder[$i]=${nodeIdArr[$j]}

fi

done

done

local k=0

local res=''

for(( k=0;k

do

remainder=$(( $k % 2 ))

if [ $remainder -eq 0 ] ; then

continue

fi

tmpPort=${PORTS[$k]}

nodeIdIndex=`expr $k - 1`

tmpMasterNodeId=${nodeIdArrOrder[$nodeIdIndex]}

cmd=$REDIS_SRC_DIR"redis-cli -p "$tmpPort" cluster replicate "$tmpMasterNodeId

res=`$cmd`

# try agin

if [[ $res != "OK" ]];then

sleep 2

res=`$cmd`

fi

done

}

function start()

{

_createConfigFile

_runRedisServer

_meet

_slotadd

sleep 1

_slave

}

function stop()

{

local k=0

local res=''

for(( k=0;k

do

cmd=$REDIS_SRC_DIR"redis-cli -p "${PORTS[$k]}" shutdown nosave"

res=`$cmd`

done

}

function flushAll()

{

local k=0

local res=''

for(( k=0;k

do

remainder=$(( $k % 2 ))

if [ $remainder -eq 1 ] ; then

continue

fi

cmd=$REDIS_SRC_DIR"redis-cli -p "${PORTS[$k]}" --raw flushall"

res=`$cmd`

done

}

function run()

{

if [ "redis" != $(whoami) ];then

echo "ERROR,you must use redis user to run this script"

return

fi

local action=$1;

case $action in

start)

start

echo "OK"

;;

stop)

stop

echo "OK"

;;

restart)

stop

start

echo "OK"

;;

flushAll)

flushAll

echo "OK"

;;

*)

echo "ERROR cmd invalid";

echo "useage:"

echo "sh redisCluster.sh start|stop|restart|flushAll"

;;

esac

}

run $1

linux stoping redis,redis的cluster集群模式shell一键启动/停止/重启/清缓存脚本相关推荐

  1. Redis 高级特性(5)— 集群模式(主从模式、哨兵模式、cluster 集群模式)

    Redis 是如何做到高可用的呢? 它主要通过支持主从模式.哨兵模式.集群模式这三种模式,来满足不同业务特点和可用等级的需求. 其中,主从模式部署最简单,用得也最多,集群模式比较复杂,但可用性最高. ...

  2. redis 3.0 cluster 集群 学习之路篇 [3]

    周氏一族,整理技术文档,给下一代留点教程...... redis 3.0 cluster 安装篇,请看 http://zhoushouby.blog.51cto.com/9150272/1560400 ...

  3. CentOS7下安装Redis伪集群(基于Redis官方Cluster集群模式版本redis-5.0.10)

    文章目录 Redis简介 什么是redis redis的优点 Redis集群都有哪些模式 主从复制(Master-Slave Replication) 哨兵模式(Sentinel) Redis官方 C ...

  4. Redis Cluster 集群模式原理和动态扩容

    Redis Cluster原理 详细参考 Redis cluster集群模式的原理, 在这里补充下要点 16384个slot, 平均分布在各个master, key-value 对存储在slot中; ...

  5. redis cluster集群模式简述

    前言 redis最开始使用主从模式做集群,若master宕机需要手动配置slave转为master:后来为了高可用提出来哨兵模式,该模式下有一个哨兵监视master和slave,若master宕机可自 ...

  6. Redis集群搭建(Cluster 集群模式,分片集群)

    Redis集群搭建Cluster 集群模式 引言 Redis的集群介绍 搭建方法 创建集群 其他服务的搭建 引言 redis相信大家不陌生,是最常用的缓存解决方案了.但是,在服务开发中,单机都会存在单 ...

  7. redis的三种集群模式原理

    一.主从同步/复制 通过持久化功能,Redis保证了即使在服务器重启的情况下也不会丢失(或少量丢失)数据,因为持久化会把内存中数据保存到硬盘上,重启会从硬盘上加载数据. 但是由于数据是存储在一台服务器 ...

  8. reids 5.0.4 cluster集群模式部署实操。

    一.准备工作 5.0.4的redis压缩包,可以自行去官网下载. linux环境 二.解压并且安装 1.新建6个文件夹用于安装redis目录 目录路径为/root/tools/7001 [root@m ...

  9. mysql cluster_redislt;3.cluster集群模式gt;

    不点蓝字,我们哪来故事? 本文约:2000字 预计阅读时间:5分钟 1 前言 现在已经到了国庆的末尾了,大家这个国庆过的怎么样?是否已经顺利地从家中返航? 当你看到这篇文章的时候,就知道moon要来提 ...

最新文章

  1. 简单实现ConfigurationManager.AppSettings[]效果存储系统变量
  2. Xcode使用正则表达式替换
  3. Apache ZooKeeper - Leader Election使用场景
  4. strtus2改成springboot_jdk1.6环境下struts2改spring boot方案
  5. Redhat 停止sendmail的方法
  6. linux+nginx+mysql+php系统修改文件上传大小限制
  7. javaserver_集成Spring和JavaServer Faces:改进的模板
  8. vip地址能ping不通_电脑高手必备ping和netstat命令
  9. 关于BaseAdapter在listView中的使用
  10. centos安装python3.5_CentOS 7安装Python3.5
  11. galaxy+note8+android+8.0,三星已经开始了S8/S8+以及Note8的Android9.0更新的开发工作!
  12. error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
  13. 数据库-Oracle【Oracle 三种集合数据类型的比较 】
  14. UE的HoudiniEngine插件版本的匹配问题
  15. android交叉编译libxml2,libxml2 ARM 交叉编译
  16. 设计资源神器,国外网盘免费下载揭秘!
  17. w10计算机右键管理,Win10右键菜单怎么管理
  18. Android工作经验6年,Android事件分发机制收藏这一篇就够了,分享PDF高清版
  19. NCAE(全国工业和信息化应用人才考试 )-- 服务外包 JAVA 软件开发复习整理(一)
  20. 小程序showLoading:网络请求前显示“加载中...”,请求完成时关闭加载中

热门文章

  1. C#LeetCode刷题-递归
  2. 斯坦福所倡导的设计思维_针对高科技项目的有效开发商倡导
  3. 如何使用JavaScript控制台:超越console.log()
  4. 逻辑回归优点_逻辑回归:优点
  5. 数据结构链表例程_如何掌握RxJava例程的四个结构
  6. des加密的c语言程序,C++中四种加密算法之DES源代码
  7. acme编辑器linux版,CAD迷你编辑器
  8. Java多线程:静态代理模式
  9. Python-关于正则表达式的总结
  10. Python3.6字符串新特性