redis cluster configuration

redis cluster configuration

①, check whether gcc is installed

gcc -v

Install gcc without it

yum install gcc

 

②Press the redis file and install it

Unzip the tar -zxvf redis-xxx.tar.gz

go to cd redis-3.0.6

Type make to install

Put redis-cli, redis-sentinel, redis-server into /usr/local/bin

In this way, redis can be started in any directory

 

③Create a new redis_cluster directory

Create 7001, 7002, 7003, 7004, 7005, 7006 folders in the redis_cluster directory

cp redis.conf /redis_cluster/redis7001.conf

vim redis7001.conf

Modify as follows:

daemonize yes #Start in the background

port 700x #Modify the port number, from 7001 to 7006

cluster-enabled yes #Open cluster, remove the comment

cluster-config-file nodes.conf

cluster-node-timeout 15000

appendonly yes

dir /redis-3.0.6/redis_cluster/700x #Modify the directory, from 7001 to 7006

bind 127.0.0.1

 

④redis-server redis700x.conf to start the corresponding redis

ps -ef|grep redis If you can see the figure below, it means the previous configuration was successful

[root@localhost src]# ps -ef|grep redis
root      2304     1  0 20:08 ?        00:00:01 redis-server 127.0.0.1:7002 [cluster]
root      2328     1  0 20:15 ?        00:00:01 redis-server 127.0.0.1:7001 [cluster]
root      2334     1  0 20:15 ?        00:00:01 redis-server 127.0.0.1:7003 [cluster]
root      2341     1  0 20:15 ?        00:00:01 redis-server 127.0.0.1:7004 [cluster]
root      2349     1  0 20:17 ?        00:00:01 redis-server 127.0.0.1:7006 [cluster]
root      2355     1  0 20:17 ?        00:00:00 redis-server 127.0.0.1:7005 [cluster]
root      4576  2272  0 20:47 pts/0    00:00:00 grep redis
 

⑤ Install the ruby ​​environment:

yum install ruby

yum install rubygems

Download redis-3.2.2.gem (you can download it in this blog)

Put it in the redis_cluster directory and execute the following command

gem install redis-3.2.2.gem

 

⑥Create a cluster using redis-trib.rb

  1. ./redis-trib.rb 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

  2. If you see the following, it means success

[root@localhost src]# ./redis-trib.rb 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
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7003
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
Adding replica 127.0.0.1:7006 to 127.0.0.1:7003
M: 0a0bfd616dd785ef341388979b2090ab43280c92 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
M: efd75010158f56f965f4f61b74a0cfff0109fa89 127.0.0.1:7002
   slots:5461-10922 (5462 slots) master
M: a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
S: df907bd1d011436651bb6b199b537d267e7e49f2 127.0.0.1:7004
   replicates 0a0bfd616dd785ef341388979b2090ab43280c92
S: 79dc86a9ed26fc14cff1b74ad2428b848d18e892 127.0.0.1:7005
   replicates efd75010158f56f965f4f61b74a0cfff0109fa89
S: 4aa14389b41103f446227fbe13155a0729231960 127.0.0.1:7006
   replicates a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f
Can I set the above configuration? (type 'yes' to accept): yes
>>> 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 127.0.0.1:7001)
M: 0a0bfd616dd785ef341388979b2090ab43280c92 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
M: efd75010158f56f965f4f61b74a0cfff0109fa89 127.0.0.1:7002
   slots:5461-10922 (5462 slots) master
M: a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
M: df907bd1d011436651bb6b199b537d267e7e49f2 127.0.0.1:7004
   slots: (0 slots) master
   replicates 0a0bfd616dd785ef341388979b2090ab43280c92
M: 79dc86a9ed26fc14cff1b74ad2428b848d18e892 127.0.0.1:7005
   slots: (0 slots) master
   replicates efd75010158f56f965f4f61b74a0cfff0109fa89
M: 4aa14389b41103f446227fbe13155a0729231960 127.0.0.1:7006
   slots: (0 slots) master
   replicates a0a7672fbb88a6dac2e05bffb2a5853bff8cf70f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
 

⑦Connect to the redis cluster client

  1. [root@localhost redis01]# ./redis-cli -c -p 7001

  2. 127.0.0.1:7001> set name andy

  3. -> Redirected to slot [5798] located at 127.0.0.1:7002

  4. OK

  5. 127.0.0.1:7002> get name

  6. "andy"

  7. 127.0.0.1:7002>

 

 

Reference https://www.cnblogs.com/yingchen/p/6763524.html

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326571558&siteId=291194637