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

How to install Redis clusters offline

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to install Redis cluster offline, which has certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article. Let's take a look at it.

First, install Redis cluster through native commands (used only to understand the principle of Redis cluster)

1. Configure the Redis node required to enable it

Because this is only a simple demonstration of the principle of Redis clustering, assume that the Redis service has been installed and create six redis.conf configuration files under the config folder, namely redis-7000.conf, redis-7001.conf, redis-7002.conf, redis-7003.conf, redis-7004.conf, and redis-7005.conf. Its contents are as follows:

Port ${port} daemonize yesdir "/ opt/redis/redis/data/" dbfilename "dump-$ {port} .rdb" logfile "${port} .log" cluster-enabled yes / / enable node clustering function cluster-config-file nodes-$ {port} .confcluster-require-full-coverage nocluster-node-timeout 15000

Start six redis backend services in turn

Redis-server redis-7000.conf

Redis-server redis-7001.conf

Redis-server redis-7002.conf

Redis-server redis-7003.conf

Redis-server redis-7004.conf

Redis-server redis-7005.conf

Ps-ef | check the startup status by grep redis:

two。 The communication between nodes is completed through the cluster command meet.

Meet:cluster meet ip port

Redis-cli-h 127.0.0.1-p 7000 cluster meet 127.0.0.1 7001

Redis-cli-h 127.0.0.1-p 7000 cluster meet 127.0.0.1 7002

Redis-cli-h 127.0.0.1-p 7000 cluster meet 127.0.0.1 7003

Redis-cli-h 127.0.0.1-p 7000 cluster meet 127.0.0.1 7004

Redis-cli-h 127.0.0.1-p 7000 cluster meet 127.0.0.1 7005

Through the node with port 7000, other nodes can also sense the existence of each other, and then communicate with each other.

Verification: after the login port number is 7000 node, enter the cluster nodes and cluster info commands, respectively.

3. Assignment slot

After the communication between the nodes is completed, virtual slots need to be assigned to each master node. There are 16384 slot,redis nodes that know which slot is on which node. If the data accesses the redis,redis that does not belong to its own slot, it will tell which redis the data should access.

Command to assign slots: cluster addslots slot [slot...]

Redis-cli-h 127.0.0.1-p 7000 cluster addslots {0.5641}

Redis-cli-h 127.0.0.1-p 7001 cluster addslots {5642.. 10922}

Redis-cli-h 127.0.0.1-p 7002 cluster addslots {10923.. 16383}

Found here that the use of addslots can only be one input, feel very ridiculous, the use of array redis will report an error, with the online solution is to change the three points in curly braces to two points, I tried not, if there is any good solution can provide it.

4. Configure the master-slave relationship of a node

Cluster replicate node-id

Redis-cli-h 127.0.0.1-p 7003 cluster replicate ${node-id-7000}

Redis-cli-h 127.0.0.1-p 7004 cluster replicate ${node-id-7001}

Redis-cli-h 127.0.0.1-p 7005 cluster replicate ${node-id-7002}

At this point, the installation of the Redis cluster is completed through the native command, and there is a problem in the intermediate steps, which can not allocate slots, but it can help you to simply understand what needs to be done from the single node of Redis to the cluster of Redis.

Second, install the Redis cluster offline through Ruby

1. Installation environment and installation package instructions

System: Centos7 (gcc was selected for installation) installation package: redis-4.0.6.tar.gz / / redis installation package ruby-2.5.6.tar.gz / / Cluster build requires the ruby plug-in needed by the Ruby environment rubygems-3.0.6.zip / / redis cluster. Rubygems is a package management tool for ruby. Install redis-3.2.2.gem zlib-1.2.11.tar.gz / / possibly missing base environment zlib openssl-1.0.2t.tar.gz / / possibly missing base environment openssl through rubygems

two。 Installation steps

(1) decompress and compile redis

Mkdir / usr/local/redis / / create the redis working directory cp redis-4.0.6.tar.gz / usr/local/redis / / copy the installation package of redis to the redis directory cd / usr/local/redis / / go in the redis file tar-vxf redis-4.0.6.tar.gz / / extract ln-s redis-4.0.6 redis / / establish a soft connection cd redis / / enter make & & make install / / compile and install redis under the redis directory

(2) create a cluster directory

Cd / usr/local/redismkdir redis_cluster / / create a redis_cluster directory under the redis installation directory mkdir redis700 {0Magne1Magne2Jing 3jin4 5} / / batch create six redis node working directories with three masters and three slaves.

(3) configure redis.conf

Cd / usr/local/redis/redis_cluster / / enter the cluster working directory

Vim redis.conf / / create the redis.conf file and add the following

Port 7000 / / configure cluster port bind native IP / / the default configuration here is 127.0.0.1 changed to private network ip. Daemonize yes / / allows redis to run pidfile / var/run/redis-7000.pid / / in the background to be consistent with the port cluster-enabled yes / / enable the cluster to remove comments from the cluster-config-file node-7000.conf / / cluster configuration, and the port is the same as the cluster-node-timeout 15000 / / request timeout. The appendonly yes / / aof log is enabled by default for 15 seconds, and a log is recorded for each write operation.

Copy the redis.conf to a file of six nodes

Cp redis.conf redis7000/ copy the configuration file to the working directory of the redis7000 node

Cp redis.conf redis7001/

Cp redis.conf redis7002/

Cp redis.conf redis7003/

Cp redis.conf redis7004/

Cp redis.conf redis7005/

Because the configuration file is written according to the configuration of the 7000 port template, all the configuration files in the working directory need to change the port number in the file content to the port number of the corresponding working directory except redis.conf in the redis7000 directory.

(4) start the service

Cd / usr/local/redis/redis_cluster

Start all nodes in turn

Redis-server redis7000/redis.conf

Redis-server redis7001/redis.conf

Redis-server redis7002/redis.conf

Redis-server redis7003/redis.conf

Redis-server redis7004/redis.conf

Redis-server redis7005/redis.conf

Check the startup status: ps-ef | grep redis

(5) install ruby

Mkdir / usr/local/ruby / / create the ruby working directory cp ruby-2.5.6.tar.gz / usr/local/ruby / / copy the installation package to this directory cd / usr/local/ruby / / enter the ruby working directory tar-vxf ruby-2.5.6.tar.gz / / extract cd ruby-2.5.6/./configuremake & & make install

Check the installation: ruby-v

(6) install rubygems

Mkdir / usr/local/rubygems / / create the rubygems working directory cp rubygems-3.0.6.zip / usr/local/rubygems / / copy the installation package to this directory cd / usr/local/rubygems / / enter the ruby working directory unzip rubygems-3.0.6.zip / / extract cd rubygems-3.0.6/ruby setup.rb

The following error occurred while executing ruby setup.rb:

Solution: the zlib package is missing and zlib needs to be installed.

(7) install zlib

Mkdir / usr/local/zlib / / create the zlib working directory cp zlib-1.2.11.tar.gz / usr/local/zlib / / copy the installation package to this directory cd / usr/local/zlib / / enter the zlib working directory tar-vxf zlib-1.2.11.tar.gz / / extract cd zlib-1.2.11/./configure-- prefix=/usr/local/zlib

Makemake install

(8) compile zlib in ruby

Cd / usr/local/ruby/ruby-2.5.6/ext/zlib/ruby extconf.rb

The following error message appears:

It is found that it is necessary to install the files into the local runtime, and additional configuration information is required for all installations. Re-execute the command:

Ruby extconf.rb-- with-zlib-include=/usr/local/zlib/include/-- with-zlib-lib=/usr/local/zlib/lib / / generates a Makefile file

Move on to the next step: make & & make install

The error message appears again:

At this time, open the ext/zlib/Makefile file and find the following line to modify the path.

Change zlib.o: $(top_srcdir) / include/ruby.h to: zlib.o:.. /.. / include/ruby.h

As shown below:

Modify, then save, and then re -: make & & make install

Zlib's errors are resolved before you continue to reinstall rubygems.

Cd / usr/local/rubygems/rubygems-3.0.6ruby setup.rb

This time, the installation is successful, as shown below:

(9) install redis-3.0.0.gem

Cp redis-3.0.0.gem / usr/local/redis/rediscd / usr/local/redis/redisgem install redis-3.3.0.gem

The following error message appears:

Because OpenSSL is required for Redis cluster interaction, we also need to install OpenSSL.

(10) install openssl

Mkdir / usr/local/openssl / / create the openssl working directory cp openssl-1.0.2t.tar.gz / usr/local/openssl / / copy the installation package to this directory cd / usr/local/openssl / / enter the openssl working directory tar-vxf openssl-1.0.2t.tar.gz / / extract cd openssl-1.0.2t/./config-fPIC-- prefix=/usr/local/openssl enable-shared./config-tmake & & make install

Installation succeeded:

(11) compile openssl in ruby

Cd / usr/local/ruby/ruby-2.5.6/ext/openssl/ruby extconf.rb-- with-openssl-include=/usr/local/openssl/include/-- with-openssl-lib=/usr/local/openssl/lib will generate a Makefile file at this time. The following errors need to be modified: make & & make install

The following error message appears:

Solution: vim Makefile changes all the $(top_srcdir) in the Makefile file to.. /. Pay attention to replace all

When the replacement is complete, re-proceed

Make & & make install

Installation succeeded:

After successful installation, proceed to step 9 to install redis-3.0.0.gem.

Cd / usr/local/redis/redis/gem install redis-3.0.0.gem

Installation succeeded:

It is not easy to install the ruby environment here. In fact, the main content of the redis cluster installation is the installation and configuration process of the Ruby environment above.

(12) start the redis cluster

Cd / usr/local/redis/redis/src/

Execute the command in this directory:

. / redis-trib.rb create-- replicas 1 192.168.182.132 7000 192.168.182.132 7001 192.168.182.132 7002 192.168.182.132 7003 192.168.182.132 purl 7004 192.168.182.132 7005

Enter yes

Installation succeeded:

(13) verify the status of the cluster

Node redis-cli-p 7002-h 192.168.182.132 connected to port 7002 in a normal way

Parameter description:-p port port-h host host-c cluster cluster

Enter ping after connecting to the cluster. If you respond to pong, the connection to the cluster is successful.

CLUSTER INFO lists the current node information, and CLUSTER NODES lists the node information in the current cluster.

Execute command: set hello word

The 7002 node reported an error, and the client should use a client with port 7000 to add the data (because it did not add-c when logging in)

The client that logs in to port 7000 re-set hello world and adds data successfully (the last time adding hello world in 7002 was not successful, so there is no content to get hello in 7000)

Use cluster mode to connect to cluster redis-cli-p 7003-h 192.168.182.132-c (7003 is the standby for 7000)

Query hello:

Get hello

Reset the value of hello:

Set hello java

Set up successfully:

By comparison, it is found that if you log in without adding-c (non-cluster login, login is a single node), when adding data, if the virtual slot of the data key is not on the redis, it cannot be added successfully, that is, single-node login will not redirect the redis operation.

(14) verify the master-slave configuration of the cluster

Shut down the node at port 7002

Pid of kill-9 7002redis node

Nodes logged in to port 7000:

Redis-cli-p 7000-h 192.168.182.132-ccluster nodes

The string before CLUSTER NODES is the id of the node. From this command, you can also know which nodes are still alive and which are dead. The ones with fail are all dead nodes.

Cluster information shows that 7002 nodes have lost down, and 7005 has replaced 7002 as the primary node.

Thank you for reading this article carefully. I hope the article "how to install Redis clusters offline" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Database

Wechat

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

12
Report