redis的模式

1、三种模式:

主从模式(redis2.8版本之前的模式)、哨兵sentinel模式(redis2.8及之后的模式)、redis cluster模式(redis3.0版本之后)
一般在配置模式时有:一主二从三哨兵,我的理解是,开启主从模式,然后开启哨兵模式。

2、主从模式

主从模式下,主机将文件复制到从机上,当主机无法使用时,那么可以从从机上读取到数据,但是无法进行写入到从机上。也就是说主从模式下,只读不写

关于注重模式配置文件的设置:

1、绑定地址的设置
bind 127.0.0.1  // 绑定主机
2、端口的重新设置,要和端口不一致
port 6381
3、设置从文件,并解释该从文件是绑定6379端口的主文件。
slaveof 127.0.0.1 6379

主从机对待写入差别:

主机写入:
127.0.0.1:6379> set a 1
OK
127.0.0.1:6379> get a
"1"
从机写入:
127.0.0.1:6380> set b 2
(error) READONLY You can't write against a read only slave.

3、哨兵(sentinel)模式

哨兵模式,在原先主从模式的情形下,进行改进,通过一个或多个的sentinel实例组成的sentinel系统监视主机,当主机无法使用时,就会让某一个从机作为新的主机,然后可以在这个新的主机下进行写入。

哨兵模式的配置文件设置:

bind  127.0.0.1    // 绑定的主机路径
port 26381         // 绑定的端口,默认是6379,根据配置的开启的redis的端口来配置
daemonize yes      // 不清楚
// mymaster 表示该主机名称 127.0.0.1表示主机路径 6379表示主机名 
// 2表示当主机失效时,至少需要2个sentinel进程来同意
sentinel monitor mymaster 127.0.0.1 6379 2   
// 表示mymaster挂掉确认时间为30000毫秒,也就是30秒。
sentinel down-after-milliseconds mymaster 30000
// 不清楚
sentinel parallel-syncs mymaster 1
// 超时确认时间需要15000毫秒
sentinel failover-timeout mymaster 15000
// 设置主机名称和密码
sentinel auth-pass mymaster 123

哨兵模式的开启:

// start表示win开启的代码 后面表示以哨兵模式开启的配置文件
start redis-server.exe sentinel26379.conf --sentinel

当主机down掉后,信息如下:

//以下是6379服务器下的少量日志
// 表示失败,
[17104] 10 Feb 22:15:46.743 # Next failover delay: I will not start a failover before Wed Feb 10 22:16:17 2021
[17104] 10 Feb 22:15:47.863 # +config-update-from sentinel d843144bc49de301acd04340ce7dc43595b0cebf 127.0.0.1 26381 @ mymaster 127.0.0.1 6379
// 将主机分配给6380服务器
[17104] 10 Feb 22:15:47.863 # +switch-master mymaster 127.0.0.1 6379 127.0.0.1 6380
[17104] 10 Feb 22:15:47.868 * +slave slave 127.0.0.1:6381 127.0.0.1 6381 @ mymaster 127.0.0.1 6380
// 将6379端口的服务器设置为6380从机
[17104] 10 Feb 22:15:47.869 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6380
[17104] 10 Feb 22:16:17.878 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6380

查看redis.conf下的配置:
6379,6380,6381服务器下的配置修改信息:

//redis6379.conf
slaveof 127.0.0.1 6380

//redis6380.conf

//redis6381.conf
slaveof 127.0.0.1 6380
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值