搭建 redis-cluster集群
程序员文章站
2022-05-22 08:22:24
...
1.集群环境
操作系统版本:centos7
redis版本:5.0.3.tar.gz
三台服务器:192.168.137.160、192.168.137.161、192.168.137.162
六个redis节点:node1、node2、node3、node4、node5、node6
节点角色:
(node1、node2、node3)–master 【0-16384】 三个主节点分配hash槽,
(node4、node5、node6 )–slaver 三个从节点备份
2. 集群安装
(1)在 /opt/redis/下创建文件夹 mkdir redis-cluster
,将redis.5.0.3拷贝到redis-cluster中并解压出两个redis,分别重命名,如下所示。(3个节点相同操作)
(2)创建数据文件夹:
mkdir redis-data
cd redis-data
mkdir 7001
mkdir 7002
(3)创建不同节点的cluster的配置文件:
touch redis-7001.conf
touch redis-7002.conf
修改每个配置文件:
vim redis-7001.conf
port 7001
daemonize yes
pidfile /var/run/redis_7001.pid
dir /opt/redis/redis-cluster/redis-data/7001
cluster-enabled yes
protected-mode no
cluster-config-file nodes_7001.conf
cluster-node-timeout 10100
appendonly yes
vim redis-7002.conf
port 7002
daemonize yes
pidfile /var/run/redis_7002.pid
dir /opt/redis/redis-cluster/redis-data/7002
cluster-enabled yes
protected-mode no
cluster-config-file nodes_7002.conf
cluster-node-timeout 10100
appendonly yes
此时在redis-cluster文件夹下为
(4)创建启动集群的脚本redis-start.sh
/opt/redis/redis-cluster/redis1/src/redis-server /opt/redis/redis-cluster/redis-7001.conf
/opt/redis/redis-cluster/redis2/src/redis-server /opt/redis/redis-cluster/redis-7002.conf
至此。其他节点重复一遍
(5)启动:./redis-start.sh
(6)创建或配置rediscluster集群(和第8一样)
./redis-cli --cluster create 192.168.137.160:7001 192.168.137.160:7002 192.168.137.161:7001 192.168.137.161:7002 192.168.137.162:7001 192.168.137.162:7002 --cluster-replicas 1
(7)停止集群脚本 redis-stop.sh
/opt/redis/redis-cluster/redis1/src/redis-cli -p 7001 shutdown
/opt/redis/redis-cluster/redis1/src/redis-cli -p 7002 shutdown
(8) 验证集群
执行
./redis-cli --cluster create 192.168.137.160:7001 192.168.137.160:7002 192.168.137.161:7001 192.168.137.161:7002 192.168.137.162:7001 192.168.137.162:7002 --cluster-replicas 1
(9)登陆集群,在任意一台redis的src目录中执行
./redis-cli -c -h 127.0.0.1 -p 7001
查看集群状态
cluster info
(10)外部查看集群状态
./redis-cli cluster check 127.0.0.1:7001
上一篇: 并查集
推荐阅读