Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis Cluster cluster deployment build

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

After walking on the road of Oracle for many years, it is also a good feeling to change my feeling and try some new knowledge. Redis, an ultra-lightweight in-memory database, only does a small piece of database function, but it is a very excellent product. Today, let's share the process of installing a Redis cluster.

To build a redis cluster, it is recommended to prepare at least 3 servers, build a total of 6 nodes and 3 master,3 slave, and require that 3 master nodes cannot all run to the same server to ensure node security. The configuration of the three servers is the same, and the corresponding port is 7000 master 7001 and 7002.

My cluster is assigned as follows, with each node running two ports. The first column serves as the main library, and the second column serves as the backup library.

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

1. Use the compiled installation report to install (just use the installation package connected at the end of the document), extract and put it in the / home/redistest directory, modify the corresponding redis.conf file, and copy 6 copies, two redis directories for each node.

[redistest] $ll

Total 13284

Drwxr-xr-x 2 redistest users 4096 Aug 9 06:44 7000drwxr-xr-x 2 redistest users 4096 Aug 9 06:44 7001drwxr-xr-x 2 redistest users 4096 Aug 9 06:44 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 06:21 redis-trib.rb

2. There are three execution files, redis-server/redis-cli/redis-trib.rb.

3. Create a 7000 folder and copy the redis.conf to the 7000 file directory, and pay attention to modifying the corresponding key configuration items (mainly by changing the port number)

Daemonize yes / / redis background runs the pidfile / var/run/redis_7000.pid / / pid file. When running multiple instances, you need to specify different pid file port 7000 / / listening ports. When running multiple instances, You need to specify a different weaning tcp-backlog 511tcp-keepalive 0loglevel notice / / log level logfile. / redis.log / / log file location databases 16 / / number of available databases appendonly yes / / redis will append every write request received to the appendonly.aof file, and when redis restarts, it will restore the previous state from the file. Appendfilename "appendonly.aof" / / AOF file name appendfsync everysec / / indicates that the write operation is accumulated, and no-appendfsync-on-rewrite yes / / AOF automatically rewrites auto-aof-rewrite-percentage 80-100 / / per second. Percentage auto-aof-rewrite-min-size 64mb / /

Note: for complete configuration, please refer to the redis.conf file in the package

4. Copy the 7000 folder, paste out the new folder 7001max 7002, and replace 7000 of the redis.conf files in the 7001max 7002 folder with 7001max 7002.

5. Switch to the root user, install ruby,yum-y install ruby rubygems using yum, and execute gem install redis, so that the installation of ruby can be completed, and the cluster can be built using redis-trib.rb

Note: redis-trib.rb is based on ruby development, so the ruby environment must be installed.

Yum installation is very convenient, but some wind farms can not be connected to the external network, so it is impossible to use yum. The package already contains the package of ruby rubygems, so you can install it directly.

Download path for ruby: https://rubygems.org/gems/redis

Then install ruby locally with the following command

Yum-y localinstall ruby rubygemsgem install redis

6. The other two servers do the same configuration operation and turn on the two redis nodes of the machine. When the redis nodes of the three machines are built, you can start redis and use ps to check the operation of redis.

7. Enable redis service

Go to the 7000 directory and start redis

Cd 7000../redis-server redis.confcd.. cd 7001../redis-server redis.confi [redistest @ ip-172-18-98-136redis] $ps-ef | grep redisredistest 3864 10 13:02? 00:00:00.. / redis-server *: 7000 [cluster] redistest 3869 10 13:02? 00:00:00.. / redis-server *: 7001 [cluster] redistest 3888 3778 0 13:05 pts/3 00:00:00 grep redis

Note: since redis.conf files use relative paths, and some generated files, such as aof files, cannot be overwritten and duplicated, the standard operation to open redis-server is to go to a directory such as 7000max 7001max 7002 to execute,.. / redis-server redis.conf, so that the files generated by each instance are in their own directories and do not interfere with each other. Of course, if you modify the configuration file directory of redis.conf, 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 complete the construction of the redis cluster cluster. In the process of building the cluster, you need to ensure that all 6 redis instances are running.

Redis determines master and Port according to the order of master and Port, so sort them out before you execute them.

The output is as follows

[redistest@ip-172-18-98-136 redis] $. / redis-trib.rb create-- replicas 1 192.8.136redistest@ip-172 7000192.8.137redistest@ip-172 7001 192.8.8.138redistest@ip-172 7002192.8.137: 7002 192.8.8.136redis-trib.rb create 7001 192.8.1387001 192.8.1387001 192.8.1387001 > 192.8.1387000 > 192.8.1387000 > 192.8.1387000 > Performing hash slots allocation on 6 nodes...Using 3 masters:192.8.8.138:7002192.8.8.137:7001192.8.8. 136:7000Adding replica 192.8.137Vol 7002 to 192.8.8.138:7002Adding replica 192.8.8.138Vl7000M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.136Vl7001 slots:10923-16383 (5461 slots) masterM: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.137Vol 7001 slots:5461-10922 (5462 slots) masterM: 6f9c383ec47461c2a86265f5db506e10397605d8 192.8.138Rover 7002 slots : 0-5460 (5461 slots) masterS: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137 fc510e5cdcc78a42ef871251736d365db5311c7f 7002 replicates 6f9c383ec47461c2a86265f5db506e10397605d8S: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.8.136 fc510e5cdcc78a42ef871251736d365db5311c7f 7001 replicates 6780f0fadd82825d04e524fd81fa710403e7152eS: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.8.1387000 replicates b00521fd8b0fae93d9e56fa6afe505ec9574c399Can 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 clusterWaiting for the cluster to join. > > Performing Cluster Check (using node 192.8.136 slots 7000) M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.136 masterM 7000 slots:10923-16383 (5461 slots) masterM: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.8.137001 slots:5461-10922 (5462slots) masterM: 6f9c383ec47461c2a86265f5db506e10397605d8 192.8.8.138138Nodes configuration updated 7002 slots:0-5460 (5461) Slots) masterM: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137 slots 7002 slots: (0 slots) master replicates 6f9c383ec47461c2a86265f5db506e10397605d8M: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.136 fc510e5cdcc78a42ef871251736d365db5311c7f 7001 slots: (0 slots) master replicates 6780f0fadd82825d04e524fd81fa710403e7152eM: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.138 slots 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.

Among them, the node of Master is: 192.8.8.136vir 7000max 192.8.8.137vir 7001Compact 192.8.8.138vir 7002 distributed on different servers, and the load balance of the cluster is realized. So far, the process of building the redis cluster is basically completed.

9. Check the cluster status

[redistest@ip-172-18-98-136 redis] $. / redis-trib.rb check 192.8.136 slots:0 7000 > Performing Cluster Check (using node 192.8.136 slots:0 7000) M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.136 slots:0 7000 slots:10923-16383 (5461 slots) master 1 additional replica (s) M: 6f9c383ec47461c2a86265f5db506e10397605d8 192.8.13 slots:0 7002 slots:0-5460 (5461 slots) master 1 additional replica (s) S: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.136 slots:0 7001 Slots: (0 slots) slave replicates 6780f0fadd82825d04e524fd81fa710403e7152eS: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137 slave replicates 6780f0fadd82825d04e524fd81fa710403e7152eS 7002 slots: (0 slots) slave replicates 6f9c383ec47461c2a86265f5db506e10397605d8M: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.13.7001 slots:5461-10922 (5462 slots) master 1 additional replica (s) S: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.8.138 additional replica 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 . / redis-trib.rb info 192.8.136 redis 7000192.8.136 keys 7000 (6780f0fa...)-> 0 keys | 5461 slots | 1 slaves.192.8.8.138:7002 (6f9c383e...)-> 0 keys | 5461 slots | 1 slaves.192.8.8.137:7001 (b00521fd...)-> 0 keys | 5462 slots | 1 slaves. [OK] 0 keys in 3 masters.0.00 keys per slot on average.

10. Check the cluster information

. / redis-trib.rb info 192.8.8.136:7000

11. If you don't finish for a long time or encounter other errors during the execution of. / redis-trib.rb create-replicas. If you need to reconfigure the cluster.

You need to close the redis instance, delete all the files except the redis.conf file in the 7000Universe 7002 directory, start the redis instance, and execute. / redis-trib.rb create again.

12. Connect to the database and query data

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

Now that the redis cluster has been completed, we need to complete the redis as the operating system starts to reduce the cost of subsequent maintenance.

13. Edit the file / home/redistest/startAll.sh. Note that the full path should be written.

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

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

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

The package is too large to be uploaded in blog. It has been uploaded to the 51cto download center, please go to the download center to download.

Http://down.51cto.com/data/2334650

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report