Redis集群部署安装

Linux版本:CentOS release 6.9

Redis 版本:redis-3.2.12.tar.gz

1、执行解压命令

tar -xzf redis-3.2.12.tar.gz

Redis3.2集群部署安装-LMLPHP

2、执行编译命令

make MALLOC=libc

Redis3.2集群部署安装-LMLPHP

Redis3.2集群部署安装-LMLPHP

3、执行安装到指定目录命令,此次指定目录为 /my/mysys/redis

make PREFIX=/my/mysys/redis install

Redis3.2集群部署安装-LMLPHP

完成后目录结构

Redis3.2集群部署安装-LMLPHP

4、单服务器模拟3主3从部署

节点(文件夹)

ip

端口

类型

cp001

192.168.96.128

6371

cp002

192.168.96.128

6372

cp003

192.168.96.128

6373

cp004

192.168.96.128

6374

cp005

192.168.96.128

6375

cp006

192.168.96.128

6376

1) 创建文件夹

Redis3.2集群部署安装-LMLPHP

2) 配置文件

bind 192.168.96.128

protected-mode no

port 6376

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes  #后台运行

supervised no

pidfile /jq_redis/cp006/pid.pid #进程号

loglevel notice

logfile /jq_redis/cp006/log/log.log #日志文件

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 /jq_redis/cp006/data/   #数据位置

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

maxmemory 50gb

maxmemory-policy noeviction

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

cluster-enabled yes   #开启集群

cluster-config-file nodes-6376.conf  #集群日志

cluster-node-timeout 15000

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

3) 启动

/jq_redis/cp001/redis/bin/redis-server /jq_redis/cp001/redis.conf

/jq_redis/cp002/redis/bin/redis-server /jq_redis/cp002/redis.conf

/jq_redis/cp003/redis/bin/redis-server /jq_redis/cp003/redis.conf

/jq_redis/cp004/redis/bin/redis-server /jq_redis/cp004/redis.conf

/jq_redis/cp005/redis/bin/redis-server /jq_redis/cp005/redis.conf

/jq_redis/cp006/redis/bin/redis-server /jq_redis/cp006/redis.conf

Redis3.2集群部署安装-LMLPHP

4) 配置集群

进入任意一个节点

/jq_redis/cp001/redis/bin/redis-cli -h 192.168.96.128 -p 6371

Redis3.2集群部署安装-LMLPHP

与其他节点握手

cluster meet 192.168.96.128 6372

cluster meet 192.168.96.128 6373

cluster meet 192.168.96.128 6374

cluster meet 192.168.96.128 6375

cluster meet 192.168.96.128 6376

Redis3.2集群部署安装-LMLPHP

分配 hash 槽

/jq_redis/cp001/redis/bin/redis-cli -h 192.168.96.128 -p 6371 cluster addslots {0..5461}

/jq_redis/cp002/redis/bin/redis-cli -h 192.168.96.128 -p 6372 cluster addslots {5462..10922}

/jq_redis/cp003/redis/bin/redis-cli -h 192.168.96.128 -p 6373 cluster addslots {10923..16383}

Redis3.2集群部署安装-LMLPHP

5) 复制节点

登陆节点查看节点信息

cluster nodes

Redis3.2集群部署安装-LMLPHP

依次登陆3个副本节点,设置复制的节点id

[root@centos01 ~]# /jq_redis/cp001/redis/bin/redis-cli -h 192.168.96.128 -p 6374

192.168.96.128:6374> cluster replicate 1fcec13c4ba9d580cc8a30eab636f52f2c95effb

OK

192.168.96.128:6374> exit

[root@centos01 ~]# /jq_redis/cp001/redis/bin/redis-cli -h 192.168.96.128 -p 6375

192.168.96.128:6375> cluster replicate a10ea0df49121e7d609520b21b26d012db551923

OK

192.168.96.128:6375> exit

[root@centos01 ~]# /jq_redis/cp001/redis/bin/redis-cli -h 192.168.96.128 -p 6376

192.168.96.128:6376> cluster replicate e835ce0d8c535deda7e4d830661b1f8f1172d85d

OK

192.168.96.128:6376> cluster nodes

a10ea0df49121e7d609520b21b26d012db551923 192.168.96.128:6372 master - 0 1537979650515 2 connected 5462-10922

2eb1edcffec6a8de13cc46a60fb4e6c6f10a33f1 192.168.96.128:6376 myself,slave e835ce0d8c535deda7e4d830661b1f8f1172d85d 0 0 5 connected

e835ce0d8c535deda7e4d830661b1f8f1172d85d 192.168.96.128:6373 master - 0 1537979646480 0 connected 10923-16383

c22df51ebc325ee0973ecfc7ed7cb4b5c931e05c 192.168.96.128:6375 slave a10ea0df49121e7d609520b21b26d012db551923 0 1537979647488 3 connected

1fcec13c4ba9d580cc8a30eab636f52f2c95effb 192.168.96.128:6371 master - 0 1537979649506 1 connected 0-5461

3f3ce9cab0d9b82bfdc1864aab1884d3ad23d2fa 192.168.96.128:6374 slave 1fcec13c4ba9d580cc8a30eab636f52f2c95effb 0 1537979648498 4 connected

Redis3.2集群部署安装-LMLPHP

测试数据

登陆集群 /jq_redis/cp001/redis/bin/redis-cli -c -h 192.168.96.128 -p 6376

Redis3.2集群部署安装-LMLPHP

05-11 21:49