当前位置:网站首页>Building a cluster: and replacing with error

Building a cluster: and replacing with error

2022-06-12 08:47:00 Wu Yu

cluster Cluster building :

Environmental preparation : Three hosts are needed . Port Division :

192.168.181.4   port : 7001, 7002

192.168.181.5 port : 7003, 7004

192.168.181,6 port : 7005, 7006

1. Modify the configuration file of the host , I'm going to modify 7001,7002 For example : Execute the command one by one

# cp /root/redis-6.2.3/redis.conf /root/redis-6.2.3/redis_7001.conf

# cp /root/redis-6.2.3/redis.conf /root/redis-6.2.3/redis_7002.conf

# mkdir -p /var/log/redis/cluster

# mkdir -p /root/redis-6.2.3/cluster/{redis_7001,redis_7002}

  1. modify Redis_700conf Configuration file for : The contents are as follows :
  2. # vim redis_7001.conf
    bind 192.168.181.4
    port 7001
    daemonize yes
    pidfile "/var/run/redis_7001.pid" // Default road strength 
    logfile "/var/log/redis/cluster/redis_7001.log" // The path of the created log file 
    dir "/root/redis-6.2.3/cluster/redis_7001" // Created cluster File path .
    masterauth “123456”
    requirepass “123456”
    appendonly yes
    cluster-enabled yes
    cluster-config-file nodes_7001.conf
    cluster-node-timeout 15000
    
    
    # vim redis_7002.conf
    bind 192.168.181.4
    port 7002
    daemonize yes
    pidfile "/var/run/redis_7002.pid" // Default road strength 
    logfile "/var/log/redis/cluster/redis_7002.log" //
    dir /root/redis-6.2.3/cluster/redis_7002"
    masterauth "123456"
    requirepass "123456"
    appendonly yes
    cluster-enabled yes
    cluster-config-file nodes_7002.conf
    cluster-node-timeout 15000
    
    

Other host configurations are the same , But you need to pay special attention to the path , Because on every host Redis Directories may be located in different locations .

And then start the... Of each host in turn Redis: stay Redis Use the following command under the directory : ./src/redis-server redis_7001.conf ,

Then trace the log file : tail -f /var/log/redis/cluster/redis_7001.log

There may be warnings , Because the default allocation of device space is too small , It needs to be expanded : Execute the following command :

echo > 1024 /proc/sys/net/core/ somaxconn

Each node on each host has no problem after startup , Next, create a cluster .

Set up the cluster :

Create a cluster on any node : The order is as follows :

./src/redis-cli -a 123456 --cluster create  192.168.181.4:7001 192.168.181.4:7002 192.168.181.5:7003  192.168.181.5:7004 192.168.181.6:7005 192.168.181.6:7006 --cluster-replicas 1

There may be mistakes here :

replace with error

The reason for the mistake : Previously configured Redis password , May have had an impact ,

You can use the following command : solve :

First of all to enter :Redis The client of ./src/redis-cli -h ip -p 7002 

And then use : config set  requirepass 123456( password )  

then :auth 123456

 

The configuration is complete . The above problems have occurred in the process of each node , So on each node , All the above commands are executed once ,

Then rebuild the cluster :

Input yes after , You can see the master-slave relationship table between nodes . It will also automatically generate nodes.conf file .

At this point, setting up the cluster is preliminarily completed , Later, you can try to enter data on the face for testing , You can also test adding and deleting nodes .

Login cluster :

# redis-cli -c -h ip  -p 7001 -a 123456                  # -c, Log in as a cluster

CLUSTER INFO # View the cluster status

CLUSTER NODES # List node information

CLUSTER MEET IP   Node number  # Add node

CLUSTER FORGET   Node number # Delete node

CLUSTER SAVECONFIG  # Save the node configuration information to the hard disk

redis cluster Clusters are decentralized , Every node is equal , You can get and set data by connecting any node .

Of course , Equality means master node , because slave Nodes don't provide services at all , Just as a counterpart master A backup of the node .

原网站

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