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

The creation and use of redis Cluster

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Cluster configuration parameters:

cluster-enabled yes //Enable cluster

cluster-config-file nodes.conf //File that holds cluster information

cluster-node-timeout 5000 //Cluster node timeout

Cluster environment preparation:

Cluster management tool redis-trib is developed by ruby language, you need to install ruby dependencies and environment first;

redis source code file has a management tool, is written with ruby, so you need to install ruby-related software;

yum install ruby rubygems -y

gem install redis

Note: Please refer to this website--> http://gems.ruby-china.org/

$ gem update --system #here ××× please

$ gem -v

2.6.3

$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

$ gem sources -l

https://gems.ruby-china.org

#Make sure only gems.ruby-china.org

Note: If you encounter problems with SSL Certificates and you cannot solve them, please use http://gems.ruby-china.org to avoid SSL problems

$ gem sources --add http://gems.ruby-china.org/--remove https://rubygems.org/

Create clusters with redis-trib:

cp /usr/local/src/redis-3.2.0/src/redis-trib.rb /usr/local/bin/redis-trib

Note: redis-trib.rb is a cluster management tool written in ruby.

Note: If it is a binary installation and there is no redis-trib file, you need to download the source file and copy the redis-trib in the source file.

Create a cluster:

Note: Minimum of 3 nodes in cluster

redis-trib create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

Note: After creation, the first 3 are dominant, and the last 3 are subordinate.

How to enter the cluster and view cluster nodes:

Use the-c option to enter the cluster: >redis-cli -c -h ip -p port

cluster info: View information about this cluster

cluster nodes: View details of nodes in this cluster

How to add cluster nodes:

syntax: add-node new_host:new_port existing_host:existing_port

Example: redis-trib add-node 127.0.0.1:7007 127.0.0.1:7001

127.0.0.1: 7007 is a new node

127.0.0.1: 7001 is an existing node (any existing master node is fine)

After adding, it is master. When adding, there is no slot. You need to re-allocate slots to this node.

>cluster nodes

Assign slots to newly added nodes: by default, newly added nodes have no slots.

#redis-trib reshard 127.0.0.1:7007

How mang slots do you want to move(from 1 to 16384)?: 500

How many slots do you want to allocate to the new node

What is the receiving node ID?

What is the ID of the node receiving the slot? --> Write the ID of the new node here

Source node: From which nodes slots are allocated to new nodes

all: represents allocation from all nodes, i.e. some are allocated from each node

Slot allocation successful:

The allocation scheme is to allocate some of the other nodes to the newly added nodes.

Set the newly added node to a node's slave:

#redis-trib add-node 192.168.2.99:7008 192.168.2.99:7001

>cluster replicate 8c381457742731bbc4d2376069d89b308c3fa5e7

8c381457742731bbc4d2376069d89b308c3fa5e7: ID for master

Note: You need to log in to the newly added node (the node that needs to be set as slave) to set it as slave.

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