Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Manually build a redis cluster

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Prepare node-master node-redis-7000.confredis-7100.confredis-7200.conf-- slave node-redis-7001.confredis-7101.confredis-7201.conf

A Redis cluster is generally composed of multiple nodes, and the number of nodes is at least 6 to ensure a complete and highly available cluster.

2. Modify the configuration $vim redis-7000.confdaemonize yes # # enable daemon process port 7000 # node port logfile "/ soft/redis/cluster/7000/redis.log" # specify log input location cluster-enabled yes # enable cluster mode cluster-node-timeout 15000 # node timeout Unit millisecond cluster-config-file "nodes-7000.conf" # Cluster internal configuration file [if it is not available when starting for the first time, it will be created automatically]

The configuration of other nodes is consistent with the stand-alone mode. The naming rules of the configuration file: redis- {prot} .conf. Start all nodes when ready.

-- Master node-redis-server / soft/redis/cluster/redis-7000.conf & redis-server / soft/redis/cluster/redis-7100.conf & redis-server / soft/redis/cluster/redis-7200.conf &-redis-server / soft/redis/cluster/redis-7001.conf & redis-server / soft/redis/cluster/redis-7101.conf & redis-server / soft/redis/cluster/redis-7201.conf &

Check whether the current node log is correct, as follows:

$cat / cluster/redis-7000.log77893:M 16 Apr 00 Apr 38 cat * Increased maximum number of open files to 10032 (it was originally set to 1024). 77893 cat M 16 Apr 00 38 cat * 925 * No cluster configuration found 77893 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.77893 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.77893 The TCP backlog setting of 0038 Server started, Redis version 3.2.0.. 77893 Redis version 3.2.0. 77893Vista M 16 Apr 00VIE38 * The server is now ready to accept connections on port 7000

After the node is started for the first time, a cluster configuration file is generated, which contains:

-- by viewing the log-- $cat nodes-7000.conf 0c0bea9746cfe04dfcbb6ec1db35be5756dd7924: 0 myself,master-000 connectedvars currentEpoch 0 lastVoteEpoch 0

File memory records the initial state of the cluster, and the most important thing here is the node ID [this is a 40-bit hexadecimal string

The node ID is created only once [different from running ID], and the configuration file will be loaded for reuse when the node is restarted.

-- Echo through command interaction-- [root@test cluster] # redis-cli-p 7000127.0.0.1 cluster nodes0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 7000 > cluster nodes0c0bea9746cfe04dfcbb6ec1db35be5756dd7924: 7000 myself,master-000000 connected3, node handshake

Node handshake refers to the process that a group of nodes running in cluster mode communicate with each other through Gossip protocol in order to perceive each other. Node handshake is the first step in establishing cluster communication, and the client initiates the command: cluster meet {IP} {port}.

The steps are as follows:

1. Node 7000 sends a meet message to node 7001 2. After receiving the meet message, node 7001 saves the information of node 7000 and replies to pong message 3. After that, nodes 7000 and 7001 regularly communicate with each other through ping/pong messages -- send instructions for node handshake-- 127.0.0.1VR 7000 > cluster meet 127.0.0.1 7001127.0.0.1VR 7000 > cluster meet 127.0.0.1 7101127.0.0.1Ranger 7000 > CLUSTER MEET 127.0.1100127.0.1VL 7000 > CLUSTER MEET 127.0.0.1 72007.0.1VL 7000 > CLUSTER MEET 127.0.17300-check whether the handshake is normal or not. .0.0.1: 7000 > cluster nodesc0ffcbe12a16d2457786b542707dca0529bb1610 127.0.0.1 connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 7300 master-01492278433843 0 connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 127.0.0.1 master-01492278432333 0 connected34d2f50d036d7b95e5f3ae43571404c735b2e3ee 127.0.1connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 7100 master-01492278430825 3 connected367ec3a52e8faedc37f3d919865016f50f689893 127.0.0.1connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 7001 master-01492278432835 2 connected8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0 127.0.0.1 master 7101 master-01492278429818 4 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 127.0.1 myself Master-0 01 connected

At this point, the node handshake is established, but it does not work properly:

127.0.0.1 cluster_slots_ok:0cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:0cluster_current_epoch:5cluster_my_epoch:1cluster_stats_messages_sent:8725cluster_stats_messages_received:87254 7000 > CLUSTER infocluster_state:failcluster_slots_assigned:0 # # slots. A value of 0 indicates that no slots are currently assigned to the node. Distribution slot

The Redis cluster maps all the data to 16384 slots, and each key is mapped to a fixed slot. Only when the node assigns slots can it respond to the key commands associated with these slots.

Here, assign slots to the node through the cluster addslots command:

-bash feature batch setup slot (lots)-redis-cli-h 127.0.0.1-p 7000 cluster addslots {0.5461} redis-cli-h 127.0.0.1-p 7000 cluster addslots {5462... 10922} redis-cli-h 127.0.0.1-p 7000 cluster addslots {10923... 16383}-allocation slot through interactive command (lots)-- 127.0.0.1 7000 > cluster Addslots {0.5461} 127.0.0.1 addslots 7000 > cluster addslots {5462... 10922} 127.0.0.1 VR 7000 > cluster addslots {10923.. 16383}-View cluster status-127.0.0.1 VR 7000 > CLUSTER INFOcluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:1cluster_current_epoch:5cluster_my_epoch:1cluster_stats_messages _ sent:8725cluster_stats_messages_received:8725127.0.0.1:7000 > CLUSTER NODESc0ffcbe12a16d2457786b542707dca0529bb1610 127.0.0.1 master 7201 master-0 1492280674461 0 connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 127.0.0.1 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 7201 master-0 1492280674965 5 connected34d2f50d036d7b95e5f3ae43571404c735b2e3ee 127.0.0.1 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 7100 master-0 1492280673454 3 connected367ec3a52e8faedc37f3d919865016f50f689893 127.0.0.1za 7001 master-01492280675467 2 connected8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0 127.0.0.1Vol 7101 master-01492280672448 4 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 127.0.1anger 7000 myself Master-01 connected 0-16383

At present, there are still 3 nodes not in use as a complete cluster.

Each node responsible for the processing slot should have a slave node to ensure automatic failover when it fails.

In cluster mode, redis node roles are assigned to master node and slave node

The node started for the first time and the node assigned to the slot are the master node, and the slave node is responsible for the master node slot information and related data.

-$redis-cli-h 127.0.0.1-p 7000 cluster nodesc0ffcbe12a16d2457786b542707dca0529bb1610 127.0.0.1 connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 7201 master-0 1492288202486 0 connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 127.0.0.1 master 7200 master-0 1492288205502 connected34d2f50d036d7b95e5f3ae43571404c735b2e3ee 127.0.0.1master 7100 master-01492288204498 3 connected367ec3a52e8faedc37f3d919865016f50f689893 127.0.0.1 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 7001 master-0 1492288201480 2 connected8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0 127.0.0.1 master 7101 master-01492288203490 4 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 127.0.0.1 Master-001 connected 0-16383After-establish Master-Slave Node-127.0.0.1 CLUSTER REPLICATE 0c0bea9746cfe04dfcbb6ec1db35be5756dd7924127.0.0.1:7101 > CLUSTER REPLICATE 367ec3a52e8faedc37f3d919865016f50f689893127.0.0.1:7201 > CLUSTER REPLICATE 8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0While-View replication status information-127.0.0.1MAX 7101 > CLUSTER NODESc0ffcbe12a16d2457786b542707dca0529bb1610 127.0.1VOF 7101 myself Slave 8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0 000 connected34d2f50d036d7b95e5f3ae43571404c735b2e3ee 127.0.0.1 slave 8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0 7001 slave 0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 0 1492288883018 3 connectedb40c70eb1c32b4af2450e94deed01dec14ca26a0 127.0.0.1Visa 7201 slave 367ec3a52e8faedc37f3d919865016f50f689893 01492288884023 5 connected8c8b9679cd7c52d28fc58aa86d6b0e78efa249c0 127.0.0.1Vera 7100 master-01492288885033 4 connected367ec3a52e8faedc37f3d919865016f50f689893 127.0.0.1slave 0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 7200 master-01492288881005 2 connected0c0bea9746cfe04dfcbb6ec1db35be5756dd7924 127.0.1 master-01492288882012 1 connected0-16383 View current Node relationship 127.0.0.1Ranger 7000 > CLUSTER SLOTS1) 1) (integer) 02) (integer) 16383 3) 1) "127.0.0.1" 2) (integer) 7000 # master node 3) "0c0bea9746cfe04dfcbb6ec1db35be5756dd7924" 4) 1) "127.0.0.1" 2) (integer) 7001 # from the node 3) "34d2f50d036d7b95e5f3ae43571404c735b2e3ee" delete allocation slot 127.0.0.1 CLUSTER DELSLOTS 7000 > CLUSTER DELSLOTS 123 or: redis-cli-h 127.0.0.1-p 7000 cluster delslots {10923. 16383} Summary: 1. Manually create a cluster After restarting the redis service The cluster is disconnected, and the node handshake is also broken. 2. Creating a cluster is divided into three steps: 1, node handshake 2, allocation slot 3, master-slave node to establish replication relationship.

Related links:

Building redis Cluster with redis-trib.rb

Redis cluster [error summary]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report