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

What are the steps for building a cluster?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "what are the steps of building a cluster". In the daily operation, I believe that many people have doubts about what the steps of building a cluster are. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the steps for building a cluster?" Next, please follow the editor to study!

Download, install and start the cluster Redis (single instance)

Download the redis package, then unzip the file, and download the Redis in the / opt directory

Go to the extracted redis file directory (you can see the Makefile file at this point) and compile the redis source file

Execute the command as follows

$cd / opt$ wget http://download.redis.io/releases/redis-4.0.9.tar.gz$ tar zxvf redis-4.0.9.tar.gz$ cd redis-4.0.9$ make$ make install

Install the compiled redis source files into the / usr/local/redis directory. If there is no redis directory in the / local directory, the redis directory will be created automatically.

Then modify the $. / src/redis-server redis.conf file-> daemonize:no to daemonize:yes

Go to the / usr/local/redis/bin directory and start redis directly with. / redis-server (in this case, the front end starts redis)

Note that due to the protected mode of Redis, only 127.0.0.1 of this machine is bound and cannot be accessed from other machines. So we need to add native ip

192.168.xxx.xxx .

Start redis through. / redis-server redis.conf under the / bin directory (this is the background startup).

Planning of $cd / opt/redis-4.0.9 $. / src/redis-server .redis.conf cluster

According to the official recommendation, cluster deployment should have at least 3 master nodes, preferably with a mode of 3 masters, 3 slaves and 6 nodes.

Configuration file

We prepare 6 configuration files, port 7001 _ 7002 _ 7003 _ 7004 _ 7005 _ 7006

And create a configuration file for 6 nodes in the redis-cluster directory. They are:

Redis-7000.confredis-7001.confredis-7002.confredis-7003.confredis-7004.confredis-7005.conf

The port number on which redis starts, such as 7000jc7001, etc. Next, edit the contents of the file:

# Port port 700 in this cluster phase specifies a pid_filepidfile / var/run/redis_7000.pid# for each cluster node. Add native ipbind 127.0.0.1 149.28.37.14 after the bind instruction to find the Cluster configuration code segment, so that Redis supports cluster cluster-enabled yes#. Each cluster node has a configuration file that cannot be edited manually. Make sure that the configuration file of each cluster node cannot access the timeout of the cluster-config-file nodes-7000.conf# cluster node (in ms). After the timeout, the cluster will assume that the node failed. Finally, change the appendonly to yesappendonly yes startup redis node to start the node one by one.

Take a look at the following startup

First, let's create the configuration file directory for Redis, as follows:

$cd / opt$ mkdir redis-cluster

The configuration of one node is completed, and the other five nodes do the same. And start the Redis instances of 6 nodes:

$nohup / opt/redis-4.0.9/src/redis-server / opt/redis-cluster/redis-7000.conf & $nohup / opt/redis-4.0.9/src/redis-server / opt/redis-cluster/redis-7001.conf & $nohup / opt/redis-4.0.9/src/redis-server / opt/redis-cluster/redis-7002.conf & $nohup / opt/redis-4.0.9/src/redis-server / opt/redis-cluster/redis- 7003.conf & $nohup / opt/redis-4.0.9/src/redis-server / opt/redis-cluster/redis-7004.conf & $nohup / opt/redis-4.0.9/src/redis-server / opt/redis-cluster/redis-7005.conf &

Use these 6 nodes to create a cluster:

$/ opt/redis-4.0.9/src/redis-trib.rb create-- replicas 1 149.28.37.147 Vol 7000 149.28.37.147 VR 7001 149.28.37.147 V 7002 149.28.37.147 V 7003 149.28.37.147 V 7004 149.28.37.147 V 7005

Or

$redis-cli-- cluster create 127.0.0.1 cluster 7001 127.0.1 cluster-replicas 1

-- replicas 1 indicates that we want to create a slave node for each master node in the cluster.

When the command is executed, it displays:

> Creating cluster > Performing hash slots allocation on 6 nodes... > Using 3 masters: > 149.28.37.147 masters 7000 > > 149.28.37.147 nodes... 7001 > 149.28.37.147 nodes... 7002 color # the result of successful execution is as follows # We can see that 7001Magi 7002j7003 has become the master node # occupied slot [0-5460], [5461-10922] respectively [10923-16383] > > Performing hash slots allocation on 6 nodes...Master [0]-> Slots 0-5460Master [1]-> Slots 5461-10922Master [2]-> Slots 10923-16383 Mustang-> Adding replica 149.28.37.147 Slots 7004 to 149.28.37.147 5460Master 7000 > > Adding replica 149.28.37 To 149.28.37.147 to 7003 to 149.28.37.147 to 7002 > > Trying to optimize slaves allocation for anti-affinity > M: 65625091304b0fa2dd75a00f62b6aceac1701094 149.28.37.147 slots:5461 > > M: slots:0-5460 (5461 slots) master > M: 4da569bf8402e4f75ab6e0fe7076919c22e3f900 149.28.37.147 slots:5461 > M: b977680e24f23f8fec96876d9014803ca752e2e2 149.28.37.14714 > slots:10923-16383 (5461 slots) Slots) master > S: 7183e47a64bca23157140229352455d1a1407dc2 149.28.37.147 7183e47a64bca23157140229352455d1a1407dc2 7003 > > replicates b977680e24f23f8fec96876d9014803ca752e2e2 > S: b2f916a643fefef1d43dbd1ef5d22f72c0ee43d6 149.28.37.147 7183e47a64bca23157140229352455d1a1407dc2 7004 > > replicates 65625091304b0fa2dd75a00f62b6aceac1701094 > S: e362d9aae5fe3e9c343d266a5ab952272e0e37b0 149.28.37.147 7183e47a64bca23157140229352455d1a1407dc2 7005 > > replicates 4da569bf8402e4f75ab6e0fe7076919c22e3f900 > Can I set the above configuration? (type 'yes' to accept): > We enter yes Enter: > > Nodes configuration updated > Assign a different config epoch to each node > > Sending CLUSTER MEET messages to join the cluster > > Waiting for the cluster to join... > > Performing Cluster Check (using node 149.28.37.147) > > M: 65625091304b0fa2dd75a00f62b6aceac1701094 149.28.37.147) > slots:0-5460 (5461 slots) master > 1 additional replica (s) > > M: b977680e24f23f8fec96876d9014803ca752e2e2 149.28.37.147) 7002 > > slots:10923-16383 (5461 slots) master > 1 additional replica (s) > S: e362d9aae5fe3e9c343d266a5ab952272e0e37b0 149.28.37.147 Slots: (0 slots) slave > > replicates 4da569bf8402e4f75ab6e0fe7076919c22e3f900 > > S: b2f916a643fefef1d43dbd1ef5d22f72c0ee43d6 149.28.37.147 slots 7004 > > slots: (0 slots) slave > > replicates 65625091304b0fa2dd75a00f62b6aceac1701094 > M: 4da569bf8402e4f75ab6e0fe7076919c22e3f900 149.28.37.147 slots 7001 > slots:5461-10922 (5462 slots) master > > 1 additional replica (s) > S: 7183e47a64bca23157140229352455d1a1407dc2 149.28.37.147 slots 7003 > > slots: (0 slots) slave > > replicates b977680e24f23f8fec96876d9014803ca752e2e2 > [OK] All nodes agree about slots configuration. > > Check for open slots... > > Check slots coverage... > > [OK] All 16384 slots covered. > Cluster has been set up. We can use Spring-Boot to access the Redis cluster very easily. Data verification

Pay attention to the parameter-c in cluster mode, which indicates the cluster, otherwise the data cannot be accessed normally!

[root@localhost redis-5.0.5] # redis-cli-p 7100-c set K1 v1127.0.0.1 set 7001 > set K1 v1-> Redirected to slot [12706] located at 127.0.0.1:7003OK. You can see the characteristics of the cluster: save the data to the calculated slot. Here we also automatically jump to 7003127.0.0.1 get 7003 > get K1 "v1" We also go back to 7001 to get K1 to try [root@localhost redis-5.0.5] # redis-cli-p 7001-c127.0.0.1 redis-cli 7001 > get K1-> Redirected to slot [12706] located at 127.0.1 V1 7003 "v1" We can see the process of redirection 127.0.0.1 redis-cli 7003 > at this point, the study of "what are the steps for building a cluster" is over? I hope I can solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report