1.建立目录
/opt/redis/redis-cluster
/opt/redis/redis-cluster/redis_node_7379/conf/
/opt/redis/redis-cluster/redis_node_7379/rdb/
/opt/redis/redis-cluster/redis_node_7380/conf/
/opt/redis/redis-cluster/redis_node_7380/rdb/
/opt/redis/redis-cluster/redis_node_7381/conf/
/opt/redis/redis-cluster/redis_node_7381/rdb/
/opt/redis/redis-cluster/redis_node_7382/conf/
/opt/redis/redis-cluster/redis_node_7382/rdb/
/opt/redis/redis-cluster/redis_node_7383/conf/
/opt/redis/redis-cluster/redis_node_7383/rdb/
/opt/redis/redis-cluster/redis_node_7384/conf/
/opt/redis/redis-cluster/redis_node_7384/rdb/
说明:7379、7380、7381、7382、7383、7384,为集群每个节点的端口
2、redis.conf配置
修改redis.conf配置,以节点7379为例,修改以下项:
daemonize yes #守护进程
port 7379 #每个节点的端口
dir /opt/redis/redis-cluster/redis_node_7379/rdb/ #指定数据文件位置
cluster-enabled yes #启用集群模式
cluster-config-file /opt/redis/redis-cluster/redis_node_7379/conf/node_7379.conf #节点的配置文件,集群启动后自动产生
cluster-node-timeout 1500 #节点访问超时时间为1500毫秒
注释bind 127.0.0.1 #去掉bind绑定访问ip信息
protected-mode no #关闭保护模式
说明:不同的节点,配置文件端口改成节点对应的端口
3、分别启动节点
redis-server /opt/redis/redis-cluster/redis_node_7379/conf/redis.conf
redis-server /opt/redis/redis-cluster/redis_node_7380/conf/redis.conf
redis-server /opt/redis/redis-cluster/redis_node_7381/conf/redis.conf
redis-server /opt/redis/redis-cluster/redis_node_7382/conf/redis.conf
redis-server /opt/redis/redis-cluster/redis_node_7383/conf/redis.conf
redis-server /opt/redis/redis-cluster/redis_node_7384/conf/redis.conf
4、检查进程启动情况
5、构建redis集群
redis-cli [-a xxx] --cluster create --cluster-replicas 1 192.168.0.143:7379 192.168.0.143:7380 192.168.0.143:7381 192.168.0.143:7382 192.168.0.143:7383 192.168.0.143:7384
说明:
(1)redis3时使用的是redis-trib.rb (ruby脚本构建集群)
(2)-a xxx 密码,如果设置了密码的话
6、验证
(1)redis-cli [-a xxx] -c -h 192.168.0.143 -p 7379 #客户端连接 备注:-a xxx 密码,如果设置了密码的话
(2)cluster info #查看集群信息
(3)cluster nodes #查看节点信息
(4)设置值