Redis cluster creation

1. Use the redis command to create a cluster
In the Redis installation directory, there is a command create-cluster start to create a cluster, first enter the directory
cd /opt/redis-3.2.8/utils/create-cluster/
1. Execute ./create-cluster After start , create 6 nodes as follows:
Starting 30001
Starting 30002
Starting 30003
Starting 30004
Starting 30005
Starting 30006
2. After executing ./create-cluster create , type yes
Using 3 masters:
127.0.0.1:30001
127.0.0.1:30002
127.0.0.1 :30003
Adding replica 127.0.0.1:30004 to 127.0.0.1:30001
Adding replica 127.0.0.1:30005 to 127.0.0.1:30002
Adding replica 127.0.0.1:30006 to 127.0.0.1:30003
M: 914b965bb9f4f9058683149ab383c2b868845b51 127.0.0.1:30001
   slots:0-5460 (5461 slots) master
M: c17b39b369260fca37d9eb125196ac4f91381a03 127.0.0.1:30002
   slots:5461-10922 (5462 slots) master
M: ac9e5b70070fe6c020bb85cd11089871931a1937 127.0.0.1:30003
   slots:10923-16383 (5461 slots) master
S: 6100cfd7a6711ec78132e636d9ea4f2dd4561a2b 127.0.0.1:30004
   replicates 914b965bb9f4f9058683149ab383c2b868845b51
S: e8885db7349fb6f8b22d32895b6411d4dd95e21d 127.0.0.1:30005
   replicates c17b39b369260fca37d9eb125196ac4f91381a03
S: 4490a4492b09757b4b6cb0203b3439c73aaab8c0 127.0.0.1:30006
   replicates ac9e5b70070fe6c020bb85cd11089871931a1937
Can I set the above configuration? (type 'yes' to accept):
The following display indicates that the cluster was created successfully
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage.. .
[OK] All 16384 slots covered.
3. View cluster status
redis-cli -c -p 30001 cluster info

cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:1229
cluster_stats_messages_received:1229
4、查看集群节点信息
127.0.0.1:30001> cluster nodes

Master 127.0.0.1:30003 ac9e5b70070fe6c020bb85cd11089871931a1937 - 0. 3 1,494,133,176,091 Connected 10923-16383
c17b39b369260fca37d9eb125196ac4f91381a03 127.0.0.1:30002 Master - 2 0 1494133175688 Connected 5461-10922
6100cfd7a6711ec78132e636d9ea4f2dd4561a2b 127.0.0.1:30004 Connected Slave 914b965bb9f4f9058683149ab383c2b868845b51 0 1,494,133,176,091. 4
914b965bb9f4f9058683149ab383c2b868845b51 127.0.0.1:30001 myself, Master - 1 0 0 Connected 0-5460
e8885db7349fb6f8b22d32895b6411d4dd95e21d 127.0.0.1:30005 Slave c17b39b369260fca37d9eb125196ac4f91381a03 0 1494133176091 5
Connected 4490a4492b09757b4b6cb0203b3439c73aaab8c0 127.0.0.1:30006 Slave ac9e5b70070fe6c020bb85cd11089871931a1937 0 1494133176091 6 Connected
Second, manually specify the port, from the beginning of 6000, to create a 6 node
1, start 6000 nodes
redis-server --port 6000 --cluster-enabled yes --cluster-config-file nodes-6000.conf --cluster-node-timeout 2000 --cluster-slave-validity-factor 10 --cluster-migration-barrier 1 --cluster-require-full-coverage yes --dbfilename dump-6000.rdb --daemonize yes

Description of each parameter:
port: Node port number
cluster-enabled: Specifies that Redis runs in cluster mode
cluster-config-file: The path to the cluster configuration file, which saves the change information of the
cluster cluster-node-timeout: Node failure time, in milliseconds, If other master nodes cannot be accessed within the specified time, the task of the node will fail. If the node is the master, trigger the salve, if it is the slave, stop querying
cluster-slave-validity-factor: failover factor, if the value exceeds the value of cluster-node-timeout*cluster-slave-validity-factor, the slave node will not become the master node
cluster-migration-barrier: the minimum number of slave nodes, for example: A--A1, A2, B-B1, C-C1, if the value is set to 2, when C fails, C1 becomes the master, and A is still two slaves node, the master C1 will be 0 slave nodes, because the value is 2
cluster-require-full-coverage: yes, when a master node in the cluster fails, the entire cluster will be unavailable, set to no, hash to this The write operation of the node fails, but the read operation is normal
. dbfilename: redis saves the file for persistent data
daemonize: yes means running in background mode.
You can bind the ip through the bind parameter, such as --bind 192.168.174.128. You can bind the ip when building across physical machines.
2. Modify the port in the above script, start 6001, 6002 nodes
3. Add node hash mapping
redis-cli -c -p 6000 CLUSTER ADDSLOTS {0..5460}
redis-cli -c -p 6001 CLUSTER ADDSLOTS {5461..10922}
redis-cli -c -p 6002 CLUSTER ADDSLOTS {10923..16383}

4. Add a configuration epoch, set a number that describes the state of the cluster at a specific point in time, and use this value when a node fails over or reshards
redis-cli -c -p 6000 CLUSTER SET-CONFIG-EPOCH 1
redis-cli -c -p 6001 CLUSTER SET-CONFIG-EPOCH 2
redis-cli -c -p 6002 CLUSTER SET-CONFIG-EPOCH 3

5. Add mutual visits between nodes
redis-cli -c -p 6000 CLUSTER MEET 127.0.0.1 6001
redis-cli -c -p 6000 CLUSTER MEET 127.0.0.1 6002

CLUSTER MEET can be automatically propagated between nodes
6. View cluster information
redis-cli -c -p 6000 cluster info

cluster_state: ok
......
At this point, the configuration of the master node of the cluster is completed.
7. Add slave nodes.
Create 6003 nodes and add 6003 to the cluster.
redis-cli -c -p 6003 CLUSTER MEET 127.0.0.1 6000

Execute redis-cli -c -p 6000 cluster nodes to view the nodes
...
632a1c4ad59406434d312690045ea9a29eb43be4 127.0.0.1:6000 myself, master - 0 0 1 connected 0-5460
8. Set 6003 to the slave node of 6000
redis-cli -c -p 6003 CLUSTER REPLICATE 632a1c4ad59406434d312690045ea9a29eb43be4

View node information
39217187b8c9f9fea9792330cda5cbb5aa5f5c32 127.0.0.1:6003 slave 632a1c4ad59406434d312690045ea9a29eb43be4 0 1494145699026 1 connected ,found that 6003 becomes 6000 salve
empathy can be set to 6001,6005 6004 to 6002 from the node, as above
three , Redis provides a cluster Ruby Create script
1. Execute the redis-server command to create 6 nodes,
for port in 5000 5001 5002 5003 5004 5005 5006 5007; do
redis-server --port ${port} --cluster-enabled yes --cluster-config-file
nodes-${port}.conf --cluster-node-timeout 2000 --cluster-slave-validityfactor
10 --cluster-migration-barrier 1 --cluster-require-full-coverage
yes --dbfilename dump-${port}.rdb --daemonize yes
done

2. Create a cluster
./src/redis-trib.rb create --replicas 1 127.0.0.1:5000 127.0.0.1:5001
127.0.0.1:5002 127.0.0.1:5003 127.0.0.1:5004 127.0.0.1:5005

Ruby scripts are easier and more convenient to operate, eliminating intermediate steps

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326278629&siteId=291194637