Support micro-Bo one hundred million social networking platform, white can also be Fun Redis cluster (actual combat piece)

The article "support micro-Bo one hundred million social networking platform, white can also be Fun Redis cluster (the principle of)" describes the relevant principles Redis cluster, this article will introduce the build Redis Cluster cluster configuration, operation and maintenance, expansion, etc. specific operations

Cluster Setup

October 2018 Redis released a stable version of the 5.0 version, introduced a variety of new features, one of which is a C language redis-cli-based, easy to build clusters of cluster management tools from Ruby-based graft to and redis-trib.rb management

Redis Cluster running cluster must contain at least three primary nodes, high availability requires a minimum of three master nodes from six 3

The following steps are based on Redis 5.0.5 version, describes how to set up a 3-36 master node from the cluster of Redis on a Linux server

  • Step 1 Create the installation directory
mkdir -p /data/project/redis-cluster
  • Step 2. Download and extract the source code compilation
cd /data/project/redis-cluster
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar xzf redis-5.0.5.tar.gz
cd redis-5.0.5
make

After executing make, if the error "jemalloc / jemalloc.h: No such file or directory", can be changed with the following command:

make MALLOC=libc
  • Step 3 6 Redis Create profile
    6 profiles not in the same directory, the following Redis six nodes 7000 to 7005 are mounted on the port
    first create a configuration file directories and files, is defined as follows:
mkdir -p /data/project/redis-cluster/nodes/7000
mkdir -p /data/project/redis-cluster/nodes/7001
mkdir -p /data/project/redis-cluster/nodes/7002
mkdir -p /data/project/redis-cluster/nodes/7003
mkdir -p /data/project/redis-cluster/nodes/7004
mkdir -p /data/project/redis-cluster/nodes/7005

touch /data/project/redis-cluster/nodes/7000/redis.conf
touch /data/project/redis-cluster/nodes/7001/redis.conf
touch /data/project/redis-cluster/nodes/7002/redis.conf
touch /data/project/redis-cluster/nodes/7003/redis.conf
touch /data/project/redis-cluster/nodes/7004/redis.conf
touch /data/project/redis-cluster/nodes/7005/redis.conf

Redis.conf contents of the configuration file is:

############################## 网络 ##############################
# 端口
port 7000
# 非保护模式,如果值为yes,则必须是 bind配置指定的ip的机器连接或者使用密码连接
protected-mode no 

############################## 通用 ##############################
# 后台运行
daemonize yes 
# 记录redis进程pid
pidfile  /var/run/redis_7000.pid

############################## 集群 ##############################
# 启用集群模式
cluster-enabled yes 
cluster-config-file nodes_7000.conf
# 集群节点如果在该超时时间(毫秒)内不可达,则认为节点处于故障状态
cluster-node-timeout 5000

############################## 持久化 ##############################
# AOF, RDB持久化文件目录
dir /data/project/redis-cluster/nodes
# 开启AOF持久化
appendonly yes
# AOF文件名
appendfilename "appendonly_7000.aof"
# 当目前aof文件大小超过上一次重写的aof文件大小的百分之多少进行重写
auto-aof-rewrite-percentage 100
# 设置允许重写的最小aof文件大小,避免了达到约定百分比但尺寸仍然很小的情况还要重写
auto-aof-rewrite-min-size 64mb
# RDB文件名
dbfilename dump_7000.rdb

Wherein the port, pidfile, cluster-config-file, appendfilename, dbfilename configuration needs to be adjusted with different nodes

Item Description refer to redis-5.0.5 / redis.conf, each of which describes it in detail, recommended reading

  • Step 4 Start node
/data/project/redis-cluster/redis-5.0.5/src/redis-server /data/project/redis-cluster/nodes/7000/redis.conf
/data/project/redis-cluster/redis-5.0.5/src/redis-server /data/project/redis-cluster/nodes/7001/redis.conf
/data/project/redis-cluster/redis-5.0.5/src/redis-server /data/project/redis-cluster/nodes/7002/redis.conf
/data/project/redis-cluster/redis-5.0.5/src/redis-server /data/project/redis-cluster/nodes/7003/redis.conf
/data/project/redis-cluster/redis-5.0.5/src/redis-server /data/project/redis-cluster/nodes/7004/redis.conf
/data/project/redis-cluster/redis-5.0.5/src/redis-server /data/project/redis-cluster/nodes/7005/redis.conf

ps -ef | grep redis, you can see six redis process started:

  • Step 5 starts the cluster
    using the following command to start the cluster, IP address, its own replacement:
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster create 192.168.56.102:7000 192.168.56.102:7001 192.168.56.102:7002 192.168.56.102:7003 192.168.56.102:7004 192.168.56.102:7005 --cluster-replicas 1

Successful start information is as follows:

This, Redis Cluster Cluster Setup complete

Cluster View

Redis5 new series of redis-cli cluster operation and maintenance functions, commands View details:

/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster help

Command parameters can refer to the specific role of official documents, the following will be based on some of the common commands for cluster management

  • Check the node status
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster check 192.168.56.102:7000

  • View cluster information
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster info 192.168.56.102:7000

Cluster expansion

There are 3 main clusters from 3, to add the following four main node 5 from the expansion becomes 5

  • Step 1 start the new node
    created Redis profile 4, the port number is 7006 - 7009, (refer to step "Cluster Bases" in step 3 and 4) and then start node
  • Step 2 The new node joins the cluster
    set has four nodes are added redis cluster master node 2, node 2 from
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster add-node 192.168.56.102:7006 192.168.56.102:7005 
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster add-node 192.168.56.102:7007 192.168.56.102:7005 

# 24e2c是节点7006的id,代表该节点加入集群并为7006的从节点
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster add-node 192.168.56.102:7008 192.168.56.102:7005 --cluster-slave --cluster-master-id 24e2c369678952b07d95c0a4b49c2d7a7b2e2bf7 
# 24e2c是节点7007的id,代表该节点加入集群并为7007的从节点
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster add-node 192.168.56.102:7009  192.168.56.102:7005 --cluster-slave --cluster-master-id ab0f74a19819a74238df7a510494e9418678cbe1

At this time, as the cluster state, wherein the master node of the master node 7006 and 7007 have not been allocated any slot, the following steps will be allocated:

  • Step 3 rebalanced simulated slot allocation
    based rebalance command, increase --cluster-simulat parameters to see which slots are migrated, without actually performing the migration operations
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster rebalance 192.168.56.102:7000 --cluster-threshold 1 --cluster-use-empty-masters  --cluster-simulat

Migration returns the following information:

  • Step 4 rebalancing slot allocation
    performed rebalance command, the number of the cluster nodes balanced slot, slot reallocation (remove --cluster-simulat)
/data/project/redis-cluster/redis-5.0.5/src/redis-cli --cluster rebalance 192.168.56.102:7000 --cluster-threshold 1 --cluster-use-empty-masters

At this point, the cluster expansion is completed, the cluster volume reduction, then, need to move to other nodes need to be offline based reshard node in slot, and then delete command del-node based on the node

to sum up

This article describes some of the basic Redis Cluster cluster implementation, limited space, followed by the opportunity to expand the number of online questions introduce Redis stepped pit experience, operation and maintenance monitoring platform, welcome to continue to focus on

reference

redis cluster management tools redis-trib-rb Detailed
http://weizijun.cn/2016/01/08/redis%20cluster management tools redis-trib-rb Comments /

Guess you like

Origin www.cnblogs.com/caison/p/11717636.html