搭建redis集群
- 多机器版本
- 最少6台机器,分别在其中六台机器也部署一套redis
#/bin/bash#创建redis主目录,数据库存放目录,日志目录,pid目录mkdir /data/redismkdir /data/redis/data/6301mkdir /data/redis/logsmkdir /data/redis/pid#安装依赖yum install -y gcc tcl#下载redis安装包wget https://download.redis.io/releases/redis-6.0.8.tar.gz#解压安装包tar -xvf redis-6.0.8.tar.gz#移动文件到redis安装目录mv redis-6.0.8 /data/redis/#开始编译make && make install#测试编译make test#如果看到以下字样:表示无错误: \o/ All tests passed without errors!grep ^[a-Z] redis_6379.confbind 192.168.13.212 # 允许通信ipprotected-mode yesport 6301 # 其他集群机器分别也要不同6302、6303、6304、6305、6306tcp-backlog 511timeout 0tcp-keepalive 300daemonize yes # redis后台运行pidfile /var/run/redis_6301.pid # pid文件loglevel noticelogfile "/data/redis_cluster/logs/redis_6301.log" # 集群日志文件databases 16always-show-logo noset-proc-title yesproc-title-template "{title} {listen-addr} {server-mode}"stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbrdb-del-sync-files nodir ./ # 配置数据文件存放路劲replica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-diskless-load disabledrepl-disable-tcp-nodelay noreplica-priority 100acllog-max-len 128maxmemory 64Mlazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush nolazyfree-lazy-user-del nolazyfree-lazy-user-flush nooom-score-adj nooom-score-adj-values 0 200 800disable-thp yesappendonly no # 是否开启aofappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble yeslua-time-limit 5000cluster-enabled yes # 开启集群状态cluster-config-file nodes-6301.conf # 集群的配置cluster-node-timeout 15000 # 集群请求超时 默认15秒,可自行设置slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000stream-node-max-bytes 4096stream-node-max-entries 100activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit replica 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10dynamic-hz yesaof-rewrite-incremental-fsync yesrdb-save-incremental-fsync yesjemalloc-bg-thread yes#启动redis/data/redis/redis-6.0.8/src/redis-server /data/redis/redis_6301.conf &
port 6301 # 端口6302、6303、6304、6305、6306
bind 192.168.11.11 # 允许通信ip
daemonize yes # redis后台运行
pidfile /usr/local/redis-cluster/redis1/redis_7001.pid # pidfile文件对应6302、6303、6304、6305、6306
cluster-enabled yes # 开启集群
cluster-config-file nodes_7001.conf # 集群的配置 配置文件首次启动自动生成 6302、6303、6304、6305、6306
cluster-node-timeout 15000 # 请求超时 默认15秒,可自行设置
appendonly yes # 开启aof
logfile "/usr/local/redis-cluster/redise1/logs/redis_7001.log" # 配置日志输入路劲 6302、6303、6304、6305、6306
dir "/usr/local/redis-cluster/redis1/data" # 配置数据文件存放路劲
创建集群
- 找一台机器做master控制集群节点,或者也可以在redis集群中其中一台安装master节点
yum -y install ruby ruby-devel rubygems rpm-build
rvm -v
gem install redis
yum install -y rubygems
redis-cli --cluster create 192.168.13.1:6301 192.168.13.2:6302 192.168.13.3:6303 192.168.13.4:6304 192.168.13.5:6305 192.168.13.6:6306 --cluster-replicas 1