安装环境: 6 台 centos7.4
在各个节点下载官网 release 包, 可以自己去官网找:
wget
解压: tar -zxvf Redis-5.0.5.tar.gz
进入目录: cd Redis-5.0.5, 如果自定义了解压目录的话需要另外指定
编译: make , 编译即可, 会在 src 目录下生成二进制文件, 即可运行 Redis
如果编译时出现提示 jemalloc/jemalloc.h: No such file or directory
重新使用 make MALLOC=libc 安装
编译完成即可运行单机
修改 Redis.conf 的配置, 使用一个最简配置: 可以把原先的做一个备份, 然后生成一个新的
- port 6379
- cluster-enabled yes
- cluster-config-file nodes.conf // 启动的时候会由 Redis 生成和管理
- cluster-node-timeout 5000
- appendonly yes
- daemonize yes // 后台运行
- bind 10.99.32.16 // 需要绑定自己的 ip, 否则外部不能访问, 每个节点都需要修改配置
不要添加 // 里面的内容
每个节点运行实例: src/Redis-server ./Redis.conf, 启动成功会提示
- 1467:C 28 Jun 2019 20:22:30.943 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
- 1467:C 28 Jun 2019 20:22:30.943 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1467, just started
- 1467:C 28 Jun 2019 20:22:30.943 # Configuration loaded
启动脚本:(之前的版本需要使用 Ruby 脚本需要更多一些操作, 5.0 的可以使用 Redis-cli 命令)
src/Redis-cli --cluster create 10.99.32.3:6379 10.99.32.9:6379 10.99.32.31:6379 10.99.32.10:6379 10.99.32.12:6379 10.99.32.13:6379 --cluster-replicas 1
启动成功后会有节点显示:
[OK] All nodes agree about slots configuration.
\>>> Check for open slots...
\>>> Check slots coverage...
[OK] All 16384 slots covered.
六台节点一个副本则有 3M3S
连接到集群 src/Redis-cli -h 10.99.32.3 -c, 如果不使用 - c, 设置 key 时会报: Redis (error) MOVED 7638
设置缓存后, 只有一个 M 和它的 Slave 有这个数据, 其他节点没有这个数据
追加节点
src/Redis-cli --cluster add-node 10.99.32.32:6379 10.99.32.3:6379
查看节点
src/Redis-cli -h 10.99.32.9 -c cluster nodes
删除节点
src/Redis-cli --cluster del-node 10.99.32.9:6379 08859612fdf824fd07c538c65073a86ca7d522cb
需要先获取节点 node-id
来源: http://www.bubuko.com/infodetail-3107484.html