这篇文章主要介绍了理论+实验——Redis集群的讲解,通过具体代码实例进行16298 讲解,并且分析了理论+实验——Redis集群的详细步骤与相关技巧,需要的朋友可以参考下https://www.b2bchain.cn/?p=16298
本文实例讲述了2、树莓派设置连接WiFi,开启VNC等等的讲解。分享给大家供大家参考文章查询地址https://www.b2bchain.cn/7039.html。具体如下:
文章目录
- 一、Redis集群
-
- 1.1 概述
- 1.2 优势
- 1.3 实现方法
- 1.4 Redis-Cluster数据分片
- 二、问题
-
- 2.1 单节点Redis服务器带来的问题
- 2.2 解决方法
- 三、实验
一、Redis集群
1.1 概述
1.2 优势
1.3 实现方法
1.4 Redis-Cluster数据分片
二、问题
2.1 单节点Redis服务器带来的问题
2.2 解决方法
三、实验
——————————-Redis(所有节点操作)——————————-
[[email protected] utils]# vim /etc/redis/6379.conf 70 #bind 127.0.0.1 89 protected-mode no 93 port 6379 137 daemonize yes 833 cluster-enabled yes 841 cluster-config-file nodes-6379.conf 847 cluster-node-timeout 15000 700 appendonly yes [[email protected] utils]# /etc/init.d/redis_6379 restart [[email protected] utils]# cd /var/lib/redis/6379/ [[email protected] 6379]# ls appendonly.aof dump.rdb nodes-6379.conf
——————————-仅master操作——————————-
[[email protected] ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 [[email protected] ~]# curl -sSL https://get.rvm.io | bash -s stable [email protected] profile.d]# source /etc/profile.d/rvm.sh [[email protected] profile.d]# rvm list known [[email protected] profile.d]# rvm install 2.4.1 [[email protected] profile.d]# rvm use 2.4.1 Using /usr/local/rvm/gems/ruby-2.4.1 [[email protected] profile.d]# ruby -v ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] [[email protected] profile.d]# gem install redis Fetching redis-4.2.2.gem Successfully installed redis-4.2.2 Parsing documentation for redis-4.2.2 Installing ri documentation for redis-4.2.2 Done installing documentation for redis after 0 seconds 1 gem installed 'master和node节点,各添加两个网卡,共六个' [[email protected] network-scripts]# /etc/init.d/redis_6379 restart [[email protected] 6379]# redis-cli --cluster create 20.0.0.128:6379 20.0.0.129:6379 20.0.0.22:6379 20.0.0.23:6379 20.0.0.4:6379 20.0.0.5:6379 --cluster-replicas 1 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 20.0.0.4:6379 to 20.0.0.128:6379 Adding replica 20.0.0.5:6379 to 20.0.0.129:6379 Adding replica 20.0.0.23:6379 to 20.0.0.22:6379 M: 44be018f73f20343548cf587cfb5c83c2a7b0099 20.0.0.128:6379 slots:[0-5460] (5461 slots) master M: 44be018f73f20343548cf587cfb5c83c2a7b0099 20.0.0.129:6379 slots:[5461-10922] (5462 slots) master M: 44be018f73f20343548cf587cfb5c83c2a7b0099 20.0.0.22:6379 slots:[10923-16383] (5461 slots) master S: 832077e6e98788914583c6cdaea9e54e3a2d7bfc 20.0.0.23:6379 replicates 44be018f73f20343548cf587cfb5c83c2a7b0099 S: 832077e6e98788914583c6cdaea9e54e3a2d7bfc 20.0.0.4:6379 replicates 44be018f73f20343548cf587cfb5c83c2a7b0099 S: 832077e6e98788914583c6cdaea9e54e3a2d7bfc 20.0.0.5:6379 replicates 44be018f73f20343548cf587cfb5c83c2a7b0099 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join >>> Performing Cluster Check (using node 20.0.0.128:6379) M: 44be018f73f20343548cf587cfb5c83c2a7b0099 20.0.0.128:6379 slots:[0-16383] (16384 slots) master 1 additional replica(s) S: 832077e6e98788914583c6cdaea9e54e3a2d7bfc 20.0.0.23:6379 slots: (0 slots) slave replicates 44be018f73f20343548cf587cfb5c83c2a7b0099 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [[email protected] 6379]# netstat -anpt | grep 6379 tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 25899/redis-server tcp 0 0 0.0.0.0:16379 0.0.0.0:* LISTEN 25899/redis-server tcp 0 0 20.0.0.128:35538 20.0.0.128:16379 TIME_WAIT - tcp 0 0 20.0.0.128:57292 20.0.0.23:16379 ESTABLISHED 25899/redis-server tcp 0 0 20.0.0.128:59008 20.0.0.4:6379 TIME_WAIT - tcp 0 0 20.0.0.128:16379 20.0.0.23:47274 ESTABLISHED 25899/redis-server tcp 0 0 20.0.0.128:39346 20.0.0.23:6379 TIME_WAIT - tcp 0 0 20.0.0.128:6379 20.0.0.23:54820 ESTABLISHED 25899/redis-server tcp 0 0 20.0.0.129:44766 20.0.0.129:6379 TIME_WAIT - tcp 0 0 20.0.0.128:38400 20.0.0.5:6379 TIME_WAIT - tcp 0 0 20.0.0.128:39356 20.0.0.23:6379 TIME_WAIT - tcp 0 0 20.0.0.22:36644 20.0.0.22:6379 TIME_WAIT - tcp 0 0 20.0.0.128:53528 20.0.0.128:6379 TIME_WAIT - tcp6 0 0 :::6379 :::* LISTEN 25899/redis-server tcp6 0 0 :::16379
测试:
redis-cli -c -h 20.0.0.4 -p 6379 ###加个 -c 开启集群,就可以看到了 [[email protected] 6379]# redis-cli -c -h 20.0.0.128 -p 6379 20.0.0.128:6379> set name oo OK 20.0.0.128:6379> keys * 1) "name" 20.0.0.128:6379> get name "oo" 20.0.0.128:6379> exit [[email protected] 6379]# redis-cli -c -h 20.0.0.129 -p 6379 20.0.0.129:6379> keys * 1) "name" 20.0.0.129:6379> get name "oo" 20.0.0.129:6379> exit [[email protected] 6379]# redis-cli -c -h 20.0.0.22 -p 6379 20.0.0.22:6379> keys * 1) "name" 20.0.0.22:6379> get name "oo" 20.0.0.22:6379> exit [[email protected] 6379]# redis-cli-c -h 20.0.0.23 -p 6379 20.0.0.23:6379> keys * 1) "name" 20.0.0.23:6379> get name -> Redirected to slot [5798] located at 20.0.0.128:6379 "oo" 20.0.0.23:6379> exit [[email protected] 6379]# redis-cli -c -h 20.0.0.4 -p 6379 20.0.0.4:6379> keys * 1) "name" 20.0.0.4:6379> get name -> Redirected to slot [5798] located at 20.0.0.128:6379 "oo" 20.0.0.4:6379> exit [[email protected] 6379]# redis-cli -c -h 20.0.0.5 -p 6379 20.0.0.5:6379> keys * 1) "name" 20.0.0.5:6379> get name -> Redirected to slot [5798] located at 20.0.0.128:6379 "oo" 20.0.0.5:6379> exit
——————————-生命周期设置——————————-
20.0.0.128:6379> EXPIRE name 20 ##20秒生命周期 20.0.0.128:6379>keys * 查看 20秒后消失了 内存中也会消除 20.0.0.23:6379>keys* 复制集中也会消失
本文转自互联网,侵权联系删除理论+实验——Redis集群
最新评论