Redis 5版本简介

摘要:
Redis数据结构类型是指Redis值的结构类型。Redis将数据直接存储在内存中。只有当内存空间不足时,一些数据才会持久化到磁盘。在这种情况下,当Redis重新启动时,它将优先使用AOF文件来恢复数据集,因为AOF文件保存的数据集通常比RDB文件保存的更完整。

1.redis特点

1)基于内存

(2)可持久化数据

(3)具有丰富的数据结构类型,适应非关系型数据的存储需求

(4)支持绝大多数主流开发语言,如C、C++、Java、Python、R、JavaScript等。

(5)支持集群模式,高效、稳定。

2.数据类型

(1)键值对形式。

(2)Redis的数据结构类型,指的就是Redis值的结构类型。

3. Redis作用

1)本质是数据库,能存储数据。
Redis能灵活处理非关系型数据的读、写问题,是对MySQL等关系型数据库的补充。
新浪微博就是使用Redis集群做数据库

(2)缓存数据。
所谓缓存,就是将数据加载到内存中后直接使用,而不是每次都通过IO流从磁盘上读取。好处:读写效率高。

而Redis则是将数据直接存储在内存中,只有当内存空间不足时,将部分数据持久化到磁盘上。

4.下载安装

# 官网下载
https://redis.io/download

$ wget https://download.redis.io/releases/redis-5.0.10.tar.gz
$ tar xzf redis-5.0.10.tar.gz
$ cd redis-5.0.10
$ make
$ make install

# make MALLOC=libc (有时候直接make有报错)

# redis启动命令,如果没发现redis-server去redis/src/目录查看
redis-server /usr/local/redis/redis.conf
关闭命令(如果有多个redis在同一台机器,需带上端口和IP,如果设置了密码也需要密码关闭 -a 'password'):
redis-cli -h 127.0.0.1 -p 6379 shutdown
Redis 5版本简介第1张Redis 5版本简介第2张
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

# chkconfig:   2345 90 10

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

#redis服务器监听的端口
REDISPORT=6379

#服务端所处位置
EXEC=/usr/local/bin/redis-server

#客户端位置
CLIEXEC=/usr/local/bin/redis-cli

#redis的PID文件位置,根据实际情况修改
PIDFILE=/var/run/redis_${REDISPORT}.pid

#redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/usr/local/redis/${REDISPORT}.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
redis启动脚本

5.redis常用配置文件

bind:允许访问该redis的主机

protected-mode:保护模式,默认开启。若设置外部网络连接redis服务,设置方式如下:

    1、关闭protected-mode模式,此时外部网络可以直接访问

    2、开启protected-mode保护模式,需配置bind ip或者设置访问密码,或者bind ip和密码都设置

requirepass:设置密码

databases:Redis默认有16个数据库,寻址角标从0开始。默认连接db0。客户端使用select命令,切换数据库

port :指定redis的服务端口,默认6379.

daemonize:Redis默认关闭后台进程模式,改成yes,redis服务在后台启动。

loglevel :日志等级

logfile:Redis日志输出目录,默认不输出日志到文件。

dbfilename:指定数据持久化的文件名

dir :指定数据持久化的文件存放目录,也是集群node.con文件存放目录

cluster-enabled:是否启用集群

cluster-config-file:集群文件

6. redis持久化

Redis持久化,就是将内存中的数据,永久保存到磁盘上。

Redis持久化有两种方式:RDB(Redis DB)、AOF(AppendOnlyFile)

Redis 可以同时使用 AOF 持久化和 RDB 持久化。 在这种情况下, 当 Redis 重启时, 它会优先使用 AOF 文件来还原数据集, 因为 AOF 文件保存的数据集通常比 RDB 文件所保存的数据集更完整。

6.1 RDB快照模式

# 在默认情况下,Redis 将数据库快照保存在名字为dump.rdb的二进制文件中,可以在redis.conf配置文件中修改持久化信息。
save 900 1 表示在900秒内,至少更新了1条数据。Redis就将数据持久化到硬盘
save 300 10 表示在300内,至少更新了10条数据,Redis就会触发将数据持久化到硬盘
save 60 10000 表示60秒内,至少更新了10000条数据,Redis就会触发将数据持久化到硬盘
6.1.1 策略
  1. 自动保存:BGSAVE
    按照配置文件中的条件满足就执行BGSAVE;

    非阻塞,Redis服务正常接收处理客户端请求;
    Redis会folk()一个新的子进程来创建RDB文件,子进程处理完后会向父进程发送一个信号,通知它处理完毕;
    父进程用新的dump.rdb替代旧文件。

  2.手动保存:SAVE
    客户端(redis-cli)发起SAVE命令;
    阻塞Redis服务,无法响应客户端请求;
    创建新的dump.rdb替代旧文件。

6.1.2 优点
  执行效率高;
  恢复大数据集速度较AOF快。

6.1.3 缺点
  会丢失最近写入、修改的而未能持久化的数据;
  folk过程非常耗时,会造成毫秒级不能响应客户端请求。

6.2 AOF模式(追加模式、文本重演)

AOF默认关闭,需要在配置文件中手动开启。
记录所有的写操作命令,在服务启动的时候使用这些命令就可以还原数据库。
Append only file,采用追加的方式保存,默认文件appendonly.aof。
6.2.1 写入机制
  AOF机制,添加了一个内存缓冲区(buffer):
  将内容写入缓冲区
  当缓冲区被填满、或者用户手动执行fsync、或者系统根据指定的写入磁盘策略自动调用fdatasync命令,才将缓冲区里的内容真正写入磁盘里
  在缓冲区里的内容未写入磁盘之前,可能会丢失

6.2.2 写入磁盘的策略
  appendfsync选项,这个选项的值可以是always、everysec或者no
  always:服务器每写入一个命令,就调用一次fdatasync,将缓冲区里面的命令写入到硬盘。这种模式下,服务器出现故障,也不会丢失任何已经成功执行的命令数据
  everysec(默认):服务器每一秒重调用一次fdatasync,将缓冲区里面的命令写入到硬盘。这种模式下,服务器出现故障,最多只丢失一秒钟内的执行的命令数据
  no:服务器不主动调用fdatasync,由操作系统决定何时将缓冲区里面的命令写入到硬盘。这种模式下,服务器遭遇意外停机时,丢失命令的数量是不确定的,no 选项并不能给服务器性能带来多大的提升,而且也会增加系统奔溃时数据丢失的数量。
  运行速度:always的速度慢,everysec和no都很快

7.Redis主从复制

概念
  主从复制模型中,有多个redis节点。
  其中,有且仅有一个为主节点Master。从节点Slave可以有多个。
  只要网络连接正常,Master会一直将自己的数据更新同步给Slaves,保持主从同步。

特点
  (1)主节点Master可读、可写.
  (2)从节点Slave只读。(read-only)
  因此,主从模型可以提高读的能力,在一定程度上缓解了写的能力。因为能写仍然只有Master节点一个,可以将读的操作全部移交到从节点上,变相提高了写能力。

配置:

环境:
系统:centos 7.7
master:192.168.0.111:6380
slave:192.168.0.112:6380,6381
修改redis.conf共8处,即可实现一个主从Redis搭建. 还是很简单的.现在我们正式开始搭建吧.
69行: bind 127.0.0.1 改为: bind 0.0.0.0 需要跨服务器访问,如果是生产最好指定IP或添加防火墙.
88行: protected-mode yes 改为: protected-mode no 如果是yes保护模式,需要配置bind或者设置密码,no的话则设置
92行: port 6379 改为: port 6381 访问端口
136行:daemonize no 改为: daemonize yes 守护进程模式运行
158行: pidfile /var/run/redis.pid 改为: pidfile /var/run/redis_6381.pid 启动使用的PID
263行: dir ./ 改为: dir /usr/local/redis-ms/6381/ 存储日志与数据文件的目录
287行: replicaof <masterip> <masterport> 改为:replicaof 192.168.21.22 6381 (从redis.conf配置才设置)
294行: # masterauth <master-password> 改为: masterauth o9bEuO6iDKrIhYkx slave节点设置master的密码,
507行: #requirepass 123456 改为: requirepass o9bEuO6iDKrIhYkx 设置访问时需要的密码
master配置文件:
bind 192.168.0.111
protected-mode no
port 6380
daemonize no # 先改为no,测试时可以看到打印的日志,正式环境改为yes
pidfile /var/run/redis_6380.pid
dir /usr/local/redis/master/
requirepass 123456

# 其余的参数可以自己去选择性配置

slave配置:

cd /usr/local/redis
mkdir slave/6380 -p
mkdir slave/6381 -p
cp redis.conf slave/6380/6380.conf
cp redis.conf slave/6381/6381.conf

# slave 1 配置
bind 192.168.0.112
protected-mode yes
port 6380
pidfile /var/run/redis_6380.pid
replicaof 192.168.0.111 6380
masterauth 123456
# slave2根据slave1只需要修改端口就行

启动redis后登录:

# master:
启动后可以看到:
Synchronization with replica 192.168.0.112:6380 succeeded
Synchronization with replica 192.168.0.112:6381 succeeded

redis-cli -p 6380 -a '123456' -h 192.168.0.111
192.168.0.111:6380> set cx cxiong
OK
192.168.0.111:6380> info Replication #此命令也可以看到详细信息
slave0:ip=192.168.0.112,port=6380,state=online,offset=683,lag=1
# slave1 和slave2 redis
-cli -p 6380 -h 192.168.0.112 192.168.0.112:6380> get cx "cxiong" # 写操作执行失败提示 (error) READONLY You can't write against a read only replica.
Redis 5版本简介第3张Redis 5版本简介第4张
bind 192.168.0.112
protected-mode yes
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6380.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/slave/6380/
replicaof 192.168.0.111 6380
masterauth 123456
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-ping-replica-period 10
repl-timeout 10
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
redis.conf

 8. Redis集群--Sentinel哨兵模式

1.主从模式缺陷
当主节点宕机了,整个集群就没有可写的节点了。
    问:由于从节点上备份了主节点的所有数据,那在主节点宕机的情况下,如果能够将从节点变成一个主节点,是不是就可以解决这个问题了呢?

答:是的,这个就是Sentinel哨兵的作用。

2.哨兵的任务
    Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务:
(1) 监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常。

(2) 提醒(Notification): 当被监控的某个 Redis 服务器出现问题时, Sentinel 可以通过 API 向管理员或者其他应用程序发送通知。

(3) 自动故障迁移(Automatic failover): 当一个主服务器不能正常工作时, Sentinel 会开始一次自动故障迁移操作, 它会进行选举,将其中一个从服务器升级为新的主服务器, 并让失效主服务器的其他从服务器改为复制新的主服务器; 当客户端试图连接失效的主服务器时, 集群也会向客户端返回新主服务器的地址, 使得集群可以使用新主服务器代替失效服务器。

3.监控(Monitoring)
    (1)Sentinel可以监控任意多个Master和该Master下的Slaves。(即多个主从模式)
  (2)同一个哨兵下的、不同主从模型,彼此之间相互独立。
  (3)Sentinel会不断检查Master和Slaves是否正常。

4.自动故障切换(Automatic failover)
    监控同一个Master的Sentinel会自动连接,组成一个分布式的Sentinel网络,互相通信并交换彼此关于被监视服务器的信息。

疑问:为什么要使用sentinel网络呢?
答:当只有一个sentinel的时候,如果这个sentinel挂掉了,那么就无法实现自动故障切换了。
  在sentinel网络中,只要还有一个sentinel活着,就可以实现故障切换。

5.故障切换的过程
(1)投票(半数原则)
  当任何一个Sentinel发现被监控的Master下线时,会通知其它的Sentinel开会,投票确定该Master是否下线(半数以上,所以sentinel通常配奇数个)。

(2)选举
  当Sentinel确定Master下线后,会在所有的Slaves中,选举一个新的节点,升级成Master节点。
  其它Slaves节点,转为该节点的从节点。

(3)原Master重新上线
  当原Master节点重新上线后,自动转为当前Master节点的从节点。

8.1哨兵模式部署

    使用哨兵模式需要先搭建一个主2从

# 查看主从
192.168.0.111:6380> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.0.112,port=6380,state=online,offset=578465,lag=0
slave1:ip=192.168.0.110,port=6380,state=online,offset=578465,lag=1
master_replid:550a9019ed53d63e31a678211425fab96da6ddcb
master_replid2:ef254865cc0a493e33bbc0f88694ac93263e7b10
master_repl_offset:578465
second_repl_offset:511899
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:466560
repl_backlog_histlen:111906
sentinel monitor <master-name> <ip> <redis-port> <quorum>
告诉sentinel去监听地址为ip:port的一个master,这里的master-name可以自定义,quorum是一个数字,指明当有多少个sentinel认为一个master失效时,master才算真正失效

sentinel auth-pass <master-name> <password>
设置连接master和slave时的密码,注意的是sentinel不能分别为master和slave设置不同的密码,因此master和slave的密码应该设置相同。

sentinel down-after-milliseconds <master-name> <milliseconds> 
这个配置项指定了需要多少失效时间,一个master才会被这个sentinel主观地认为是不可用的。 单位是毫秒,默认为30秒

sentinel parallel-syncs <master-name> <numslaves> 
这个配置项指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行 同步,这个数字越小,完成failover所需的时间就越长,但是如果这个数字越大,就意味着越 多的slave因为replication而不可用。可以通过将这个值设为 1 来保证每次只有一个slave 处于不能处理命令请求的状态。

sentinel failover-timeout <master-name> <milliseconds>
failover-timeout 可以用在以下这些方面:     
1. 同一个sentinel对同一个master两次failover之间的间隔时间。   
2. 当一个slave从一个错误的master那里同步数据开始计算时间。直到slave被纠正为向正确的master那里同步数据时。    
3.当想要取消一个正在进行的failover所需要的时间。    
4.当进行failover时,配置所有slaves指向新的master所需的最大时间。不过,即使过了这个超时,slaves依然会被正确配置为指向master,但是就不按parallel-syncs所配置的规则来了。

配置哨兵模式

cd /usr/local/redis
mkdir sentinel
cp sentinel.conf sentinel/

# master 由于主从设置了密码,所以这里也需要设置 port
26379 daemonize no pidfile /var/run/redis-sentinel.pid logfile "/var/log/master.log" dir /tmp # # monitor 监控master IP地址和端口,最后的数字1 是有几个哨兵确认即确认主下线 sentinel monitor mymaster 192.168.0.111 6379 1 # #修改心跳为30000毫秒 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes sentinel auth-pass mymaster 123456
sentinel notification-script mymaster /usr/local/redis/sentinel/notify.sh
# slave1 port 26379 daemonize yes pidfile /var/run/redis-sentinel.pid logfile "/var/log/slave1.log" dir /tmp sentinel monitor mymaster 192.168.0.111 6380 1 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes sentinel auth-pass mymaster 123456
sentinel notification-script mymaster /usr/local/redis/sentinel/notify.sh
# slave2 port 26379 daemonize yes pidfile /var/run/redis-sentinel.pid logfile "/var/log/slave1.log" dir /tmp sentinel monitor mymaster 192.168.0.111 6380 1 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes sentinel auth-pass mymaster 123456
sentinel notification-script mymaster /usr/local/redis/sentinel/notify.sh

notify.sh:
# 配置当master发生转移时进行邮件通知
# /bin/bash
TO="mail@qq.com"
SUBJECT="redis 发生故障转移"
CONTEXT="redis 发生故障转移"
echo -e $CONTEXT | mailx -s $SUBJECT $TO

启动:

redis-sentinel /usr/local/redis/sentinel/sentinel.conf

验证sentinel结果

[root@node1 sentinel]# redis-cli -p 26379
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.0.111:6380,slaves=2,sentinels=3
127.0.0.1:26379> 

查看monitor 信息,包含publish ping info 等信息

[root@node2 redis]# redis-cli -h 192.168.0.112 -p 6380
192.168.0.112:6380> monitor
OK
1611238079.243835 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.111,26379,2c35b4005313e08a1f63ae610f1c6b2e4fbdeb29,4,mymaster,192.168.0.111,6380,4"
1611238079.306039 [0 192.168.0.111:39986] "PING"
1611238079.319472 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.112,26379,5836276e4b4c9873f34306f9eaa954c24ce3a83f,4,mymaster,192.168.0.111,6380,4"
1611238079.371552 [0 192.168.0.112:50042] "PING"
1611238079.732581 [0 192.168.0.111:39986] "PUBLISH" "__sentinel__:hello" "192.168.0.111,26379,2c35b4005313e08a1f63ae610f1c6b2e4fbdeb29,4,mymaster,192.168.0.111,6380,4"
1611238079.951977 [0 192.168.0.110:39640] "PING"
1611238080.352478 [0 192.168.0.111:39986] "PING"
1611238080.407596 [0 192.168.0.112:50042] "PING"
1611238080.712552 [0 192.168.0.110:39640] "PUBLISH" "__sentinel__:hello" "192.168.0.110,26379,09ec92475178ccf00e52bdbfc9f71e4bab19e391,4,mymaster,192.168.0.111,6380,4"
1611238080.869619 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.110,26379,09ec92475178ccf00e52bdbfc9f71e4bab19e391,4,mymaster,192.168.0.111,6380,4"
1611238080.898855 [0 192.168.0.112:50042] "PUBLISH" "__sentinel__:hello" "192.168.0.112,26379,5836276e4b4c9873f34306f9eaa954c24ce3a83f,4,mymaster,192.168.0.111,6380,4"
1611238080.994489 [0 192.168.0.110:39640] "PING"
1611238081.292834 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.111,26379,2c35b4005313e08a1f63ae610f1c6b2e4fbdeb29,4,mymaster,192.168.0.111,6380,4"
1611238081.339470 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.112,26379,5836276e4b4c9873f34306f9eaa954c24ce3a83f,4,mymaster,192.168.0.111,6380,4"
1611238081.392597 [0 192.168.0.111:39986] "PING"
1611238081.454638 [0 192.168.0.112:50042] "PING"
1611238081.733629 [0 192.168.0.111:39986] "PUBLISH" "__sentinel__:hello" "192.168.0.111,26379,2c35b4005313e08a1f63ae610f1c6b2e4fbdeb29,4,mymaster,192.168.0.111,6380,4"
1611238082.073600 [0 192.168.0.110:39640] "PING"
1611238082.455256 [0 192.168.0.111:39986] "PING"
1611238082.511158 [0 192.168.0.112:50042] "PING"
1611238082.753551 [0 192.168.0.110:39640] "PUBLISH" "__sentinel__:hello" "192.168.0.110,26379,09ec92475178ccf00e52bdbfc9f71e4bab19e391,4,mymaster,192.168.0.111,6380,4"
1611238082.915633 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.110,26379,09ec92475178ccf00e52bdbfc9f71e4bab19e391,4,mymaster,192.168.0.111,6380,4"
1611238082.956576 [0 192.168.0.112:50042] "PUBLISH" "__sentinel__:hello" "192.168.0.112,26379,5836276e4b4c9873f34306f9eaa954c24ce3a83f,4,mymaster,192.168.0.111,6380,4"
1611238083.134109 [0 192.168.0.110:39640] "PING"
1611238083.312908 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.111,26379,2c35b4005313e08a1f63ae610f1c6b2e4fbdeb29,4,mymaster,192.168.0.111,6380,4"
1611238083.386855 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.112,26379,5836276e4b4c9873f34306f9eaa954c24ce3a83f,4,mymaster,192.168.0.111,6380,4"
1611238083.501301 [0 192.168.0.111:39986] "PING"
1611238083.541638 [0 192.168.0.112:50042] "PING"
1611238083.546508 [0 192.168.0.111:6380] "PING"
1611238083.738718 [0 192.168.0.111:39986] "PUBLISH" "__sentinel__:hello" "192.168.0.111,26379,2c35b4005313e08a1f63ae610f1c6b2e4fbdeb29,4,mymaster,192.168.0.111,6380,4"
1611238084.163607 [0 192.168.0.110:39640] "PING"
1611238084.510103 [0 192.168.0.111:39986] "PING"
1611238084.588757 [0 192.168.0.112:50042] "PING"
1611238084.791326 [0 192.168.0.110:39640] "PUBLISH" "__sentinel__:hello" "192.168.0.110,26379,09ec92475178ccf00e52bdbfc9f71e4bab19e391,4,mymaster,192.168.0.111,6380,4"
1611238084.940186 [0 192.168.0.111:6380] "PUBLISH" "__sentinel__:hello" "192.168.0.110,26379,09ec92475178ccf00e52bdbfc9f71e4bab19e391,4,mymaster,192.168.0.111,6380,4"
1611238084.963348 [0 192.168.0.112:50042] "PUBLISH" "__sentinel__:hello" "192.168.0.112,26379,5836276e4b4c9873f34306f9eaa954c24ce3a83f,4,mymaster,192.168.0.111,6380,4"
1611238085.226519 [0 192.168.0.110:39640] "PING"

测试:

redis主从正常的时候,只有主可以写,从都不能写,这是关闭主redis,可以查看日志发现转移到slave节点了,可以在slave节点写一个键 set k1 test

当原来的master启动后,进去写发现提示不能写,get k1,发现键可以获取到,已经从主变为从了

9.Redis-cluster集群

1.哨兵模式的缺陷
    在哨兵模式中,仍然只有一个Master节点。当并发写请求较大时,哨兵模式并不能缓解写压力。
  我们知道只有主节点才具有写能力,那如果在一个集群中,能够配置多个主节点,是不是就可以缓解写压力了呢?
  答:是的。这个就是redis-cluster集群模式。

2.Redis-cluster集群概念
(1)由多个Redis服务器组成的分布式网络服务集群;
(2)集群之中有多个Master主节点,每一个主节点都可读可写;
(3)节点之间会互相通信,两两相连;
(4)Redis集群无中心节点。

3.集群节点复制
    在Redis-Cluster集群中,可以给每一个主节点添加从节点,主节点和从节点直接遵循主从模型的特性。
  当用户需要处理更多读请求的时候,添加从节点可以扩展系统的读性能。

4.故障转移
    Redis集群的主节点内置了类似Redis Sentinel的节点故障检测和自动故障转移功能,当集群中的某个主节点下线时,集群中的其他在线主节点会注意到这一点,并对已下线的主节点进行故障转移。
    集群进行故障转移的方法和Redis Sentinel进行故障转移的方法基本一样,不同的是,在集群里面,故障转移是由集群中其他在线的主节点负责进行的,所以集群不必另外使用Redis Sentinel。

5.集群分片策略
  Redis-cluster分片策略,是用来解决key存储位置的
  集群将整个数据库分为16384个槽位slot,所有key-value数据都存储在这些slot中的某一个上。一个slot槽位可以存放多个数据,key的槽位计算公式为:slot_number=crc16(key)%16384,其中crc16为16位的循环冗余校验和函数。
  集群中的每个主节点都可以处理0个至16383个槽,当16384个槽都有某个节点在负责处理时,集群进入上线状态,并开始处理客户端发送的数据命令请求。

6.集群redirect转向
  由于Redis集群无中心节点,请求会随机发给任意主节点;
  主节点只会处理自己负责槽位的命令请求,其它槽位的命令请求,该主节点会返回客户端一个转向错误;
  客户端根据错误中包含的地址和端口重新向正确的负责的主节点发起命令请求。

10.集群搭建配置(系统优化参数请自行处理)

# 系统优化没做到位,redis启动后有一些warning报警,可以处理
TCP监听队列大小
  即TCP listen的backlog大小,“/proc/sys/net/core/somaxconn”的默认值一般较小如128,需要修改大一点,比如改成32767。立即生效还可以使用命令:sysctl -w net.core.somaxconn=32767。
  要想永久生效,需要在文件/etc/sysctl.conf中增加一行:net.core.somaxconn = 32767,然后执行命令“sysctl -p”以生效。
  Redis配置项tcp-backlog的值不能超过somaxconn的大小。

 OOM相关:vm.overcommit_memory
  “/proc/sys/vm/overcommit_memory”默认值为0,表示不允许申请超过CommitLimmit大小的内存。可以设置为1关闭Overcommit,设置方法请参照net.core.somaxconn完成。

 /sys/kernel/mm/transparent_hugepage/enabled
  默认值为“[always] madvise never”,建议设置为never,以开启内核的“Transparent Huge Pages (THP)”特性,设置后redis进程需要重启。为了永久生效,请将“echo never > /sys/kernel/mm/transparent_hugepage/enabled”加入到文件/etc/rc.local中。
  什么是Transparent Huge Pages?为提升性能,通过大内存页来替代传统的4K页,使用得管理虚拟地址数变少,加快从虚拟地址到物理地址的映射,以及摒弃内存页面的换入换出以提高内存的整体性能。内核Kernel将程序缓存内存中,每页内存以2M为单位。相应的系统进程为khugepaged。
  在Linux中,有两种方式使用Huge Pages,一种是2.6内核引入的HugeTLBFS,另一种是2.6.36内核引入的THP。HugeTLBFS主要用于数据库,THP广泛应用于应用程序。
  一般可以在rc.local或/etc/default/grub中对Huge Pages进行设置。
# 环境
centos 7.9: 192.168.0.111 redis端口:7001 7002 7003
centos 7.9: 192.168.0.112 redis端口:7004 7005 7006

# 在对应服务器新建目录
cd /usr/local/redis/
mkdir conf && cd conf && mkdir 7001 7002 7003 # 另外一台服务器对应新建
# 拷贝也拷贝到对应目录下
cp /usr/local/redis/redis.conf /usr/local/redis/7001/


# 配置
bind 192.168.0.111
daemon yes
port 7001
pidfile "/var/run/redis_7001.pid"
logfile "/usr/local/redis/conf/7001/redis.log"
dir "/usr/local/redis/conf/7001/"
appendonly yes
# 打开集群:yes表示以集群方式运行
cluster-enabled yes
# 默认放在dir指定的目录,注意不能包含目录,纯文件名,为redis-server进程自动维护,不能手工修改
cluster-config-file nodes-7001.conf

# 2台服务器其余的端口和配置也按照相应的修改

# 启动redis脚本
# start_cluster.sh
#!/bin/bash
cd /usr/local/redis/conf/7001/ && /usr/local/redis/src/redis-server /usr/local/redis/conf/7001/7001.conf
cd /usr/local/redis/conf/7002/ && /usr/local/redis/src/redis-server /usr/local/redis/conf/7002/7002.conf
cd /usr/local/redis/conf/7003/ && /usr/local/redis/src/redis-server /usr/local/redis/conf/7003/7003.conf

# 启动redis

10.1执行创建集群命令

[root@node1 conf]# /usr/local/redis/src/redis-cli --cluster create 192.168.0.111:7001 192.168.0.111:7002 192.168.0.111:7003 192.168.0.112:7004 192.168.0.112:7005 192.168.0.112:7006 --cluster-replicas 1

# --cluster-replicas 1  表示主从配置比,1表示的是1:1,前三个是主,后三个是从
# 若配置文件中设置的密码,则还需要加上-a passwod

>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.0.112:7006 to 192.168.0.111:7001
Adding replica 192.168.0.111:7003 to 192.168.0.112:7004
Adding replica 192.168.0.112:7005 to 192.168.0.111:7002
M: f34090f7f97229ee11bbc33decc1a572a508f217 192.168.0.111:7001
   slots:[0-5460] (5461 slots) master
M: eb7e75bc30912b79c222422696d0ce7401061d24 192.168.0.111:7002
   slots:[10923-16383] (5461 slots) master
S: e1c603a80d98724c1e9203f22e13554cd6c90836 192.168.0.111:7003
   replicates 093b4824954ef39f6aaebc549ccb778a779f6141
M: 093b4824954ef39f6aaebc549ccb778a779f6141 192.168.0.112:7004
   slots:[5461-10922] (5462 slots) master
S: 5d8919c87935443d6d0398804cf7c3633b37c725 192.168.0.112:7005
   replicates eb7e75bc30912b79c222422696d0ce7401061d24
S: bf54081536141ef94652d9decfd8ade8fd07313c 192.168.0.112:7006
   replicates f34090f7f97229ee11bbc33decc1a572a508f217
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
.
>>> Performing Cluster Check (using node 192.168.0.111:7001)
M: f34090f7f97229ee11bbc33decc1a572a508f217 192.168.0.111:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: eb7e75bc30912b79c222422696d0ce7401061d24 192.168.0.111:7002
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 093b4824954ef39f6aaebc549ccb778a779f6141 192.168.0.112:7004
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: bf54081536141ef94652d9decfd8ade8fd07313c 192.168.0.112:7006
   slots: (0 slots) slave
   replicates f34090f7f97229ee11bbc33decc1a572a508f217
S: 5d8919c87935443d6d0398804cf7c3633b37c725 192.168.0.112:7005
   slots: (0 slots) slave
   replicates eb7e75bc30912b79c222422696d0ce7401061d24
S: e1c603a80d98724c1e9203f22e13554cd6c90836 192.168.0.111:7003
   slots: (0 slots) slave
   replicates 093b4824954ef39f6aaebc549ccb778a779f6141
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

10.2 查询集群信息

[root@node1 7001]# redis-cli -c -h 192.168.0.111 -p 7001 cluster nodes
eb7e75bc30912b79c222422696d0ce7401061d24 192.168.0.111:7002@17002 master - 0 1611241903616 2 connected 10923-16383
093b4824954ef39f6aaebc549ccb778a779f6141 192.168.0.112:7004@17004 master - 0 1611241902000 4 connected 5461-10922
bf54081536141ef94652d9decfd8ade8fd07313c 192.168.0.112:7006@17006 slave f34090f7f97229ee11bbc33decc1a572a508f217 0 1611241902611 6 connected
f34090f7f97229ee11bbc33decc1a572a508f217 192.168.0.111:7001@17001 myself,master - 0 1611241901000 1 connected 0-5460
5d8919c87935443d6d0398804cf7c3633b37c725 192.168.0.112:7005@17005 slave eb7e75bc30912b79c222422696d0ce7401061d24 0 1611241901603 5 connected
e1c603a80d98724c1e9203f22e13554cd6c90836 192.168.0.111:7003@17003 slave 093b4824954ef39f6aaebc549ccb778a779f6141 0 1611241904623 4 connected
参数说明:

-c:表示以集群方式连接惹redis
-h:指定IP地址
-p:指定端口
cluster nodes:查询集群节点信息
cluster info:查询集群状态信息

查询集群各类状态

Redis 5版本简介第5张Redis 5版本简介第6张
[root@node1 redis]# redis-cli -h 192.168.0.111 -c -p 7001
192.168.0.111:7001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:416
cluster_stats_messages_pong_sent:403
cluster_stats_messages_sent:819
cluster_stats_messages_ping_received:398
cluster_stats_messages_pong_received:416
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:819
192.168.0.111:7001> cluster nodes
bc053eba10e250a7cdd6dbf399bc962e27f5d866 192.168.0.111:7002@17002 master - 0 1611318904748 2 connected 10923-16383
96ed924479ba846bf3e82ef8669dc34082c9c09b 192.168.0.111:7003@17003 slave cc381563074a7779a0ad250b83301b81d50ba2d6 0 1611318904000 4 connected
e5700897b67917699bb68f22dae624300c2cc042 192.168.0.111:7001@17001 myself,master - 0 1611318899000 1 connected 0-5460
cc381563074a7779a0ad250b83301b81d50ba2d6 192.168.0.112:7004@17004 master - 0 1611318905756 4 connected 5461-10922
200087a0430621a44d42dae772413ce47cc7ba20 192.168.0.112:7006@17006 slave e5700897b67917699bb68f22dae624300c2cc042 0 1611318903742 6 connected
f0eaffe55a1543445231a22574fce085299eb383 192.168.0.112:7005@17005 slave bc053eba10e250a7cdd6dbf399bc962e27f5d866 0 1611318903000 5 connected
192.168.0.111:7001> set name cxiong
-> Redirected to slot [5798] located at 192.168.0.112:7004
OK
192.168.0.112:7004> set sex 1
-> Redirected to slot [2584] located at 192.168.0.111:7001
OK
192.168.0.111:7001> set addr 10086
-> Redirected to slot [12790] located at 192.168.0.111:7002
OK
192.168.0.111:7002> get name
-> Redirected to slot [5798] located at 192.168.0.112:7004
"cxiong"
192.168.0.112:7004> get addr
-> Redirected to slot [12790] located at 192.168.0.111:7002
"10086"
192.168.0.111:7002> get sex
-> Redirected to slot [2584] located at 192.168.0.111:7001
"1"
测试

10.3 redis cluster集群重新启动

暂时未知

10.4 redis-cli 集群命令帮助

[root@node1 redis]# redis-cli --cluster help
Cluster Manager Commands:
  create         host1:port1 ... hostN:portN
                 --cluster-replicas <arg>
  check          host:port
                 --cluster-search-multiple-owners
  info           host:port
  fix            host:port
                 --cluster-search-multiple-owners
  reshard        host:port
                 --cluster-from <arg>
                 --cluster-to <arg>
                 --cluster-slots <arg>
                 --cluster-yes
                 --cluster-timeout <arg>
                 --cluster-pipeline <arg>
                 --cluster-replace
  rebalance      host:port
                 --cluster-weight <node1=w1...nodeN=wN>
                 --cluster-use-empty-masters
                 --cluster-timeout <arg>
                 --cluster-simulate
                 --cluster-pipeline <arg>
                 --cluster-threshold <arg>
                 --cluster-replace
  add-node       new_host:new_port existing_host:existing_port
                 --cluster-slave
                 --cluster-master-id <arg>
  del-node       host:port node_id
  call           host:port command arg arg .. arg
  set-timeout    host:port milliseconds
  import         host:port
                 --cluster-from <arg>
                 --cluster-copy
                 --cluster-replace
  help           

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

10.5 测试故障性转移

  在故障期间,获取key值都可以在别的nodes里获取到

# 在此测试期间,为了触发故障转移,我们可以做的最简单的事情(也就是在分布式系统中可能出现的语义上最简单的故障)是使单个进程崩溃
[root@Master conf]# redis-cli -h 192.168.0.112 -p 7001 debug segfault
Error: Server closed the connection
# redis-cli -h 192.168.0.112 -p 7004 debug segfault
[root@node1 7003]# redis-cli -c -h 192.168.0.111 -p 7002
192.168.0.111:7002> cluster nodes
bc053eba10e250a7cdd6dbf399bc962e27f5d866 192.168.0.111:7002@17002 myself,master - 0 1611320054000 2 connected 10923-16383
cc381563074a7779a0ad250b83301b81d50ba2d6 192.168.0.112:7004@17004 master,fail - 1611319488239 1611319486221 4 disconnected
96ed924479ba846bf3e82ef8669dc34082c9c09b 192.168.0.111:7003@17003 master - 0 1611320058188 7 connected 5461-10922
200087a0430621a44d42dae772413ce47cc7ba20 192.168.0.112:7006@17006 master - 0 1611320057174 8 connected 0-5460
f0eaffe55a1543445231a22574fce085299eb383 192.168.0.112:7005@17005 slave bc053eba10e250a7cdd6dbf399bc962e27f5d866 0 1611320056159 5 connected
e5700897b67917699bb68f22dae624300c2cc042 192.168.0.111:7001@17001 master,fail - 1611319646927 1611319645000 1 disconnected

重新启动故障redis

192.168.0.111:7002> cluster nodes
bc053eba10e250a7cdd6dbf399bc962e27f5d866 192.168.0.111:7002@17002 myself,master - 0 1611320358000 2 connected 10923-16383
cc381563074a7779a0ad250b83301b81d50ba2d6 192.168.0.112:7004@17004 slave 96ed924479ba846bf3e82ef8669dc34082c9c09b 0 1611320359379 7 connected
96ed924479ba846bf3e82ef8669dc34082c9c09b 192.168.0.111:7003@17003 master - 0 1611320360388 7 connected 5461-10922
200087a0430621a44d42dae772413ce47cc7ba20 192.168.0.112:7006@17006 master - 0 1611320358000 8 connected 0-5460
f0eaffe55a1543445231a22574fce085299eb383 192.168.0.112:7005@17005 slave bc053eba10e250a7cdd6dbf399bc962e27f5d866 0 1611320359000 5 connected
e5700897b67917699bb68f22dae624300c2cc042 192.168.0.111:7001@17001 slave 200087a0430621a44d42dae772413ce47cc7ba20 0 1611320359000 8 connected

10.6 集群管理

# 1.添加新的主节点
redis-cli --cluster add-node new_host:new_port existing_host:existing_port --cluster-master-id node_id
# 例子说明
# 给已存在的192.168.0.111:7001端口再添加一个 new_host:new_port为要新添加的主节点IP和端口,此处是192.
168.0.110:7007 existing_host:existing_port表示的是已存在的一个主节点的IP和端口,这个可以从上述的节点信息中查看到,根据slots槽数,7003端口对应的节点槽数是10923-16383,16383表示的是最后的槽数 --cluster-master-id表示的是最后一个主节点的节点id,表示的是新添加的主节点要在这个节点后面 [root@node1 ~]# redis-cli --cluster add-node 192.168.0.110:7007 192.168.0.111:7001 --cluster-master-id e5700897b67917699bb68f22dae624300c2cc042 >>> Adding node 192.168.0.110:7007 to cluster 192.168.0.111:7001 >>> Performing Cluster Check (using node 192.168.0.111:7001) S: e5700897b67917699bb68f22dae624300c2cc042 192.168.0.111:7001 slots: (0 slots) slave replicates 200087a0430621a44d42dae772413ce47cc7ba20 M: 96ed924479ba846bf3e82ef8669dc34082c9c09b 192.168.0.111:7003 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 200087a0430621a44d42dae772413ce47cc7ba20 192.168.0.112:7006 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: f0eaffe55a1543445231a22574fce085299eb383 192.168.0.112:7005 slots: (0 slots) slave replicates bc053eba10e250a7cdd6dbf399bc962e27f5d866 M: bc053eba10e250a7cdd6dbf399bc962e27f5d866 192.168.0.111:7002 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: cc381563074a7779a0ad250b83301b81d50ba2d6 192.168.0.112:7004 slots: (0 slots) slave replicates 96ed924479ba846bf3e82ef8669dc34082c9c09b [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. >>> Send CLUSTER MEET to node 192.168.0.110:7007 to make it join the cluster. [OK] New node added correctly. # 查看 192.168.0.110:7007> cluster nodes 99aa44c17491637deecbddda5bbfc80890b4daf3 192.168.0.110:7007@17007 myself,slave bc053eba10e250a7cdd6dbf399bc962e27f5d866 0 1611323597000 1 connected f0eaffe55a1543445231a22574fce085299eb383 192.168.0.112:7005@17005 slave bc053eba10e250a7cdd6dbf399bc962e27f5d866 0 1611323596468 2 connected e5700897b67917699bb68f22dae624300c2cc042 192.168.0.111:7001@17001 slave 200087a0430621a44d42dae772413ce47cc7ba20 0 1611323593000 8 connected 200087a0430621a44d42dae772413ce47cc7ba20 192.168.0.112:7006@17006 master - 0 1611323595000 8 connected 0-5460 bc053eba10e250a7cdd6dbf399bc962e27f5d866 192.168.0.111:7002@17002 master - 0 1611323594451 2 connected 10923-16383 96ed924479ba846bf3e82ef8669dc34082c9c09b 192.168.0.111:7003@17003 master - 0 1611323597476 7 connected 5461-10922 cc381563074a7779a0ad250b83301b81d50ba2d6 192.168.0.112:7004@17004 slave 96ed924479ba846bf3e82ef8669dc34082c9c09b 0 1611323595460 7 connected
# 2.hash槽重新分配
# 添加完新节点后,需要对新添加的主节点进行hash槽重新分配,这样该主节点才能存储数据,redis共有16384个槽。(node_id必须都是主节点)
redis-cli --cluster reshard host:port --cluster-from node_id --cluster-to node_id --cluster-slots <args> --cluster-yes
# 例子说明
host:port表示的是新添加的那个主节点IP和端口,此处表示的是IP:7007(由于测试变为slave了,结果添加不了)
--cluster-from node_id表示的是集群第一个主节点的节点id,这个可以现有集群的slots槽数分配看出,此处表示的是7001端口对应的节点
--cluster-to node_id表示的是集群最后一个主节点的节点id,也就是新添加的那个主节点id,此处表示的是7007端口对应的节点
--cluster-slots 500表示的是给新主节点分配多少,此处500表示是分配从0-499个slots槽数,若不加上这个会让手动输入
--cluster-yes表示的是自动应答为yes,若不加上这个会让手动输入yes,表示同意此次分配
# 3.添加新从节点
redis-cli --cluster add-node new_host:new_port existing_host:existing_port --cluster-slave --cluster-master-id node_id
例如:redis-cli --cluster add-node 192.168.0.110:7008 192.168.0.111:7002 --cluster-slave --cluster-master-id bc053eba10e250a7cdd6dbf399bc962e27f5d866
cluster nodes:03033fcdade6b2bb1663852216003e8168e064ea 192.168.0.110:7008@17008 slave bc053eba10e250a7cdd6dbf399bc962e27f5d866 0 1611324674580 2 connected
#
4.删除节点 redis-cli --cluster del-node host:port node_id
例如:

[root@Master conf]# redis-cli --cluster del-node 192.168.0.110:7008 03033fcdade6b2bb1663852216003e8168e064ea
>>> Removing node 03033fcdade6b2bb1663852216003e8168e064ea from cluster 192.168.0.110:7008
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

删除后可以发现刚添加的从节点已经小时了

 # 5.删除后从其他节点还是可以看到这个节点,需要执行其他命令,这样这个节点就看不见了

192.168.0.111:7001>cluster forget 03033fcdade6b2bb1663852216003e8168e064ea

11.人工手动切换主从

在需要变为主节点的slave上执行

192.168.0.112:7005> cluster failover
OK
# 然后查看就可以发现从slave 变为myself,master 
f0eaffe55a1543445231a22574fce085299eb383 192.168.0.112:7005@17005 myself,master - 0 1611325331000 11 connected 10923-16383

12.大压力下redis参数调整要点

为何大压力下要这样调整?

最重要的原因之一Redis的主从复制,两者复制共享同一线程,虽然是异步复制的,但因为是单线程,所以也十分有限。如果主从间的网络延迟不是在0.05左右,比如达到0.6,甚至1.2等,那么情况是非常糟糕的,因此同一Redis集群一定要部署在同一机房内。

这些参数的具体值,要视具体的压力而定,而且和消息的大小相关,比如一条200~500KB的流水数据可能比较大,主从复制的压力也会相应增大,而10字节左右的消息,则压力要小一些。大压力环境中开启appendfsync是十分不可取的,容易导致整个集群不可用,在不可用之前的典型表现是QPS毛刺明显。

这么做的目的是让Redis集群尽可能的避免master正常时触发主从切换,特别是容纳的数据量很大时,和大压力结合在一起,集群会雪崩

参数

建议最小值

说明

repl-ping-slave-period

10

每10秒ping一次

repl-timeout

60

60秒超时,也就是ping十次

cluster-node-timeout

15000

repl-backlog-size

1GB

Master对slave的队列大小

appendfsync

no

让系统自动刷

save

大压力下,调大参数值,以减少写RDB带来的压力:

"900 20 300 200 60 200000"

appendonly

对于队列,建议单独建立集群,并且设置该值为no

免责声明:文章转载自《Redis 5版本简介》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇佛山居住证办理(首次)释放虚拟磁盘未使用空间来减少计费容量下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Git敏捷开发--rebase命令

git rebase是git下比较常用的命令,以下记录自己遇到较多的使用场景。 合并分支 在多人协作的项目中,拉分支是很常见的事情,经常需要同步自己的分支与远端master分支一致,有两种方式: git merge master git rebase master 两者的区别在于:前者会在生成一条 Merge branch master into XX...

Redis——6.0集群安装部署

前言 redis集群化部署主要用于大型缓存架构,一般的小型架构,使用redis主从配置 + sentinel哨兵集群应付系统压力, 使用redis集群可以方便快捷地对集群进行动态扩容,动态的添加、删除节点,reshard、并带有自动故障恢复功能。 一般redis集群使用三主三从,并且尽量保证主服务器与从服务器不在同一台机器上,防止机器故障导致的集群瘫痪,每...

Redis 内存压缩原理

Redis 无疑是一个大量消耗内存的数据库,因此 Redis 引入了一些设计巧妙的数据结构进行内存压缩来减轻负担。ziplist、quicklist 以及 intset 是其中最常用最重要的压缩存储结构。 了解编码类型 Redis对外提供了 string, list, hash, set, zset等数据类型,每种数据类型可能存在多种不同的底层实现,这些底...

Mosquito集群模式

参考链接: http://blog.csdn.net/z729685731/article/details/70142182 http://blog.csdn.net/yuhaiyang457288/article/details/73927889 集群效果:无论在哪台服务器中订阅的信息,无论在哪台服务器上发布了信息,订阅者都可以收到发布的信息。 集群部署...

k8s中设置探针-存活探针和就绪探针

基础概念 探针 是由 kubelet 对容器执行的定期诊断。 针对运行中的容器,kubelet 可以选择是否执行以下三种探针,以及如何针对探测结果作出反应: livenessProbe:指示容器是否正在运行。如果存活态探测失败,则 kubelet 会杀死容器, 并且容器将根据其重启策略决定未来。如果容器不提供存活探针, 则默认状态为 Success。 r...

从零开始的野路子React/Node(7)将Swagger(OpenAPI)运用于后端API

之前公司做项目是用过swagger来配置python模型的API,感觉非常好用。swagger可以提供request, response甚至error的验证机制,十分便利。node当然也可以用啦。 我们需要使用的库主要是swagger-ui-express,它将提供swagger的相关功能以及一个UI,方便查看和调试。 1、初始设定 老规矩,我们还是通过e...