1 Redis Simple configuration file
[[email protected] 7007]cat redis.conf daemonize yespidfile/var/run/redis7007.pidport 7007tcp-backlog 511timeout 0tcp-keepalive 0loglevel noticelogfile "/tmp/redis7007.log" Databases 16save, 1save, 10save, 10000stop- Writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump7007.rdbdir/data/redis/7007/ Slave-serve-stale-data yesslave-read-only Yesrepl-diskless-sync Norepl-diskless-sync-delay 5repl-ping-slave-period 10repl-timeout 60repl-disable-tcp-nodelay noslave-priority 100#requirepass fangyalimaxmemory 50000000maxmemory-policy volatile-lruappendonly yesappendfilename "appendonly.aof" Appendfsync Everysecno-appendfsync-on-rewrite Noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000cluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" Hash-max-ziplist-entries 512hash-max-ziplist-value 64lIst-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit Normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32MB 8MB 60hz 10aof-rewrite-incremental-fsync Yes
New Dir directory/data/redis/7007/Plan port is 7000-7005
Copy the configuration files to the appropriate directory, and note the modification of the port
Start Redis
Install Ruby
Http://www.ruby-lang.org/en/downloads/./configure-prefix=/usr/local/rubymakemake Install
Installing Rubygem
Https://rubygems.org/pages/downloadruby setup.rb
Installing Gem-redis
Https://rubygems.org/gems/redis/versions/3.2.2gem install-l/data/soft/redis-3.2.2.gem cp/usr/local/redis-3.0.7/ src/redis-trib.rb/usr/local/bin/
Create a cluster
[[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 configured the password, cancel out OK
Simple operation
New Add master node redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000 Assign slotredis-trib.rb Reshard 127.0.0.1:7006 to the master node redis-trib.rb add-node--slave--master-id 2e30017779471ea0c2609b5badf2733951fb9f46 127.0.0.1:7007 192.168.56.160:7006 View node information 127.0.0.1:7004> CLUSTER nodes68cc9ca44041627308b176841da689b56b599a42 192.168.56.160:7001 master-0 1462783984818 2 connected 10923-16383b0b592510b6140b994c0c4d5a7e0016e75478911 192.168.56.159:7005 slave 68cc9ca44041627308b176841da689b56b599a42 0 1462783984817 6 CONNECTED8DE4C186553CD6CBA9EF72EC3549916CE1D5BCD8 192.168.56.159:7007 Slave 2e30017779471ea0c2609b5badf2733951fb9f46 0 1462783983810 7 connected80655f860c39d2f0f46f29a9d11a6dfac227431c 192.168.56.159:7003 master-0 1462783985824 4 connected 5512-109222e30017779471ea0c2609b5badf2733951fb9f46 192.168.56.160:7006 master-0 1462783984314 7 connected 0-48 5461-551172cf83dd2da22e7239075abd75fcc713492187e7 192.168.56.160:7002 slave 80655f860c39d2f0f46f29a9d11a6dfac227431c 0 1462783983811 4 connected097c31f3d8c283e327a975889630fc79c7376352 192.168.56.159:7004 Myself,slave 9995d337a11da3487a393c546d6547c5a3229d39 0 0 5 connected9995d337a11da3487a393c546d6547c5a3229d39 192.168.56.160:7000 master-0 1462783983811 1 Connected 49-5460k After ill master node 7006, 7007 is promoted to the primary node 127.0.0.1:7004> CLUSTER nodes68cc9ca44041627308b176841da689b56b599a42 192.168.56.160:7001 master-0 1462784014543 2 connected 10923-163838DE4C186553CD6CBA9EF72EC3549916CE1D5BCD8 192.168.56.159:7007 master-0 1462784016056 8 connected 0-48 5461-5511097c31f3d8c283e327a975889630fc79c7376352 192.168.56.159:7004 myself,slave 9995d337a11da3487a393c546d6547c5a3229d39 0 0 5 connectedb0b592510b6140b994c0c4d5a7e0016e75478911 192.168.56.159:7005 Slave 68cc9ca44041627308b176841da689b56b599a42 0 1462784016056 6 connected80655f860c39d2f0f46f29a9d11a6dfac227431c 192.168.56.159:7003 master-0 1462784015046 4 connected 5512-1092272cf83dd2da22e7239075abd75fcc713492187e7 192.168.56.160:7002 slave 80655f860c39d2f0f46f29a9d11a6dfac227431c 0 1462784015046 4 connected2e30017779471ea0c2609b5badf2733951fb9f46 192.168.56.160:7006 master,fail-1462784002036 1462784001935 7 disconnected9995d337a11da3487a393c546d6547c5a3229d39 192.168.56.160:7000 master-0 1462784015550 1 Connected 49-5460 After starting 7006 again, 7006 is automatically replaced with 7007 slave127.0.0.1:7004> CLUSTER Nodes68cc9ca44041627308b176841da689b56b599a42 192.168.56.160:7001 master-0 1462784108358 2 connected 10923-163838DE4C186553CD6CBA9EF72EC3549916CE1D5BCD8 192.168.56.159:7007 master-0 1462784108860 8 Connected 0-48 5461-5511097c31f3d8c283e327a975889630fc79c7376352 192.168.56.159:7004 Myself,slave 9995d337a11da3487a393c546d6547c5a3229d39 0 0 5 connectedb0b592510b6140b994c0c4d5a7e0016e75478911 192.168.56.159:7005 slave 68cc9ca44041627308b176841da689b56b599a42 0 1462784107351 6 connected80655f860c39d2f0f46f29a9d11a6dfac227431c 192.168.56.159:7003 master-0 1462784108860 4 connected 5512-1092272cf83dd2da22e7239075abd75fcc713492187e7 192.168.56.160:7002 Slave 80655f860c39d2f0f46f29a9d11a6dfac227431c 0 1462784106850 4 connected2e30017779471ea0c2609b5badf2733951fb9f46 192.168.56.160:7006 slave 8DE4C186553CD6CBA9EF72EC3549916CE1D5BCD8 0 1462784107352 8 connected9995d337a11da3487a393c546d6547c5a3229d39 192.168.56.160:7000 master-0 1462784107856 1 Connected 49-5460
Basic commands
Information about the cluster CLUSTER info print cluster CLUSTER NODES lists all nodes currently known to the cluster, as well as information about those nodes. Node CLUSTER MEET <ip> <port> adds the node specified by IP and port to the cluster, making it part of the cluster. CLUSTER Forget <node_id> removes node_id specified node from the cluster. CLUSTER REPLICATE <node_id> Sets the current node to node_id node from the specified node. CLUSTER Saveconfig Save the configuration file of the node to the hard disk. Slot (slot) CLUSTER addslots <slot> [slots ...] assigns one or more slots (slots) (assign) to the current node. CLUSTER delslots <slot> [slots ...] removes the assignment of one or more slots to the current node. CLUSTER Flushslots removes all slots assigned to the current node, making the current node a node without any slots assigned. CLUSTER setslot <slot> Node <node_id> assigns the slot slot to the node specified by node_id, and if the slot is already assigned to another node, let the other node delete the slot before assigning it. CLUSTER setslot <slot> Migrating <node_id> migrates the slot slots of this node to the nodes specified in the node_id. CLUSTER setslot <slot> importing <node_id> import slot slots from node_id specified node to this node. CLUSTER Setslot <slot> STABLE cancels the import or migration (migrate) of the slot slots. Key CLUSTER keyslot <key> calculate the key should be placed on which slot. CLUSTER Countkeysinslot <slot> Returns the number of key-value pairs currently contained in the slot slot. CLUSTER GetkeysinslOT <slot> <count> returns the key in count slot slots.
REDIS Cluster Simple installation configuration