Home > Database > Redis > body text

How to build a redis cluster

Release: 2019-07-08 09:15:49
Original
7058 people have browsed it

How to build a redis cluster

Redis cluster construction

Cluster construction: Redis cluster requires at least 3 nodes

Step one: Create a folder redis-cluster, Then create 6 folders below:

(1)mkdir -p /usr/local/redis-cluster

(2)mkdir 7001, mkdir 7002, mkdir 7003, mkdir 7004 , mkdir 7005, mkdir 7006

The second step: Copy the previous redis.conf configuration files to the 700* directory respectively, and modify the contents of each file. The command is as follows:

(1 )daemonize yes

(2)port 700*

(3)bind 192.168.2.2 Bind the ip of the current machine

(4)dir /usr/local/redis -cluster/700*/ Specify the data file storage location

(5)cluster-enabled yes (Start cluster mode)

(6)cluster-config-file nodes700*.conf

(7)cluster-node-timeout 5000

(8)appendonly yes

Step 3: Since the redis cluster requires the use of ruby ​​commands. So we need to install ruby, the command is as follows:

(1)yum install ruby

(2)yum install rubygems

(3)gem install redis (install redis and ruby interface)

This error may occur here: ERROR: Error installing redis: redis requires Ruby version >= 2.2.2

Here, you can refer to http://blog.csdn .net/fengye_yulu/article/details/77628094 to solve this problem.

Step 4: Start 6 redis instances respectively, and then check whether the startup is successful

(1)/usr/local/redis/bin/redis-server /usr/local/redis- cluster/700*/redis.conf

(2)ps -el | grep redis

How to build a redis cluster

Start all 6

Step 5: First go to the installation directory of redis3.0, and then execute the redis-trib.rb command.

(1) cd /usr/local/redis-3.0.0-rc2/src

(2)./redis-trib.rb create --replicas 1 139.196.123.218:7001 139.196.123.218:7002 139.196.123.218:7003 139.196.123.218:7004 139.196.123.218:7005 139.196.123.218:7006 (1 means the ratio of master to slave nodes, 1 means master:slave; 1: 1)

How to build a redis cluster

Step 6: The cluster is successfully established and verified:

(1) Connect to any client: ./redis-cli -c -h -p(- c means cluster mode, specify the ip address and port,)

For example: usr/local/redis/bin/redis-cli -c -h 192.168.1.1 -p 7001

(2) Verify: cluster info (view cluster messages), cluster nodes (view node list)

(3) Verify data operations

(4) To shut down the cluster, you need to shut down one by one, use the command :

usr/local/redis/bin/redis-cli -c -h 192.168.1.1 -p 700* shutdown

For more Redis related knowledge, please visit Redis usage tutorial Column!

The above is the detailed content of How to build a redis cluster. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!