Centos 6.5 redis cluster cluster setup

Source: Internet
Author: User
Tags hash redis centos port number redis cluster install redis
Centos 6.5 redis cluster cluster setup

Reference article: Redis learning Note (14) Redis cluster Introduction and construction Preface

There are two ways to create a Redis cluster in general:

1.

Use the Redis replication feature to replicate Redis and read and write separation for master and slave. Use Redis Sentinel to ensure high availability of redis clusters.

This approach has the following advantages: the ability to support lateral expansion, when the peak throughput is higher, can be increased by the expansion of the slave node, can support higher read QPS

However, there are the following disadvantages: Usually a master node, even if the read-write separation, up to tens of thousands of of the write QPS (simple data structure, more complex data may be lower) when read and write separation, Redis client (such as Jedis) Insufficient support for read and write separation in this regard. may need to expand and package, or modify the source to do horizontal expansion, you need to be careful not to take a star-like mechanism, need to take a tree structure (star-like structure will cause the master node to mount a lot of slave nodes, when doing data replication on the master node pressure) Need to maintain a sentinel cluster for high-availability purposes

2.

Redis Cluster has been released in version 3.0. Effectively solves the requirements of the Redis distributed aspect. Redis Cluster is a collection of Replication,sentinel features, while supporting multi-master horizontal scaling. Can be a good solution to the problem of traffic bottlenecks. Use Redis cluster to break through traffic bottlenecks.

In contrast, Redis cluster is a distributed solution. However, there are also the following functional limitations: Key bulk operation support is limited. Only keys with the same slot value are currently supported for bulk operations key transaction operation support is limited, transactional operations on the same node are supported, transactions with multiple nodes are not supported.

This article introduces some basic knowledge of Redis cluster and how to build a Redis cluster cluster. Data Distribution theory

The primary solution to a distributed database is to map data to multiple nodes in a certain rule, each node being responsible for a subset of the entire data. Common partitions have hash partitions and sequential partitions. Redis cluster takes a hash partition rule. Common hash partitions are available in the following ways: node redundancy partition consistency hash partition virtual slot partition

The Redis cluster uses virtual slot partitioning, where all keys are mapped to 0-16383 slots based on a hash function, with the formula: Slot = CRC16 (key) &16383. Each node is responsible for maintaining part of the slot and the key-value data mapped by the slot. Building Redis Cluster Environment CentOs 6.5 Redis 4.0.9 (2018/4/10 latest Version) node

Redis cluster clusters are typically composed of multiple nodes with more than 6 nodes in order to guarantee a highly available cluster.

The configuration of a node is listed here
Copy the Utils/redis_init_script under the Redis directory to redis_7000:

Modify the following content:

redisport=7000

Then copy the file to the/etc/init.d/directory.

Copy the redis.conf to/etc/redis/7000.conf in the Redis directory and modify the following:

Port 7000
cluster-enabled Yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
daemonize Yes
pidfile  /var/run/redis_7000.pid
dir      /var/reids/7000
logfile  /var/log/redis/7000. Log
bind 192.168.1.103//natively IP address
appendonly Yes

Then create the following folder:/var/redis/7000/var/log/redis/

Then go to the/etc/init.d/directory below to execute./redis_7000 start command launches a Redis instance. Check to see if the startup was successful by viewing/var/log/redis/7000.log.

Deploy 6 instances as per the method above. If 6 instances are on a machine that is not available, copy the configuration file directly in the past. If a machine runs 2 or more instances, you need to be careful about modifying the port number.

Join you for testing, all the nodes are running on the same machine, the configuration file can be changed to the following:

Port 7000
cluster-enabled Yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
Cluster-announce-ip 39.10X. Xx. XX//own server IP
cluster-announce-port 7000
cluster-announce-bus-port 17000
daemonize Yes
pidfile  /var/run/redis_7000.pid
dir      /var/reids/7000
logfile  /var/log/redis/7000.log
AppendOnly Yes

After running 6 Redis instances, you're ready to go. The Redis cluster is now running, but it's not working. Create a cluster

To create a cluster using ruby-related tools, you need to execute the following command to install Ruby:

Yum install-y Ruby
yum install-y rubygems
gem install Redis

When executing the gem install Redis it is time to burst the following error:

Gem Install Redis
Error:  error installing Redis:
        Redis requires Ruby version >= 2.2.2.

This is due to the fact that the system installs the Ruby version for CentOS 6.5 by default to 1.8.7 so you need to upgrade to 2.2.2.

Execute the following command:

GPG2--keyserver hkp://keys.gnupg.net--recv-keys d39dc0e3

curl-l get.rvm.io | bash-s stable

source/usr/local/ RVM/SCRIPTS/RVM

# View available ruby versions
RVM list known

# Install 2.3.4 version
RVM install 2.3.4

# Set default version
RVM Use 2.3.4

gem install Redis

This will allow you to install it successfully. After the installation is finished, copy the src/redis-trib.rb file from the Redis directory into the/usr/local/bin.

Then create the cluster using the following method:

REDIS-TRIB.RB Create--replicas 1 192.168.1.103:7000 \
192.168.1.103:7001 192.168.1.104:7002 192.168.1.104:7003 \< c1/>192.168.1.105:7004 192.168.1.105:7005

During execution, you will be asked if you can assign slots and enter Yes.

The parameter--replicas indicates that each master has a slave, and if there is nothing unexpected, the Redis cluster and the build is complete. You can check the status of the cluster with the following command:

REDIS-TRIB.RB Check 192.168.1.103:7001
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.