当前位置:网站首页>Setting up redis cluster cluster under Windows

Setting up redis cluster cluster under Windows

2022-07-05 04:27:00 Eleven elder sister

One 、 Download and install

  • You need to download the following three :Redis、Ruby Language environment 、Redis Of Ruby drive redis-3.2.2.gem

  • 1、Redis-x64-5.0.14.1.zip download , 6 platform redis The server , Build pseudo clusters , And run on different ports 6380-6385
     Insert picture description here

  • 2、Ruby download ,ruby Script to build the cluster , All the way next, Finally, uncheck ,finish, then cmd It outputs ruby -v Represents a successful installation
     Insert picture description here
     Insert picture description here
     Insert picture description here

  • 3、 install Redis Of Ruby drive rubygems download , It's a tool for Ruby Components are packaged Ruby Packing system ; Decompress after downloading , Then open the command window and switch to the decompression directory , Carry out orders ruby setup.rb
     Insert picture description here
     Insert picture description here

Two 、 build Redis colony

  • For the cluster to function properly, at least 3 Main node , Recommended configuration 3 Main node , rest 3 As the slave nodes of each master node ( It is also the mode recommended by the official website ), Simulate through different ports of the same computer

  • 1、 Create a new folder Redis-cluster, And download the above Redis-x64-5.0.14.1.zip unpack , And rename the folder to 6380
     Insert picture description here

  • 2、 open 6380 A file in a directory redis.windows.conf, Modify the port number inside port by 6380, The main changes are as follows ,

    1. port 6380 // Change to the same port number as the current folder name 
    2. appendonly yes // Specifies whether to log after each update operation ,Redis stay   By default, data is written to disk asynchronously , If you don't turn it on , It may lead to 4.  Cause data loss for a period of time . yes Express : storage ,aof, Save the write operation record to the log 
    3. cluster-enabled yes // Turn on cluster mode 
    4. cluster-config-file nodes-6380.conf  // Save node configuration , Automatically create , Auto update ( It is recommended to add port number when naming )
    5. cluster-node-timeout 15000 // Cluster timeout , If the node does not respond after this time, it is determined to be down 
    

     Insert picture description here

  • 3、 stay 6380 New file in directory start.bat, The contents are as follows , It is used to enter the folder named by each port to start the service

    title redis-6380
    redis-server.exe redis.windows.conf
    

     Insert picture description here

  • 4、 Copy 6380 Folder , And rename to 6381-6385, At the same time, modify the redis.windows.con And start.bat The port number in the file , take 6380 Replace with the corresponding 6381-6385
     Insert picture description here

  • 5、 Open any cmd Window execution gem install redis
     Insert picture description here

  • 6、 Build cluster scripts , from 6380 Copy and paste under the directory redis-cli.exe To Redis-cluster Under the table of contents , meanwhile 6380~6385 Under each directory start.bat Double click the file to run without closing !!!
     Insert picture description here
     Insert picture description here

  • 7、 Then in the present Redis-cluster Open in directory cmd window , Execute the following command , Now the cluster is built

    redis-cli --cluster create 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 --cluster-replicas 1
    

     Insert picture description here

3、 ... and 、 Cluster environment test

  • Reference documents
  • redis-cli -c -h 127.0.0.1 -p 6380
  • View cluster information :cluster info
  • View master-slave relationship :info replication, Cluster nodes are arranged from left to right from master to slave 6 individual redis node , So it can also be seen that 6380,6381,6382 Three are the master nodes ,6383,6384,6385 There are three slave nodes , The correspondence is : Lord 6380 from 6383
  • View the node assignments slot:cluster nodes
     Insert picture description here

Four 、 take redis-cluster Registered student windows service

  • Reference documents

  • Console launch redis server If the console is closed redis server Will be shut down together , Then we need to let redis Running in the background requires redis server register as windows service , And then again start

  • So we can solve the above problems in the following ways , To 6380-6385 Rename services respectively under the directory , And start the , Please ensure that at least three master node services have been started in the background , Otherwise, it will cause the connection redis-cluster, But it can't connect to the inside db0

    #  adopt service-name start-up redis service :
    redis-server --service-install redis.windows.conf --service-name redis6380 --loglevel verbose
    redis-server --service-start --service-name redis6380
    
    #  adopt service-name stop it redis service :
    redis-server --service-stop --service-name redis6380
    

     Insert picture description here
     Insert picture description here

  • If the service fails to start , Open as administrator cmd perform SC delete The service name , Then when the corresponding directory is rebuilt
     Insert picture description here

5、 ... and 、 open redis Visualization tools , The connection is successful as shown in the figure

  • Pictured , Test connection successful
     Insert picture description here
  • The default is 127.0.0.1 You can visit , Modified as follows .conf, You can modify bind Designated LAN ip visit , After modifying the configuration , You need to restart the service to take effect

 Insert picture description here

原网站

版权声明
本文为[Eleven elder sister]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050426027047.html