1.在opt/redis-7.0.10下 mkdir redisCluster文件目录
cp redis.conf redisCluster
2.vim redis6379.conf
创建6379 6380 6381 6389 6390 6391 六个结点的配置文件
cp redis6379.conf redis6380.conf ........
include /root/myredis/redis.conf
port 6379
pidfile "/var/run/redis_6379.pid"
dbfilename "dump6379.rdb"
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
修改每个配置文件中的内容
3.添加脚本命令:touch start.sh
#!/bin/sh
redis-server redis6379.conf &
redis-server redis6380.conf &
redis-server redis6381.conf &
redis-server redis6389.conf &
redis-server redis6390.conf &
redis-server redis6391.conf &
要求:redis6379名称要与创建的配置文件名称一致
4.关闭脚本vim shutdown.sh
#!/bin/sh
redis-cli -p 6379 shutdown &
redis-cli -p 6380 shutdown &
redis-cli -p 6381 shutdown &
redis-cli -p 6389 shutdown &
redis-cli -p 6390 shutdown &
redis-cli -p 6391 shutdown &
5.执行脚本
#启动redis
sh start.sh
#关闭redis
sh shutdown.sh
6.启动6 个服务
[root@localhost redisCluster]# redis-server redis6379.conf
[root@localhost redisCluster]# redis-server redis6380.conf
[root@localhost redisCluster]# redis-server redis6381.conf
[root@localhost redisCluster]# redis-server redis6389.conf
[root@localhost redisCluster]# redis-server redis6390.conf
[root@localhost redisCluster]# redis-server redis6391.conf
[root@localhost redisCluster]# ps -ef | grep redis
root 13471 10062 0 17:57 pts/1 00:00:00 cp -i redis.conf redisCluster
root 13813 1 0 18:11 ? 00:00:00 redis-server *:6379 [cluster]
root 13814 1 0 18:11 ? 00:00:00 redis-server *:6380 [cluster]
root 13815 1 0 18:11 ? 00:00:00 redis-server *:6391 [cluster]
root 13816 1 0 18:11 ? 00:00:00 redis-server *:6381 [cluster]
root 13817 1 0 18:11 ? 00:00:00 redis-server *:6389 [cluster]
root 13818 1 0 18:11 ? 00:00:00 redis-server *:6390 [cluster]
root 13987 10062 0 18:20 pts/1 00:00:00 grep --color=auto redis
切换到opt/redis-7.0.10/src
运行
redis-cli --cluster create --cluster-replicas 1 192.168.126.128:6379 192.168.126.128:6380 192.168.126.128:6381 192.168.126.128:6389 192.168.126.128:6390 192.168.126.128:6391
7.登录查看
[root@localhost /]# redis-cli -c -p 6379
登录指令添加 -c 代表以集群方式登录
8.查看集群信息
192.168.126.128:6381> CLUSTER NODES