Deploying clusters using Redis

Source: Internet
Author: User
Tags redis cluster install redis

We are now on a server, through 6 ports to simulate the Redis cluster deployment, to build the model is: three primary database 7001,7002,7003, each has one from the database 7004,7005,7006.

First create the directory/usr/local/redis-cluster, and then create 6 directory 7001-7006:

Then first copy the Redis configuration file redis.conf to 7001 directory, execute VI command Edit redis.conf, need to modify the place for:

Daemonize Yes (background run)
Port 700* (set for each machine's port number)
bind 192.168.202.131 (must bind the current host IP)
dir/usr/local/ redis-cluster/700*/(Specifies the location where the data file Dump.rdb must be specified, otherwise the data may be lost)
cluster-enabled Yes (start cluster mode)
Cluster-config-file Nodes700*.conf (700* preferably with port)
Cluster-node-timeout 5000 (expiration, optional)
appendonly Yes (start aof persistence, optional)

Copy the edited redis.conf to 7002-7006 directory, and then modify to the corresponding port number 7002-7006, in order to facilitate the use of full text replacement: After the implementation of the VI command, the colon into the last line mode, and then execute the%s/7001/700*/g.

Since the Redis cluster needs to use the ruby command, we need to install Ruby under Ruby,ubuntu First, as follows:

sudo apt-get update
sudo apt-get install ruby
sudo apt-get install RubyGems

Then execute the following command to install the Redis and Ruby interfaces:

Gem Install Redis

Then start 6 Redis instances separately: (My Redis-server program is installed in/usr/local/bin/, please correspond to your own)

/usr/local/bin/redis-server/usr/local/redis-cluster/7001/redis.conf 
/usr/local/bin/redis-server/usr/local/ redis-cluster/7002/redis.conf 
/usr/local/bin/redis-server/usr/local/redis-cluster/7003/redis.conf/ 
usr /local/bin/redis-server/usr/local/redis-cluster/7004/redis.conf 
/usr/local/bin/redis-server/usr/local/ Redis-cluster/7005/redis.conf 

After it is turned on, you can perform ps-el|grep Redis to see if it starts successfully.

Then execute Redis's src directory of the REDIS-TRIB.RB command, where create represents the creation of the cluster, –replicas represents the master-slave node ratio, 1 represents a master one from:

./usr/redis/redis-3.2.6/src/redis-trib.rb Create--replicas 1 192.168.202.131 7001 192.168.202.131 7002 192.168.202.131 7003 192.168.202.131 7004 192.168.202.131 7005 192.168.202.131 7006

Start the service in a clustered manner, and enter the info command to view the master and subordinate information:

Enter the cluster info command to view cluster information:

Cluster node information can be viewed through the cluster nodes command: (Redis allocates hash slots to the main library node).

Now open multiple terminals, respectively, to connect the Redis service of the 7001,7002,7003 port:

The set K1 v1 is then executed in 7001, and the K1 is stored in the 7003 hash slot 12706, where K1 is not visible in the 7001,7002, but can be accessed through get K1, and is redirected to the 7003-Port K1 service:

Now, we execute set K4 v4 in 7001, find K4 is stored to 7002, then we exit 7002 Service, start 7002 from the library that 7005, execute get K4, will find that still need to redirect to 7002 to obtain, this is unreasonable. We need to execute the readonly command from Library 7005, and then get the K4, we can get it from library 7005 directly: (But it's good to not have this set in Jedis)

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.