Linux installation Redis cluster

Source: Internet
Author: User
Tags redis version redis cluster install redis









Linux Install standalone Redis has already been mentioned in another article, the bottom of the cluster, the environment is Sina Cloud Server:



redis3.0 started supporting the cluster later.



Introduction: What does Redis do with clustering?



  Use a ruby script called Redis-trib.rb. REDIS-TRIB.RB is the official Redis- Managed redis Cluster tool, integrated in the redis source src directory (redis-xxx/src/). is based on the Redis-provided cluster command encapsulated into a simple, convenient, practical operation tool. redis-trib.rb is done by Redis authors in Ruby. So the Redis cluster needs to install the Ruby environment first.



First look where: go to the Redis source code directory, you can see the redis-trib.rb script






Body, one: Installing the Ruby Environment: (Prerequisites)



As already mentioned, the Redis cluster is a ruby script, so the ruby environment is needed to execute the script.



To install the Ruby environment:



  Yum Install Ruby



   Yum install RubyGems (The manager of the Ruby package, the package used to download Ruby)









Show nothing todo, stating that the server has Ruby installed.



Two: Install Ruby package Redis-3.3.0.gem



  REDIS-TRIB.RB's run requires a ruby package, just like our Java program needs the jar package.



  This package and the Redis version do not have to match, as long as the support on the line, I found an online and redis-3.2.9 version of the near 3.3.0 version. Switch to the Redistar directory, with the SECURECRT RZ command Redis-3.3.0.gem upload to the Redistar directory, the package installed to any line, just provide an environment only.



The SecureCRT RZ command is uploaded to the server, into the Redistar directory, and the RZ command is executed to upload the file.





Perform the gem install redis-3.0.0.gem command installation.



Installation Complete:






+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



Here are some introductory things:



Go to the SRC directory of Redis and use LL *.rb to find the redis-trib.rb file,



Executes the command./redis-trib help can view the commands and features provided by the toolkit





-rwxrwxr-x 1 root root 60852 May 17 15:39 redis-trib.rb
[[email protected] /redistar/redis-3.2.9/src]# ./redis-trib.rb help
Usage: redis-trib <command> <options> <arguments ...>

  create          host1:port1 ... hostN:portN
                  --replicas <arg>
  check           host:port
  info            host:port
  fix             host:port
                  --timeout <arg>
  reshard         host:port
                  --from <arg>
                  --to <arg>
                  --slots <arg>
                  --yes
                  --timeout <arg>
                  --pipeline <arg>
  rebalance       host:port
                  --weight <arg>
                  --auto-weights
                  --use-empty-masters
                  --timeout <arg>
                  --simulate
                  --pipeline <arg>
                  --threshold <arg>
  add-node        new_host:new_port existing_host:existing_port
                  --slave
                  --master-id <arg>
  del-node        host:port node_id
  set-timeout     host:port milliseconds
  call            host:port command arg arg .. arg
  import          host:port
                  --from <arg>
                  --copy
                  --replace
  help            (show this help)

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.


Below is an explanation from someone else's article:



You can see that REDIS-TRIB.RB has the following features:


  • 1. Create: Creating a Cluster
  • 2. Check: Checking the cluster
  • 3. Info : View cluster information
  • 4. fix : Fix the cluster
  • 5. Reshard : Online Migration Slots
  • 6. Rebalance : Balance the number of cluster node slots
  • 7. Add-node : Join the new node to the cluster
  • 8. del-node : Remove nodes from the cluster
  • 9. Set-timeout : Sets the time-out for heartbeat connections between cluster nodes
  • 10. Call: Execute commands on all nodes of the cluster
  • 11. Import: Importing external Redis data into the cluster
  • There are two main classes of REDIS-TRIB.RB:ClusterNodeandRedisTrib. TheClusterNodeinformation for each node is saved, andRedisTribit is the implementation of each REDIS-TRIB.RB function.
  • ++++++++++++++++++++++++++++++++++++++++

    Just focus on the ability to create clusters. Let's start with a brief introduction to the use of the Redis-trib.rb script, with Create as an example:



Create          host1:port1 hostn:portn --replicas <arg>





host1:port1 ... hostN:portNThis must be an optional parameter after the optional parameter, the representation of the sub-parameter must be filled in after--replicas <arg>a parameter, like--slavethis, without parameters, after mastering the basic rule, you can get the use of redis-trib.rb from the help command.






Example: Create a cluster



The Create command has an optional replicas parameter, andreplicas indicates that several slave are required.



The Create command for a slave cluster is as follows:



$ruby redis-trib.rb Create --replicas 1 10.180.157.199:6379 10.180.157.200:6379 10.180.157.201:6379 10.180.157.202:6379 10.180.157.205:63 10.180.157.208:6379



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



Three: Build our cluster:






Cluster has three nodes in the cluster, each node has a master one. Requires 6 virtual machines.






Build a pseudo-distributed cluster, using 6 Redis instances to simulate.



1, create the Redis-cluster directory under user/local:



mkdir Redis-cluster





When you create the REDIS01 directory






Enter Usr/local/redis, copy redis-cli,redis-server,redis.conf to/usr/local/ redis-cluster/redis01 Directory





View:






Description: When installing Redis stand-alone version, only made command, no make install, and then the REDIS-CLI, Redis-server, redis.conf three files copied to their own manually built/usr/local/ Redis directory,



If you use a Redis standalone version of [[email protected] redis-3.0.0]# make install Prefix=/usr/local/redis, there will be several other files in the/usr/local/redis directory, It is not clear what the difference is.



Step One: Create 6 Redis instances with port numbers from 7001~7006



The second step: Modify the Redis configuration file, back-end boot daenonize to Yes is the previous installation of a standalone version has been done.



1, modify the port number, enter the VIM edit mode, non-insert mode (INSERT press ESC to exit) input/port Enter to quickly locate








2. Open the comment in front of cluster-enable. : wq! Save edits






3, copy redis01 to the current directory, CP is copied,-R is a joint subdirectory copy, and named Redis02, Redis03, Redis04, Redis05, Redis06



Cp–r REDIS01/REDIS02





Modify the port number of REDIS02, Redis03, Redis04, Redis05, Redis06 to 7002, 7003, 7004, 7005, 7006



4: Copy the Ruby script that created the cluster into the Redis-cluster directory.



Go to Redis source redistar/redis-3.2.9/src to copy:



CP *.rb/usr/local/redis-cluster/* wildcard character, SRC directory only one. rb file is redis-trib.rb






View



:



Start 6 Redis instances, one to boot a little more complicated, create a script in the Redis-cluster directory to start 6 instances:



Cd/usr/local/redis-cluster



Vim startall.sh will open the Vim editor and create an empty text:






: wq! save script, create success:






Execute./startall.sh prompt Permission denied description insufficient permissions, execute command chmod 777 startall.sh Modify Permissions






Re-execute./startall.sh, ps-aux|grep redis View Redis operation, 6379 is the previous Redis did not stop



You can see that the Redis ports 7001, 7002, 7003, 7004, 7005, 7006 are all up.






5: Create the cluster.



Based on the description in the top split line: Execute the following command in the Redis-cluster directory:



./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 12 7.0.0.1:7006





 
[[email protected] /usr/local/redis-cluster]# ./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: b370efb2e0dd8dd09aeee2177099d68c5982a01c 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
M: 387d8975195982ed96a08cd0d14587bfa68659db 127.0.0.1:7002
   slots:5461-10922 (5462 slots) master
M: bc46045f41d337e4316230fb40bdfb8c1784d419 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master S: d99c5ba8d944a45d3393a5c84b014446ff16c1e0 127.0.0.1:7004
   replicates b370efb2e0dd8dd09aeee2177099d68c5982a01c
S: a3352a69d5f1b69bed39d4ffe636305dc808f891 127.0.0.1:7005
   replicates 387d8975195982ed96a08cd0d14587bfa68659db
S: ad04e4409aae4295d1198403330e967285396d05 127.0.0.1:7006
   replicates bc46045f41d337e4316230fb40bdfb8c1784d419 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: b370efb2e0dd8dd09aeee2177099d68c5982a01c 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: a3352a69d5f1b69bed39d4ffe636305dc808f891 127.0.0.1:7005
   slots: (0 slots) slave
   replicates 387d8975195982ed96a08cd0d14587bfa68659db
S: ad04e4409aae4295d1198403330e967285396d05 127.0.0.1:7006
   slots: (0 slots) slave
   replicates bc46045f41d337e4316230fb40bdfb8c1784d419
M: bc46045f41d337e4316230fb40bdfb8c1784d419 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: d99c5ba8d944a45d3393a5c84b014446ff16c1e0 127.0.0.1:7004
   slots: (0 slots) slave
   replicates b370efb2e0dd8dd09aeee2177099d68c5982a01c
M: 387d8975195982ed96a08cd0d14587bfa68659db 127.0.0.1:7002
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[[email protected] /usr/local/redis-cluster]#


The cluster is built.



Test cluster






[Email protected]/usr/local/redis-cluster]# redis01/redis-cli-h 192.168.25.153-p 7002–c



Description:-h+host–p+ port number –c is to connect the cluster, pay attention to the pit, do not add error





Can see the connection is 7001 of the node, set name when the calculation of the existence of which hash slot, will jump to that slot corresponding node.



Do not write the pit of-C:






----------------------write here first, tomorrow, 2017-05-25:23:20.






Linux installation Redis cluster


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.