redis There are three common architecture, a single case, Sentinel, clusters, others have said, here only briefly Cluster Setup.
Singleton easiest nothing to say.
Sentinel said before, there are sentinel node monitors the master and slave in this mode, if the master downtime can be automatically converted to the slave master, but it also has a problem that can not be dynamically expanded, and storage size is limited by memory size limit for each node .
Cluster mode Redis-Cluster, uses no central structure, each node and other nodes in the cluster have a connection, data can be distributed across the host storage solve the problem of limited storage size is limited by the host, Redis cluster pre-divided into many slots 16384 (slot), each node is assigned a portion of the slot, when a key-value to be placed in Redis cluster, based on a hash algorithm to decide which key into the slot, and then find the corresponding host data storage, query data is the same.
Within a cluster can also configure the master-slave mode, for example, six data node cluster, the master node may be provided three, each corresponding to a node from the master node, a master node when the down automatically from the node becomes a master node, ensure that the entire cluster can use. However, a master node and the corresponding node from the cluster down unavailable. Each master node may be configured from a plurality of nodes.
Cluster Setup steps
1, create several virtual machines (cluster model minimum of three master node) For example, we set up a three-master three clusters from to create six virtual machines, of course, you want to test, then you can also be deployed on the same host, different use port simulate different hosts.
2, installed on each host redis, note redis profile Note cluster-related configuration, such as modifying the value of cluster-enabled yes, an open cluster representation, other time-out or modify the configuration according to the actual default.
3, will not become after you install redis own cluster, also need to execute the command to create a cluster, this is not the same for each version, redis5 use redis-cli --cluster, redis3 use redis-trib.rb, specifically below.
redis5 cluster creation
redis5 of cluster-related commands, write here just created, of course, also supports add nodes, delete, etc. to operate solt
[root@fvb9wbpl-clustermanager-e0hhllme ~]# redis-cli --cluster help Cluster Manager Commands: create host1:port1 ... hostN:portN --cluster-replicas <arg> check host:port --cluster-search-multiple-owners info host:port fix host:port --cluster-search-multiple-owners reshard host:port --cluster-from <arg> --cluster-to <arg> --cluster-slots <arg> --cluster-yes --cluster-timeout <arg> --cluster-pipeline <arg> --cluster-replace rebalance host:port --cluster-weight <node1=w1...nodeN=wN> --cluster-use-empty-masters --cluster-timeout <arg> --cluster-simulate --cluster-pipeline <arg> --cluster-threshold <arg> --cluster-replace add-node new_host:new_port existing_host:existing_port --cluster-slave --cluster-master-id <arg> del-node host:port node_id call host:port command arg arg .. arg set-timeout host:port milliseconds import host:port --cluster-from <arg> --cluster-copy --cluster-replace help For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
Creating a cluster command from the master, followed by ip address and port cluster, cluster-replicas 1 represents a master node corresponds to a slave node is assigned automatically Once created from the relationship
cli---cluster the Create --cluster Redis-Replicas 1 10.110 . 30.136 : 6379 10.110 . 30.137 : 6379 10.110 . 30.138 : 6379 10.110 . 30.144 : 6379 10.110 . 30.145 : 6379 10.110 . 30.146 : 6379 prompted then enter yes, then start creating clusters
Once created view cluster, behind ip can be any node in the cluster, the master node M represents the results, when M nodes in a cluster node cluster will automatically become S M nodes, this can be self-testing
[root@fvb9wbpl-clustermanager-e0hhllme ~]# redis-cli --cluster check 10.110.30.68:6379 10.110.30.70:6379 (5e49929d...) -> 0 keys | 5461 slots | 1 slaves. 10.110.30.69:6379 (6dc594c5...) -> 0 keys | 5462 slots | 1 slaves. 10.110.30.112:6379 (2b9a0210...) -> 0 keys | 5461 slots | 1 slaves. [OK] 0 keys in 3 masters. 0.00 keys per slot on average. >>> Performing Cluster Check (using node 10.110.30.68:6379) S: 15a969da394187e239baab1cc57bc6ec810996fe 10.110.30.68:6379 slots: (0 slots) slave replicates 2b9a0210b3223a1d865324ec32cc70f8ebcbaf65 S: 095777fb0d8ad380e420b9ef465d202a745a14e6 10.110.30.114:6379 slots: (0 slots) slave replicates 6dc594c5180f655603504ab68591b2e7492c7963 S: 20a33128f5353d36cb084d6ae2bf24c5b4806538 10.110.30.113:6379 slots: (0 slots) slave replicates 5e49929d47e7bd438ea2e25c3731179f460eb387 M: 5e49929d47e7bd438ea2e25c3731179f460eb387 10.110.30.70:6379 slots:[0-5460] (5461 slots) master 1 additional replica(s) M: 6dc594c5180f655603504ab68591b2e7492c7963 10.110.30.69:6379 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 2b9a0210b3223a1d865324ec32cc70f8ebcbaf65 10.110.30.112:6379 slots:[10923-16383] (5461 slots) master 1 additional replica(s) [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
redis3 cluster creation
redis3 does not support cluster, 3 version to create a cluster using redis-trib.rb, of course, also need ruby etc. are not described here.
redis-trib.rb parameters with similar cluster, following the above understanding that could be easily understood, essentially the same
[root@mucuijwb-clustermanager-o9sprluh bin]# /usr/local/bin/redis-trib.rb help Usage: redis-trib <command> <options> <arguments ...> create host1:port1 ... hostN:portN --replicas <arg> check host:port info host:port fix host:port --timeout <arg> reshard host:port --from <arg> --to <arg> --slots <arg> --yes --timeout <arg> --pipeline <arg> rebalance host:port --weight <arg> --auto-weights --use-empty-masters --timeout <arg> --simulate --pipeline <arg> --threshold <arg> add-node new_host:new_port existing_host:existing_port --slave --master-id <arg> del-node host:port node_id set-timeout host:port milliseconds call host:port command arg arg .. arg import host:port --from <arg> --copy --replace help (show this help) For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
Create a master from the same cluster command, with the meaning of the parameters of the cluster
/usr/local/bin/redis-trib.rb create --replicas 1 10.110.30.74:6379 10.110.30.137:6379 10.110.30.138:6379 10.110.30.144:6379 10.110.30.145:6379 10.110.30.146:6379
Check the cluster
[root@mucuijwb-clustermanager-o9sprluh bin]# /usr/local/bin/redis-trib.rb check 10.110.30.74:6379 >>> Performing Cluster Check (using node 10.110.30.74:6379) M: 7483d09dadda2ecebd9fdbd6b1f186769e00904d 10.110.30.74:6379 slots:0-5460 (5461 slots) master 1 additional replica(s) M: 76ecc2cf2ddc07fe7f2fda53f2f5318198321761 10.110.30.72:6379 slots:5461-10922 (5462 slots) master 1 additional replica(s) M: 0f60c9c6595726d391805f5acfaf5be13496346a 10.110.30.73:6379 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: 6f56bbe811be2ff97ef654777ae48c3ae5d83824 10.110.30.111:6379 slots: (0 slots) slave replicates 76ecc2cf2ddc07fe7f2fda53f2f5318198321761 S: 8c3bb1ed5e531665dfedf126df5121b76dc604d4 10.110.30.110:6379 slots: (0 slots) slave replicates 7483d09dadda2ecebd9fdbd6b1f186769e00904d S: 543c3b42c93ccac1728eaa5d5c9a43938f922890 10.110.30.108:6379 slots: (0 slots) slave replicates 0f60c9c6595726d391805f5acfaf5be13496346a [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
Cluster connection
Client connection can be directly connected trunked mode redis node through intermediate nodes do not need to forward the client connects clusters need to add -c parameters, or error data will be inserted
[root@fvb9wbpl-rediscluster-vddntq84 ~]# redis-cli -c 127.0.0.1:6379> dbsize (integer) 0 127.0.0.1:6379>
Connect to other hosts
[root@fvb9wbpl-rediscluster-vddntq84 ~]# redis-cli -c -h 10.110.30.113 -p 6379 10.110.30.113:6379> dbsize (integer) 0 10.110.30.113:6379>
Inserting data and query data, note slot allocation operation of the slot, can be seen to be distributed storage
[root@fvb9wbpl-rediscluster-vddntq84 ~]# redis-cli -c -h 10.110.30.113 -p 6379 10.110.30.113:6379> set foo bar -> Redirected to slot [12182] located at 10.110.30.112:6379 OK10.110.30.112:6379> set c d -> Redirected to slot [7365] located at 10.110.30.69:6379 OK 10.110.30.69:6379> 10.110.30.69:6379> get foo -> Redirected to slot [12182] located at 10.110.30.112:6379 "bar" 10.110.30.112:6379> get c -> Redirected to slot [7365] located at 10.110.30.69:6379 "d" 10.110.30.69:6379>