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

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

Share

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

Redis cluster

Redis is an open source key-value storage system. Due to its excellent performance, most Internet companies use it as a server-side cache. Redis only supports single instance mode before version 3.0. although it supports master-slave mode and Sentinel mode deployment to solve a single point of failure, now Internet enterprises often have hundreds of gigabytes of data, but it is completely unable to meet the needs of the business. Therefore, Redis has launched the cluster mode after version 3.0.

GB

< TB < PB --- Redis 集群采用了P2P的模式,完全去中心化。Redis 把所有的 Key 分成了 16384 个 slot,每个 Redis 实例负责其中一部分 slot 。集群中的所有信息(节点、端口、slot等),都通过节点之间定期的数据交换而更新。 Redis 客户端可以在任意一个 Redis 实例发出请求,如果所需数据不在该实例中,通过重定向命令引导客户端访问所需的实例。 Redis 集群搭建规划,由于集群至少需要6个节点(3主3从模式), 计划是在一台机器上模拟一个集群, 这和生产环境的集群搭建没本质区别 (1)所有的redis节点彼此互联(PING-PONG机制),内部使用二进制协议优化传输速度和带宽.   (2)节点的fail是通过集群中超过半数的节点检测失效时才生效.   (3)客户端与redis节点直连,不需要中间proxy层.客户端不需要连接集群所有节点,连接集群中任何一个可用节点即可 创建多节点 cluster集群 HA高可用 先源码装一个redis 创建实例目录 mkdir /etc/redis-clustercd /etc/redis-clustermkdir -p 6379/data 6380/data 6381/data 6382/data 6383/data 6384/data

replication execution script

Mkdir / etc/redis-cluster/bincd / opt/redis-5.0.0/src/cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server redis-trib.rb / etc/redis-cluster/bin

replicates a new Redis instance

Cp / etc/redis/* / etc/redis-cluster/6379vi / etc/redis-cluster/6379/redis.conf port 6379 (port number of each node) daemonize yes bind 192.168.86.130 (bind current machine IP) dir "/ etc/redis-cluster/6379/data/" (data file storage location) pidfile / var/run/redis_6379.pid (pid 6379 and port to correspond) cluster-enabled yes (boot Cluster mode) cluster-config-file nodes6379.conf (6379 and port to correspond) cluster-node-timeout 15000 appendonly yes

The \ cp-rf command is copied without using an alias

Cp-rf / etc/redis-cluster/6379/* / etc/redis-cluster/6380cp-rf / etc/redis-cluster/6379/* / etc/redis-cluster/6381cp-rf / etc/redis-cluster/6379/* / etc/redis-cluster/6382cp-rf / etc/redis-cluster/6379/* / etc/redis-cluster/6383cp-rf / etc/redis-cluster/6379/* / etc/redis-cluster/6384

modifies the configuration files of 6380, 6381, 6382, 6383 and 6384 nodes respectively

Using global substitution within vi / etc/redis-cluster/6380/redis.conf:%s/6379/6380/g / / text using global replacement vi / etc/redis-cluster/6381/redis.conf:%s/6379/6381/g / / text using global substitution vi / etc/redis-cluster/6383redis.conf:%s/6379 within text / 6383g / / use global substitution within vi / etc/redis-cluster/6384redis.conf:%s/6379/6384g / / text

enables all node services (& running in the background)

For i in 79 80 81 82 83 84doredis-server / etc/redis-cluster/63$ i/redis.conf & done

login any node verifies that the node service can log in normally

Redis-cli-h 192.168.80.100-p 6379

the ruby environment required to install the cluster

since the Redis cluster needs to use the ruby command, we need to install ruby and related interfaces.

Yum-y install ruby ruby-devel rubygems rpm-build

upgrade ruby version

Gem sources-a http://mirrors.aliyun.com/rubygems/

adds aliyun image and detects Ruby version

Install RAM

(Ruby Version Manager) is a command line tool for RAM that you can easily install and manage Ruby versions using RAM. RVM includes version management and Gem library management (gemset) of Ruby.

Gpg-keyserver hkp://keys.gnupg.net-recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDBcurl-sSL https://get.rvm.io | bash-s stable source / etc/profile.d/rvm.

View the Ruby version:

Rvm list known

To install Ruby, just find anything higher than version 2.2.2 from the information found above:

Rvm install 2.6

Using the command gem to install the redis interface gem is a toolkit for ruby

Gem install redis

When the installation is complete, the ruby environment executes the following command to confirm that it is normal.

Redis-trib.rb

creates a cluster

briefly explains this command: call the ruby command to create a cluster.-- replicas 1 indicates that the master-slave replication ratio is 1:1, that is, one master node corresponds to one slave node. Then, we are assigned each master node and corresponding slave node service by default, as well as the size of the solt, because there are only 16383 solt in the Redis cluster, which will be evenly distributed to us by default. Of course, you can specify, and subsequent nodes can also be reassigned.

. / redis-trib.rb create-- replicas 1 192.168.80.100 yes 6379 192.168.80.100 yes 6380 192.168.80.100 yes

Redis-cli-- cluster create 192.168.80.100 cluster create 6379 192.168.80.100 cluster-replicas 6380 192.168.80.100 cluster-replicas 1

verification

connects through the client command, and looks at the status and node information through the cluster command.

/ usr/local/redis-cluster/bin/redis-cli-c-h 192.168.80.100-p 6379 / / Log in to 192.168.86.130 cluster nodes 6379 > cluster info / / View status 192.168.86.130 Fringe 6379 > cluster nodes / / View node information

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

Servers

Wechat

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

12
Report