Redis 伪集群的构建
1.创建 集群文件夹:
mkdir -p /usr/redis-3.2.4/cluster/7701/
mkdir -p /usr/redis-3.2.4/cluster/7702/
mkdir -p /usr/redis-3.2.4/cluster/7703/
mkdir -p /usr/redis-3.2.4/cluster/7704/
mkdir -p /usr/redis-3.2.4/cluster/7705/
mkdir -p /usr/redis-3.2.4/cluster/7706/
2.复制 redis-server,可以将整个 redis 的 src文件夹拷贝进去。
cp -r /usr/redis-3.2.4/src /usr/redis-3.2.4/cluster/7701/
cp -r /usr/redis-3.2.4/src /usr/redis-3.2.4/cluster/7702/
cp -r /usr/redis-3.2.4/src /usr/redis-3.2.4/cluster/7703/
cp -r /usr/redis-3.2.4/src /usr/redis-3.2.4/cluster/7704/
cp -r /usr/redis-3.2.4/src /usr/redis-3.2.4/cluster/7705/
cp -r /usr/redis-3.2.4/src /usr/redis-3.2.4/cluster/7706/
3.新建 redis.conf
daemonize no
pidfile /var/run/redis.pid
修改端口
port 16001
bind 内网ip
tcp-backlog 511
timeout 0
tcp-keepalive 0
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 ./
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
修改为yes
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
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-entries 512
list-max-ziplist-value 64
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
=========================新增===============================
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
========================================================
内网连接是否可用:
redis-cli -h 10.105.51.14 -p 7701
因为redis3.0以上是默认redis的只能本机访问,所以这里必须是测试一下内网是否可以访问。
3.复制redis.conf
cp /usr/redis-3.2.4/cluster/7701/redis.conf /usr/redis-3.2.4/cluster/7702/redis.conf
cp /usr/redis-3.2.4/cluster/7701/redis.conf /usr/redis-3.2.4/cluster/7703/redis.conf
cp /usr/redis-3.2.4/cluster/7701/redis.conf /usr/redis-3.2.4/cluster/7704/redis.conf
cp /usr/redis-3.2.4/cluster/7701/redis.conf /usr/redis-3.2.4/cluster/7705/redis.conf
cp /usr/redis-3.2.4/cluster/7701/redis.conf /usr/redis-3.2.4/cluster/7706/redis.conf
注意更换端口。
4.
创建集群,让上面的实例互相通讯(1 表示为每个master分配一个salve)
/usr/redis-3.2.4/src/redis-trib.rb create –replicas 1 \
10.105.51.14:7701 \
10.105.51.14:7702 \
10.105.51.14:7703 \
10.105.51.14:7704 \
10.105.51.14:7705 \
10.105.51.14:7706
5.查看所有的集群信息:
redis-cli -c -h 10.105.51.14 -p 7701