Redis6.0 Simple and Clear Cluster Redis-cluster Tutorial

Here, three servers are deployed as an example. The IP addresses are 192.168.124.23 , 192.168.124.24, and 192.168.124.25. Log in with the common user ubuntu
. There are a total of three master nodes and three slave nodes. Each server allocates a different slot, one master and one slave

  1. Download the Redis6.0 Stable version installation package from the official website https://redis.io/download to (the file location can be customized)
    /usr/local/redis-6.0.x.tar.gz

  2. Unzip the installation packagetar -zxvf redis-6.0.x.tar.gz

  3. Enter the redis folder ( cd /usr/localredis-6.0.x) and compile make(if the make command is wrong, please try to upgrade the gcc version)

  4. Verify that the compilation result is successful make test(if an error is reported in CentOS, please execute yum install tcland try again)

  5. Create a folder for storing the cluster (you can customize the folder location and name, here is /usr/local/redis-clusteran example)

    mkdir /usr/local/redis-cluster
    cd /usr/local/redis-cluster

  6. Copy two copies of redis to each /usr/local/redis-clusterserver and rename them to redis7000~7005 respectively. Command example: (If the user is not root, you need to use the chowncommand to modify the folder owner)

    #Copy command example:
    cp -r redis-6.0.x /usr/local/redis-cluster/redis7000

    #This is just to verify whether you have successfully operated here and change the permissions

    #Check the file directory to confirm whether it has been successfully copied in
    [email protected]: /usr/local/redis-cluster$ ls
    redis7000 redis7001 #The
    ubuntu here is changed to your username
    [email protected]: /usr/local/ redis-cluster$ sudo chown -R ubuntu:root /usr/local/redis-cluster
    #------------------------------ -------------------
    [email protected]:/usr/local/redis-cluster$ ls
    redis7002 redis7003
    [email protected]:/usr/local/redis- cluster$ sudo chown -R ubuntu:root /usr/local/redis-cluster
    #-------------------------------- -----------------
    [email protected]:/usr/local/redis-cluster$ ls
    redis7004 redis7005
    [email protected]:/usr/local/redis-cluster$ sudo chown -R ubuntu:root /usr/local/redis-cluster

  7. Take redis7000 as an example to modify the configuration file. Redis7001~7005 need to do the same operation (different nodes use their own port numbers instead of 7000)

    cd /usr/local/redis-cluster/redis7000 #Copy
    a configuration file and use this new file to start the Redis cluster in the future
    cp redis.conf redis7000.conf #Modify
    the configuration file (you can use "'/' after entering the vim editor" key to quickly locate the configuration item location)
    vi redis7000.conf

Next, edit this configuration file and modify the following configuration items

#############
port 7000 #设置启动端口
cluster-enabled yes #允许集群启动
cluster-config-file nodes7000.conf #集群配置文件名
cluster-node-timeout 5000 #集群节点之间多少毫秒无法连接后判定节点挂掉
pidfile /usr/local/redis-cluster/redis7000/redis7000.pid #修改pid文件创建位置
logfile /usr/local/redis-cluster/redis7000/redis7000.log #修改日志文件存储位置
dir /usr/local/redis-cluster/redis7000/data/ #修改数据文件存储位置
#############
  1. Start the nodes on each of the three servers

    [email protected]:/usr/local/redis-cluster$ ./redis7000/src/redis-server redis7000/redis7000.conf
    [email protected]:/usr/local/redis-cluster$ ./redis7001/src/redis-server redis7001/redis7001.conf
    #----------------------------------------------------
    [email protected]:/usr/local/redis-cluster$ ./redis7002/src/redis-server redis7002/redis7002.conf
    [email protected]:/usr/local/redis-cluster$ ./redis7003/src/redis-server redis7003/redis7003.conf
    #----------------------------------------------------
    [email protected]:/usr/local/redis-cluster$ ./redis7004/src/redis-server redis7004/redis7004.conf
    [email protected]:/usr/local/redis-cluster$ ./redis7005/src/redis-server redis7005/redis7005.conf

  2. Use any node to create a cluster, here use redis7000 node to create (note that once created, used permanently, restarting the cluster in the future starts directly from the ninth step)

    cd /usr/local/redis-cluster

    redis7000/src/redis-cli --cluster create 192.168.124.23:7000 192.168.124.23:7001 192.168.124.24:7002 192.168.124.24:7003 192.168.124.25:7004 192.168.124.25:7005 --cluster-replicas 1

After executing this command, 16384 slots will be evenly allocated to three groups of nodes, enter Y to confirm

  1. Select a server to open the client, here select port 7000 of 192.168.124.23, after entering the client, you can use the cluster infocommand to check whether the cluster is successfully started. It can be used after success .
[email protected]:/usr/local/redis-cluster$ ./redis7000/src/redis-cli -c -h 192.168.124.23 -p 7000
  1. End command: (execute on any server, here select 192.168.124.23 in the Redis7000 directory) It is recommended to save the command in a shell script file for easy operation
redis7000/src/redis-cli -c -h 192.168.124.23 -p 7000 shutdown
redis7000/src/redis-cli -c -h 192.168.124.23 -p 7001 shutdown
redis7000/src/redis-cli -c -h 192.168.124.24 -p 7002 shutdown
redis7000/src/redis-cli -c -h 192.168.124.24 -p 7003 shutdown
redis7000/src/redis-cli -c -h 192.168.124.25 -p 7004 shutdown
redis7000/src/redis-cli -c -h 192.168.124.25 -p 7005 shutdown

If you have any questions, welcome to comment~
If your problem is successfully solved, give a like and go acridine~

Guess you like

Origin blog.csdn.net/segegefe/article/details/124340412