今天,观看尚硅谷Redis视频,讲到Redis集群搭建,为了避免以后遗忘,所以简单记录一下。
Redis集群提供了以下好处:
实现扩容分摊压力无中心配置相对简单Redis集群的不足:
·多键操作是不被支持的多键的Redis事务是不被支持的。lua脚本不被支持。由于集群方案出现较晚,很多公司已经采用了其他的集群方案,而代 理或者客户端分片的方案想要迁移至redis cluster,需要整体迁移而 不是逐步过渡,复杂度较大。1、首先需要创建 6 个,redis.conf个文件,在这里,我在/opt/myRedis目录下创建了以下6个conf文件
2、在创建的配置文件中写入以下内容
include /opt/myRedis/redis.conf pidfile /var/run/redis6379.pid port 6379 dbfilename dump6379.rdb #集群配置 cluster-enabled yes #打开集群模式 cluster-config-file nodes-6379.conf #设置节点配置文件名 cluster-node-timeout 15000 #设置节点失联事件,超过该时间(毫秒),集群自动进行主从切换3、启动redis
[root@localhost myRedis]# redis-server redis6379.conf [root@localhost myRedis]# redis-server redis6380.conf [root@localhost myRedis]# redis-server redis6381.conf [root@localhost myRedis]# redis-server redis6389.conf [root@localhost myRedis]# redis-server redis6390.conf [root@localhost myRedis]# redis-server redis6391.conf [root@localhost myRedis]# ll 总用量 160 -rw-r--r--. 1 root root 805 10月 5 11:18 nodes-6379.conf -rw-r--r--. 1 root root 805 10月 5 11:18 nodes-6380.conf -rw-r--r--. 1 root root 805 10月 5 11:18 nodes-6381.conf -rw-r--r--. 1 root root 805 10月 5 11:18 nodes-6389.conf -rw-r--r--. 1 root root 805 10月 5 11:18 nodes-6390.conf -rw-r--r--. 1 root root 805 10月 5 11:18 nodes-6391.conf [root@localhost myRedis]# ps -ef | grep redis hh4uop 3589 3524 0 09:19 pts/1 00:00:00 vim redis root 4111 3990 0 09:41 pts/4 00:00:00 vim redis.conf root 4311 3990 0 09:57 pts/4 00:00:15 redis-sentinel *:26379 [sentinel] root 5075 1 0 10:49 ? 00:00:07 redis-server *:6380 [cluster] root 5196 1 0 10:55 ? 00:00:07 redis-server *:6381 [cluster] root 5409 1 0 11:10 ? 00:00:05 redis-server *:6379 [cluster] root 5514 1 0 11:15 ? 00:00:05 redis-server *:6389 [cluster] root 5521 1 0 11:16 ? 00:00:05 redis-server *:6390 [cluster] root 5527 1 0 11:16 ? 00:00:04 redis-server *:6391 [cluster] root 6067 3267 0 12:04 pts/0 00:00:00 grep --color=auto redis4、输入以下命令
[root@localhost /]# cd /opt [root@localhost opt]# cd /opt/redis-6.0.8/src [root@localhost src]# ./redis-cli --cluster create 10.132.22.220:6379 10.132.22.220:6380 10.132.22.220:6381 10.132.22.220:6389 10.132.22.220:6390 10.132.22.220:6391 --cluster-replicas 1输入yes
5、以集群的方式进入客户端
[root@localhost myRedis]# redis-cli -c -p 63796、通过cluster nodes命令查看集群信息
发现有三个主服务器,三个从服务器
至此,搭建完成