Detailed description of Redis Cluster deployment and Construction

Source: Internet
Author: User
Tags redis cluster install redis

Detailed description of Redis Cluster deployment and Construction

I 've been on the road to Oracle for many years. It's also a good feeling to change my feeling and try new knowledge. Redis, an ultra-light memory database, is a very good product that only implements the functions of a small database. Today, we will share with you the process of installing the Redis cluster.

To build a redis cluster, we recommend that you have at least three servers, a total of six nodes, three master nodes, and three slave servers, and that three master nodes not all run to the same server, ensure node security. The configuration of the three servers is the same. Use the redistest account to set up the corresponding port 7000/7001/7002.

My cluster is allocated as follows, and each node runs two ports. The first column is the master database, and the second column is the slave database.

192.8.8.136: 7000 192.8.8.136: 7001
192.8.8.137: 7001 192.8.8.137: 7002
192.8.8.138: 7002 192.8.8.138: 7000

1. Run the compiled installation report (use the installation package connected at the end of the document), decompress the package, and put it in the/home/redistest directory to modify the corresponding redis. conf file, and copy 6 copies. Each node has two redis directories.
[Redistest] $ ll
Total 13284

Drwxr-xr-x 2 redistest users 4096 Aug 9 7000
Drwxr-xr-x 2 redistest users 4096 Aug 9 7001
Drwxr-xr-x 2 redistest users 4096 Aug 9 7002
-Rwxr-xr-x 1 redistest users 5708657 Aug 22 2016 redis-cli
-Rwxr-xr-x 1 redistest users 7817132 Aug 22 2016 redis-server
-Rwxr-xr-x 1 redistest users 60578 Aug 9 redis-trib.rb

2. There are 3 Execution files at this time, redis-server/redis-cli/redis-trib.rb

3. Create the 7000 folder and copy redis. conf to the 7000 file directory. Modify the corresponding key configuration items (change the port number)

Daemonize yes // redis running in the background
Pidfile/var/run/redis_7000.pid // pid file. When running multiple instances, you must specify different pid files.
Port 7000 // listening port. When running multiple instances, you must specify different weaning ports.
Tcp-Back log 511
Tcp-keepalive 0
Loglevel notice // Log Level
Logfile./redis. log // location of the log file
Databases 16 // number of available databases
Appendonly yes // redis will append each write operation request received to the appendonly. aof file. When redis restarts, it will restore the previous state from the file.
Appendfilename "appendonly. aof" // AOF file name
Appendfsync everysec // indicates that write operations are accumulated and synchronized once per second.
No-appendfsync-on-rewrite yes // AOF automatic Rewriting
Auto-aof-rewrite-percentage 80-100 // rewrite percentage
Auto-aof-rewrite-min-size 64 mb //

Note: For complete configuration, see the redis. conf file in the software package.
 
4. Copy the 7000 folder, paste the new 7001/7002 folder, and replace 7001/7002 in the redis. conf file in the 7000 folder with 7001/7002.

5. Switch to the root user, use yum to install ruby, yum-y install ruby rubygems, and execute gem install redis to complete ruby installation, you can use the redis-trib.rb to build a cluster
Note: The redis-trib.rb is developed based on ruby, so you must install the ruby environment.

Yum is easy to install, but some wind farms cannot connect to the Internet, so yum cannot be used. The software package contains ruby rubygems. Install it directly.

Ruby download path:
Https://rubygems.org/gems/redis

Run the following command to locally install ruby:

Yum-y localinstall ruby rubygems
Gem install redis

6. The other two servers perform the same configuration and enable the two redis nodes of the machine. After the redis nodes of the three servers are set up, you can start redis, use ps to view redis running status

7. Enable the redis Service
Go to the 7000 directory and start redis

Cd 1, 7000
.../Redis-server redis. conf
Cd ..
Cd 1, 7001
.../Redis-server redis. conf

[Redistest @ ip-172-18-98-136 redis] $ ps-ef | grep redis
Redistest 3864 1 0? 00:00:00 ../redis-server *: 7000 [cluster]
Redistest 3869 1 0? 00:00:00 ../redis-server *: 7001 [cluster]
Redistest 3888 3778 0 00:00:00 pts/3 grep redis

Note: Due to redis. conf files use relative paths and generate some files. For example, aof files cannot overwrite duplicates. Therefore, the standard operation to enable redis-server is, go to the 7000/7001/7002 directory and execute ,.. /redis-server redis. conf, so that the files generated by each instance are in their respective directories and do not interfere with each other; of course, if you modify redis. conf configuration file directory, You can execute redis-server in different directories, which can be flexibly mastered and used

8. After the redis node is set up, you need to build the redis cluster. During the cluster building process, you need to ensure that the six redis instances are running.
Redis determines the master and slave based on the order of IP and Port. Therefore, it is necessary to sort the order before executing.
Output:

[Redistest @ ip-172-18-98-136 redis] $./redis-trib.rb create -- replicas 1 192.8.136: 7000 192.8.8.8.8.8: 7001 192.8.8.138: 7002 192.8.8.8.8.8.136: 7002 192.8.8.138: 7001
>>> Creating cluster
>>> Specify Ming hash slots allocation on 6 nodes...
Using 3 masters:
192.8.8.138: 7002
192.8.8.133: 7001
192.8.8.136: 7000
Adding replica 192.8.8.137: 7002 to 192.8.8.138: 7002
Adding replica 192.8.8.138: 7000 to 192.8.8.8.137: 7001
Adding replica 192.8.8.136: 7001 to 192.8.8.136: 7000
M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.8.136: 7000
Slots: 10923-16383 (5461 slots) master
M: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.8.137: 7001
Slots: 5461-10922 (5462 slots) master
M: 6f9c383ec47461c2a86265f5db506e10da-605d8 192.8.8.138: 7002
Slots: 0-5460 (5461 slots) master
S: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137: 7002
Replicates 6f9c383ec47461c2a86265f5db506e10da-605d8
S: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.8.136: 7001
Replicates 6780f0fadd82825d04e524fd81fa710403e7152e
S: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.8.138: 7000
Replicates b00521fd8b0fae93d9e56fa6afe505ec9574c399
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 .....
>>> Specify Ming Cluster Check (using node 192.8.8.136: 7000)
M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.8.136: 7000
Slots: 10923-16383 (5461 slots) master
M: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.8.137: 7001
Slots: 5461-10922 (5462 slots) master
M: 6f9c383ec47461c2a86265f5db506e10da-605d8 192.8.8.138: 7002
Slots: 0-5460 (5461 slots) master
M: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137: 7002
Slots: (0 slots) master
Replicates 6f9c383ec47461c2a86265f5db506e10da-605d8
M: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.8.136: 7001
Slots: (0 slots) master
Replicates 6780f0fadd82825d04e524fd81fa710403e7152e
M: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.8.138: 7000
Slots: (0 slots) master
Replicates b00521fd8b0fae93d9e56fa6afe505ec9574c399
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

The Master node is: 192.8.8.136: 7000/192. 8.8.20.: 7001/192. 8.8.138: 7002 is distributed on different servers. Server Load balancer is implemented for the cluster, and the redis cluster construction process is basically completed;
 
9. Check the cluster status

[Redistest @ ip-172-18-98-136 redis] $./redis-trib.rb check 192.8.136: 7000
>>> Specify Ming Cluster Check (using node 192.8.8.136: 7000)
M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.8.136: 7000
Slots: 10923-16383 (5461 slots) master
1 additional replica (s)
M: 6f9c383ec47461c2a86265f5db506e10da-605d8 192.8.8.138: 7002
Slots: 0-5460 (5461 slots) master
1 additional replica (s)
S: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.8.136: 7001
Slots: (0 slots) slave
Replicates 6780f0fadd82825d04e524fd81fa710403e7152e
S: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137: 7002
Slots: (0 slots) slave
Replicates 6f9c383ec47461c2a86265f5db506e10da-605d8
M: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.8.137: 7001
Slots: 5461-10922 (5462 slots) master
1 additional replica (s)
S: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.8.138: 7000
Slots: (0 slots) slave
Replicates b00521fd8b0fae93d9e56fa6afe505ec9574c399
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[Redistest @ ip-172-18-98-136 redis] $./redis-trib.rb info 192.8.8.136: 7000
192.8.8.136: 7000 (6780f0fa...)-> 0 keys | 5461 slots | 1 slaves.
192.8.8.138: 7002 (6f9c383e...)-> 0 keys | 5461 slots | 1 slaves.
192.8.8.ys: 7001 (b00521fd...)-> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

10. Check cluster information

/Redis-trib.rb info 192.8.8.136: 7000

11. If it is not finished for a long time while executing./redis-trib.rb create -- replicas, or if it encounters another error. If you need to re-configure the cluster.
You need to close the redis instance, delete all files except the redis. conf file under the 7000/7001/7002 directory, then start the redis instance, and then execute the./redis-trib.rb create again.

12. Connect to the database and query data

[Root @ localhost src] # redis-cli-c-p 7000
127.0.0.1: 7000> cluster meet 127.0.0.1 7000
OK

Now, the redis cluster has been completed. Next we need to complete redis with the operating system starting, reducing the subsequent maintenance costs.

13. edit the file/home/redistest/startAll. sh. Be sure to write the full path.

/Home/redistest/redis-server/home/redistest/redis/7000/redis. conf
/Home/redistest/redis-server/home/redistest/redis/7001/redis. conf

Command line, add to the/etc/rc. local folder, you need to start redis with the redistest user

Su-redistest-c/home/redistest/startAll. sh

You can download the following information:

Click this link to follow the official website of the customer's home. After the link is followed, the number 151185 is returned. You can get the sharing password of a netizen.

If you cancel paying attention to the Public Account of the customer's house, you will not be able to provide this service even if you pay attention to it again!

Link: https://pan.baidu.com/s/1qZg2Hcg password: Get to see the above method, the address is invalid, please leave a message below.

------------------------------------------ Split line ------------------------------------------

For download all, see

FTP address: ftp://ftp1.bkjia.com

Username: ftp1.bkjia.com

Password: www.bkjia.com

Detailed description of deployment and construction of redis Cluster in LinuxIDC.com/ 2018/redis Cluster/

For the download method, see

------------------------------------------ Split line ------------------------------------------

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151185.htm

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.