当前位置:网站首页>Local redis cluster setup

Local redis cluster setup

2022-06-09 05:26:00 Anonymous s

1. install redis service

1) Basic environment installation

yum install -y cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make tcl

yum -y install centos-release-scl centos-release-scl-rh

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

(centos7 default gcc Version less than 5.3 Can't compile )

sudo echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

soruce /etc/profile

2) download redis

wget http://download.redis.io/releases/redis-6.0.5.tar.gz

3) Unpack the installation

tar -zxvf redis-6.0.5.tar.gz
cd redis-6.0.5
make
make test
make install

The compiled file is copied to /usr/local/bin Under the table of contents

4) reproduce 6 Nodes

The default here is /usr/local/redis Create 6 A folder , The naming rule is node00(1-6)

[[email protected] redis]# ll
 Total usage  0
drwxr-xr-x. 2 root root 82 1 month   27 17:09 node001
drwxr-xr-x. 2 root root 82 1 month   27 17:06 node002
drwxr-xr-x. 2 root root 82 1 month   27 17:06 node003
drwxr-xr-x. 2 root root 82 1 month   27 17:06 node004
drwxr-xr-x. 2 root root 82 1 month   27 17:06 node005
drwxr-xr-x. 2 root root 82 1 month   27 17:09 node006

5) Copy redis Configure the file to each node , Modify configuration item

modify

port 6379                               -> port 4001   // From node port number 

protected-mode no                       -> protected-mode yes   // Turn off protection mode 

daemonize no                            -> daemonize yes   // The process runs in the background 

dir ./                                  -> dir  /usr/local/redis/node001/  // Profile location 
  
# masterauth <master-password>          -> masterauth   111111  // Master password   Set up your own  , If it is not set, the slave node cannot successfully go online after the master node goes offline .

# requirepass foobared                  -> requirepass 111111    //redis password 
  
appendonly no                           -> appendonly yes     // Persistence 

# cluster-enabled yes                   -> cluster-enabled yes   // Enable clustering 

# cluster-config-file nodes-6379.conf   -> cluster-config-file node001.conf // The configuration file name is defined by itself , It is better to correspond to the port 

6) Start all nodes

/usr/local/bin/redis-server  /usr/local/redis/node001/redis.conf
/usr/local/bin/redis-server  /usr/local/redis/node002/redis.conf
/usr/local/bin/redis-server  /usr/local/redis/node003/redis.conf
/usr/local/bin/redis-server  /usr/local/redis/node004/redis.conf
/usr/local/bin/redis-server  /usr/local/redis/node005/redis.conf
/usr/local/bin/redis-server  /usr/local/redis/node006/redis.conf
[[email protected] node001]# ps -aux|grep redis
root      9340  0.0  0.4 171632 13676 ?        Rsl  17:06   0:01 /usr/local/bin/redis-server 127.0.0.1:4001 [cluster]
root      9346  0.0  0.3 165488  9764 ?        Rsl  17:06   0:01 /usr/local/bin/redis-server 127.0.0.1:4002 [cluster]
root      9352  0.0  0.3 165488  9680 ?        Rsl  17:06   0:01 /usr/local/bin/redis-server 127.0.0.1:4003 [cluster]
root      9358  0.0  0.3 165488  9840 ?        Rsl  17:06   0:01 /usr/local/bin/redis-server 127.0.0.1:4004 [cluster]
root      9366  0.0  0.3 165488  9888 ?        Rsl  17:06   0:01 /usr/local/bin/redis-server 127.0.0.1:4005 [cluster]
root      9415  0.0  0.3 165488  9832 ?        Rsl  17:09   0:01 /usr/local/bin/redis-server 127.0.0.1:4006 [cluster]
root      9745  0.0  0.0 112828   984 pts/1    R+   17:38   0:00 grep --color=auto redis

7) Start cluster

/usr/local/bin/redis-cli  -p 4001  -a 111111  --cluster create 127.0.0.1:4001  127.0.0.1:4002 127.0.0.1:4003 127.0.0.1:4004 127.0.0.1:4005 127.0.0.1:4006 --cluster-replicas 1( Value is the number of slave nodes . Here is 3 Lord 3 from , So each node corresponds to 1 Slave nodes )

8) Check the status

127.0.0.1:4002> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:8
cluster_my_epoch:2
cluster_stats_messages_ping_sent:1994
cluster_stats_messages_pong_sent:1973
cluster_stats_messages_fail_sent:4
cluster_stats_messages_auth-ack_sent:2
cluster_stats_messages_sent:3973
cluster_stats_messages_ping_received:1973
cluster_stats_messages_pong_received:1993
cluster_stats_messages_fail_received:1
cluster_stats_messages_auth-req_received:2
cluster_stats_messages_received:3969



127.0.0.1:4002> cluster nodes
fa1bc24665c02d21eb492ecc8d4a06cbe770d206 127.0.0.1:[email protected] master - 0 1643276420195 8 connected 0-5460
8bcbe21d826117ac18cbea31c1b2239c924cb0f5 127.0.0.1:[email protected] myself,master - 0 1643276420000 2 connected 5461-10922
afce1168c68afd8b18cd5e0c076d8e38ae5e4b5a 127.0.0.1:[email protected] slave 8bcbe21d826117ac18cbea31c1b2239c924cb0f5 0 1643276418000 4 connected
fc05a1d4b1f03b513fcf5b07100460ac8dbb64ef 127.0.0.1:[email protected] slave b7975fcc2f9536db5c88f05c102de5b7d4468843 0 1643276419189 5 connected
b7975fcc2f9536db5c88f05c102de5b7d4468843 127.0.0.1:[email protected] master - 0 1643276421203 3 connected 10923-16383
29c0d34e0f730fc4f21d68d7928bb0289096e81f 127.0.0.1:[email protected] slave fa1bc24665c02d21eb492ecc8d4a06cbe770d206 0 1643276418183 8 connected


127.0.0.1:4002> cluster slots
1) 1) (integer) 0
   2) (integer) 5460
   3) 1) "127.0.0.1"
      2) (integer) 4001
      3) "fa1bc24665c02d21eb492ecc8d4a06cbe770d206"
   4) 1) "127.0.0.1"
      2) (integer) 4006
      3) "29c0d34e0f730fc4f21d68d7928bb0289096e81f"
2) 1) (integer) 5461
   2) (integer) 10922
   3) 1) "127.0.0.1"
      2) (integer) 4002
      3) "8bcbe21d826117ac18cbea31c1b2239c924cb0f5"
   4) 1) "127.0.0.1"
      2) (integer) 4004
      3) "afce1168c68afd8b18cd5e0c076d8e38ae5e4b5a"
3) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "127.0.0.1"
      2) (integer) 4003
      3) "b7975fcc2f9536db5c88f05c102de5b7d4468843"
   4) 1) "127.0.0.1"
      2) (integer) 4005
      3) "fc05a1d4b1f03b513fcf5b07100460ac8dbb64ef"

9) Test it  

kill Drop one of the primary nodes and see cluster info Medium  cluster_status Is it still ok, After restarting the slave node, check whether the slave node is rejoined .

原网站

版权声明
本文为[Anonymous s]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021428223753.html