redis集群搭建

Posted lpaxq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis集群搭建相关的知识,希望对你有一定的参考价值。

mkdir /usr/local/redis
cp /tmp/redis-4.0.0.tar.gz /usr/local/redis/
cp /tmp/ruby-2.3.2.tar.gz /usr/local/redis/
cd /usr/local/redis
tar -zxvf redis-4.0.0.tar.gz
cd redis-4.0.0
make
make test
cd src/
cp -a redis-server redis-cli redis-sentinel redis-trib.rb redis-check-aof redis-check-rdb redis-benchmark /usr/local/bin/
cd /usr/local/redis
mkdir redis-cluster
cd redis-cluster/
mkdir nodes-{7001,7002,7003}
二节点
mkdir nodes-{7004,7005,7006}
cp redis.conf到各个节点中

egrep -v "^#|^$" redis.conf
%s/7001/7002/g
/usr/local/redis/redis-cluster/nodes-7001/redis_7001.log


redis.conf:


bind 192.168.8.14
protected-mode yes
port 7002
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_7002.pid
loglevel notice
logfile "/usr/local/redis/redis-cluster/nodes-7002/redis_7002.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/redis-cluster/nodes-7002/
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
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
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
aof-use-rdb-preamble no
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-7002.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
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

启动各节点:
redis-server /usr/local/redis/redis-cluster/nodes-7001/redis.conf
redis-server /usr/local/redis/redis-cluster/nodes-7002/redis.conf
redis-server /usr/local/redis/redis-cluster/nodes-7003/redis.conf
redis-server /usr/local/redis/redis-cluster/nodes-7004/redis.conf
redis-server /usr/local/redis/redis-cluster/nodes-7005/redis.conf
redis-server /usr/local/redis/redis-cluster/nodes-7006/redis.conf

kill -9 `ps -ef | grep redis | grep -v grep | awk ‘{print $2}‘`

安装ruby:
cd /usr/local/redis/
tar -zxvf ruby-2.3.2.tar.gz
cd ruby-2.3.2
./configure
make && make install
gem install redis


redis-trib.rb create --replicas 1 192.168.8.14:7001 192.168.8.14:7002 192.168.8.14:7003 192.168.8.15:7004 192.168.8.15:7005 192.168.8.15:7006

 































































































以上是关于redis集群搭建的主要内容,如果未能解决你的问题,请参考以下文章

Redis Cluster集群的搭建

Redis实战-Redis集群环境搭建(自动搭建)

Redis实战-Redis集群环境搭建(自动搭建)

一般Redis集群搭建采用几台服务器?

redis集群搭建怎么分配内存的

Redis Cluster基于Docker的集群搭建