Linux under the Redis Cluster Building, node additions and deletions, Sentinel master-Slave switching __linux

Source: Internet
Author: User
Tags redis custom name redis cluster install redis

Redis more than 3.0 support clusters, because the cluster needs ruby support, you need to install the Ruby environment and download the Communication Management Pack

Ruby Environment Installation


Redis Command Reference: http://doc.redisfans.com/


After Ruby has been processed, the cluster is built

1, new cluster folder, and in the new 10010, 10020, 10030, 10040, 10050, 10060 folder

(main 10010, from 10020; main 10030, from 10040; main 10050, from 10060)


2, the Redis installation directory under the redis.conf file, CP to 10010 folder

Modify REDIS.CONF Configuration text

A, modify bind 127.0.0.1 IP for your server IP

B, the port is modified 10010

C, modify daemonize No to Yes; start daemon, generate PID file

D, modify Pidfile value, PID file storage path

E, modify the LogLevel value, log level, can be changed to debug

F, modify logfile value, log file storage path

G, modify AppendOnly value, start aof persistence. However, to build master and subordinate words, consider disabling the main Redis persistence, from the redis to persist on the line

H, start cluster-enabled yes; start cluster

I, starting cluster-conf-file nodes-10010.conf; storing hash slots

J, start cluster-node-timeout 15000; node Timeout time

After modifying and saving the file, then separate the redis.conf file, CP to 10020, 10030, 10040, 10050, 10060 folder, and make the corresponding modification



3. Start each node separately


After startup, connect the Redis client

Command: Redis-cli-c-H [IP]-P [port], connect cluster client, command Plus-C.


On the connection, view cluster status information

Command: Cluster info

Can see the state is fail, the number of hash slots is also 0;


4, through the Redis provided by the REDIS-TRIB.RB Cluster management tools for management (REDIS-TRIB.RB using Ruby write, so you need to install a ruby environment, and download the relevant Redis package).

In the Redis installation directory, enter the SRC directory, you can see REDIS-TRIB.RB


Execute command:./REDIS-TRIB.RB Create--replicas 1 [ip]:[port] [Ip]:[port] [Ip]:[port] [Ip]:[port] [Ip]:[port] [Ip]:[port]

--replicas 1, identifying settings from 1 nodes

[Ip]:[port], the front three are the primary node, the following three are from the node


In this step, if you install Ruby, you will be prompted with the following error

Rubygems/core_ext/kernel_require.rb:55:in ' require ': Cannot load such file--Redis (Loaderror)

Please install Redis cluster Communication related packs

Command: Gem install Redis


5, the above operation, through the cluster Manager to achieve the cluster management and master-slave implementation. Connecting cluster clients again to view cluster information

You can see the status OK and there are 16,384 hash slots. These 16,384 hash slots are evenly distributed to three primary nodes.

(The 10010 nodes in the figure are 0-5460 (5461 slots), 10030 nodes are 5461-10922 (5462 slots), 10040 nodes are 10923-16383 (5461 slots))



6, Redis through the key using the CRC16 algorithm to calculate a result, and then the result to 16384 for the remainder, corresponding to which node in the data will be deposited into which node



-----------------------------------------------------------------------------------------------------------

Cluster off, my method

1, kill-9 encounter Redis cluster related process

2, clean up the Redis cluster related folders under the Nodexxx.conf file

3, restart Redis and create Redis Cluster Management node

-----------------------------------------------------------------------------------------------------------


Dynamic increase of cluster nodes

1, add nodes, new 10070 folders, and the CP configuration file redis.conf to the directory, modify the configuration file to start

Command:./REDIS-TRIB.RB add-node [Ip]:[port] [Ip]:[port];redis installation directory under SRC directory execution

The front one [Ip]:[port] is the new service node that you just created, and the next one is the target service


2, view the cluster node information, connect the cluster client to execute the command

Command: Cluster nodes can see that 10070 has joined the cluster, but has not yet allocated a hash slot


3. Allocating hash Slots

Command:./redis-trib.rb reshard [under src directory under Ip]:[port];redis installation directory execution

After executing the command, you need to confirm the number of hash slots, confirm the ID of the target node once again, and confirm that the node is equally divided (#1: All) after confirmation. All confirmation complete Start node adjustment


4. View cluster node information again and execute command after connecting cluster client

Command: Cluster nodes can see that 10070 has joined the cluster and allocated a hash slot


-----------------------------------------------------------------------------------------------------------


Dynamic deletion of cluster nodes

1. Recycle hash Slot

Command:./redis-trib.rb reshard [under src directory under Ip]:[port];redis installation directory execution

After executing the command, you need to confirm the node ID that receives the hash slot, confirm the node ID that will be recycled hash slot again, confirm (#1:d one), and all confirmation completes start node adjustment


2, view the cluster node information, connect the cluster client to execute the command

Command: cluster nodes; You can see that the 10070-node hash slot has been assigned to 10010 nodes



3, delete the node

Command:./REDIS-TRIB.RB del-node [Ip]:[port] [Nodeid]; you need to delete the IP and port of the node, Nodeid is the ID of the node


4. View cluster node information again and execute command after connecting cluster client

Command: cluster nodes; You can see that 10070 nodes have been deleted.


Command: Cluster nodes, you can see that the hash slot for the 10070 node has been assigned to the 10010 node
------------------------------------------------------- ----------------------------------------------------

Sentinel high Availability, automatic master-slave switching
sentinel.conf under Redis installation directory

Modify the file configuration
1, except sentinel default port 26379 can not be modified, other not commented options are commented out

2, modify profile

Sentinel Monitor [custom need to monitor master node name [Primary node IP] [primary node port] [define how many Sentinel think Master node is dead before switching master]
Sentinel Down-after-milliseconds [consistent with custom name] [timeout, unit milliseconds]
SE Ntinel Failover-timeout [consistent with custom name] [timeout, per millisecond]
Sentinel Parallel-syncs [consistent with custom name] [number of slave for sync]
3, Start Sentinel, under the Redis installation directory under the SRC directory to execute command command:./redis-sentinel. /sentinel.conf

* You can test that when the 10010 node shutdown, 10020 becomes the primary node and inherits the 10010 hash slot. Starting 10010 again, you will find that 10010 becomes 10020 from the node. and sentinel.conf will automatically modify the

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.