1 redis简单的配置文件
[[email protected] 7007]cat redis.conf daemonize yes pidfile /var/run/redis7007.pid port 7007 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile "/tmp/redis7007.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump7007.rdb dir /data/redis/7007/ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-ping-slave-period 10 repl-timeout 60 repl-disable-tcp-nodelay no slave-priority 100 #requirepass fangyali maxmemory 50000000 maxmemory-policy volatile-lru appendonly yes appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
新建dir目录/data/redis/7007/ 计划端口为7000-7005
把配置文件分别copy到相应目录,注意修改端口
启动redis
redis-server /data/redis/7000/redis.conf redis-server /data/redis/7001/redis.conf redis-server /data/redis/7002/redis.conf redis-server /data/redis/7003/redis.conf redis-server /data/redis/7004/redis.conf redis-server /data/redis/7005/redis.conf
安装ruby
http://www.ruby-lang.org/en/downloads/ ./configure -prefix=/usr/local/ruby make make install
安装rubygem
https://rubygems.org/pages/download ruby setup.rb
安装gem-redis
https://rubygems.org/gems/redis/versions/3.2.2 gem install -l /data/soft/redis-3.2.2.gem cp /usr/local/redis-3.0.7/src/redis-trib.rb /usr/local/bin/
创建集群
[[email protected] soft]redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 192.168.56.159:7003 192.168.56.159:7004 192.168.56.159:7005 >>> Creating cluster [ERR] Sorry, can't connect to node 127.0.0.1:7000 配置了密码,取消掉OK
简单操作
新添加主节点 redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000 分配slot redis-trib.rb reshard 127.0.0.1:7006 给主节点新加从节点 redis-trib.rb add-node --slave --master-id 2e30017779471ea0c2609b5badf2733951fb9f46 127.0.0.1:7007 192.168.56.160:7006 查看节点信息 127.0.0.1:7004> CLUSTER NODES 68cc9ca44041627308b176841da689b56b599a42 192.168.56.160:7001 master - 0 1462783984818 2 connected 10923-16383 b0b592510b6140b994c0c4d5a7e0016e75478911 192.168.56.159:7005 slave 68cc9ca44041627308b176841da689b56b599a42 0 1462783984817 6 connected 8de4c186553cd6cba9ef72ec3549916ce1d5bcd8 192.168.56.159:7007 slave 2e30017779471ea0c2609b5badf2733951fb9f46 0 1462783983810 7 connected 80655f860c39d2f0f46f29a9d11a6dfac227431c 192.168.56.159:7003 master - 0 1462783985824 4 connected 5512-10922 2e30017779471ea0c2609b5badf2733951fb9f46 192.168.56.160:7006 master - 0 1462783984314 7 connected 0-48 5461-5511 72cf83dd2da22e7239075abd75fcc713492187e7 192.168.56.160:7002 slave 80655f860c39d2f0f46f29a9d11a6dfac227431c 0 1462783983811 4 connected 097c31f3d8c283e327a975889630fc79c7376352 192.168.56.159:7004 myself,slave 9995d337a11da3487a393c546d6547c5a3229d39 0 0 5 connected 9995d337a11da3487a393c546d6547c5a3229d39 192.168.56.160:7000 master - 0 1462783983811 1 connected 49-5460 kill 主节点7006后,7007提升为主节点 127.0.0.1:7004> CLUSTER NODES 68cc9ca44041627308b176841da689b56b599a42 192.168.56.160:7001 master - 0 1462784014543 2 connected 10923-16383 8de4c186553cd6cba9ef72ec3549916ce1d5bcd8 192.168.56.159:7007 master - 0 1462784016056 8 connected 0-48 5461-5511 097c31f3d8c283e327a975889630fc79c7376352 192.168.56.159:7004 myself,slave 9995d337a11da3487a393c546d6547c5a3229d39 0 0 5 connected b0b592510b6140b994c0c4d5a7e0016e75478911 192.168.56.159:7005 slave 68cc9ca44041627308b176841da689b56b599a42 0 1462784016056 6 connected 80655f860c39d2f0f46f29a9d11a6dfac227431c 192.168.56.159:7003 master - 0 1462784015046 4 connected 5512-10922 72cf83dd2da22e7239075abd75fcc713492187e7 192.168.56.160:7002 slave 80655f860c39d2f0f46f29a9d11a6dfac227431c 0 1462784015046 4 connected 2e30017779471ea0c2609b5badf2733951fb9f46 192.168.56.160:7006 master,fail - 1462784002036 1462784001935 7 disconnected 9995d337a11da3487a393c546d6547c5a3229d39 192.168.56.160:7000 master - 0 1462784015550 1 connected 49-5460 再次启动7006后,7006自动替换为7007 slave 127.0.0.1:7004> CLUSTER NODES 68cc9ca44041627308b176841da689b56b599a42 192.168.56.160:7001 master - 0 1462784108358 2 connected 10923-16383 8de4c186553cd6cba9ef72ec3549916ce1d5bcd8 192.168.56.159:7007 master - 0 1462784108860 8 connected 0-48 5461-5511 097c31f3d8c283e327a975889630fc79c7376352 192.168.56.159:7004 myself,slave 9995d337a11da3487a393c546d6547c5a3229d39 0 0 5 connected b0b592510b6140b994c0c4d5a7e0016e75478911 192.168.56.159:7005 slave 68cc9ca44041627308b176841da689b56b599a42 0 1462784107351 6 connected 80655f860c39d2f0f46f29a9d11a6dfac227431c 192.168.56.159:7003 master - 0 1462784108860 4 connected 5512-10922 72cf83dd2da22e7239075abd75fcc713492187e7 192.168.56.160:7002 slave 80655f860c39d2f0f46f29a9d11a6dfac227431c 0 1462784106850 4 connected 2e30017779471ea0c2609b5badf2733951fb9f46 192.168.56.160:7006 slave 8de4c186553cd6cba9ef72ec3549916ce1d5bcd8 0 1462784107352 8 connected 9995d337a11da3487a393c546d6547c5a3229d39 192.168.56.160:7000 master - 0 1462784107856 1 connected 49-5460
基本命令
集群 CLUSTER INFO 打印集群的信息 CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。 节点 CLUSTER MEET <ip> <port> 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。 CLUSTER FORGET <node_id> 从集群中移除 node_id 指定的节点。 CLUSTER REPLICATE <node_id> 将当前节点设置为 node_id 指定的节点的从节点。 CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面。 槽(slot) CLUSTER ADDSLOTS <slot> [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。 CLUSTER DELSLOTS <slot> [slot ...] 移除一个或多个槽对当前节点的指派。 CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。 CLUSTER SETSLOT <slot> NODE <node_id> 将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。 CLUSTER SETSLOT <slot> MIGRATING <node_id> 将本节点的槽 slot 迁移到 node_id 指定的节点中。 CLUSTER SETSLOT <slot> IMPORTING <node_id> 从 node_id 指定的节点中导入槽 slot 到本节点。 CLUSTER SETSLOT <slot> STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。 键 CLUSTER KEYSLOT <key> 计算键 key 应该被放置在哪个槽上。 CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的键值对数量。 CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 个 slot 槽中的键。
时间: 2024-10-26 10:21:32