redis复制+Sentinel搭建
tar xzf redis-3.2.8.tar.gz
cd redis-3.2.8
yum install gcc
make
注意我们使用的是redis3.2.8的版本,这是目前最稳定也是最新的redis版本了。下面我们看一下简单配置
#bind 127.0.0.1 # 绑定的主机地址
protected-mode no # 是否开启保护模式,开启该参数后,redis只会本地进行访问
port 6379
timeout 300 # 当客户端闲置多长时间后关闭连接 daemonize yes # 是否以守护进程的模式运行
pidfile /home/redis/tmp/redis_6379.pid loglevel notice # 日志级别,最好是warning
logfile /home/redis/log/redis_6379.log databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes # 在出现错误的时候,是否要停止保存
rdbcompression yes # 使用压缩rdb文件
rdbchecksum yes # 是否校验rdb文件的名称
dbfilename dump.rdb
dir /home/redis/data # 数据库目录,数据库的写入会在这个目录 slave-serve-stale-data yes #主从失去联系以后,继续相应客户端的请求
#slave-read-only yes # yes开启从库只读
repl-diskless-sync no # 是否使用socket方式复制数据,采用disk的方式
repl-diskless-sync-delay 5 # diskless复制的延迟时间,默认值是5,可以不设置
repl-disable-tcp-nodelay no #此设置可减少延迟
slave-priority 100 # 设置优先级,最低的优先级会优先称为主节点 appendonly no #不使用appendonly来进行持久化操作
#appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no #
auto-aof-rewrite-percentage 100 #开始重写日志
auto-aof-rewrite-min-size 64mb lua-time-limit 5000 #最长时间设置,默认为毫秒
slowlog-log-slower-than 10000 #慢查询的时间
slowlog-max-len 128 latency-monitor-threshold 0 #关闭监视器
requirepass maxiangqianredis
port 6379
timeout 300 daemonize yes
pidfile /home/redis/tmp/redis_6379.pid loglevel notice
logfile /home/redis/log/redis_6379.log databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /home/redis/data slave-serve-stale-data yes
#slave-read-only yes # yes开启从库只读
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100 appendonly no
#appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128 latency-monitor-threshold 0
requirepass maxiangqianredis
slaveof 172.16.16.34 6379
masterauth maxiangqianredis
[root@localhost redis]# /home/maxiangqian/redis-3.2.8/src/redis-cli
127.0.0.1:6379> AUTH maxiangqianredis
OK
127.0.0.1:6379> set name maxiangqian
OK
[root@mxqmongodb2 redis]# /home/maxiangqian/redis-3.2.8/src/redis-cli
127.0.0.1:6379> get name
127.0.0.1:6379> AUTH maxiangqianredis
OK
127.0.0.1:6379> get name
"maxiangqian"
edis-sentinel /path/to/sentinel.conf
redis-server /path/to/sentinel.conf --sentinel
port 26379
logfile "/home/Sentinel/log/sentinel_263797.log"
daemonize yes
sentinel monitor localhost 172.16.16.34 6379 2
sentinel down-after-milliseconds localhost 60000
sentinel failover-timeout localhost 180000
sentinel parallel-syncs localhost 1
sentinel auth-pass localhost maxiangqianredis
#sentinel notification-script <master-name> <script-path>
PING :返回 PONG 。
SENTINEL masters :列出所有被监视的主服务器,以及这些主服务器的当前状态。
SENTINEL slaves :列出给定主服务器的所有从服务器,以及这些从服务器的当前状态。
SENTINEL get-master-addr-by-name : 返回给定名字的主服务器的 IP 地址和端口号。 如果这个主服务器正在执行故障转移操作, 或者针对这个主服务器的故障转移操作已经完成, 那么这个命令返回新的主服务器的 IP 地址和端口号。
SENTINEL reset : 重置所有名字和给定模式 pattern 相匹配的主服务器。 pattern 参数是一个 Glob 风格的模式。 重置操作清楚主服务器目前的所有状态, 包括正在执行中的故障转移, 并移除目前已经发现和关联的, 主服务器的所有从服务器和 Sentinel 。
SENTINEL failover : 当主服务器失效时, 在不询问其他 Sentinel 意见的情况下, 强制开始一次自动故障迁移 (不过发起故障转移的 Sentinel 会向其他 Sentinel 发送一个新的配置,其他 Sentinel 会根据这个配置进行相应的更新)。
[root@mxqmongodb2 home]# mkdir Sentinel
[root@mxqmongodb2 home]# cd Sentinel/
[root@mxqmongodb2 Sentinel]# mkdir data log tmp
启动:
/home/maxiangqian/redis-3.2.8/src/redis-server /home/Sentinel/sentinel.conf --sentinel
SENTINEL masters
SENTINEL slaves localhost
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=localhost,status=ok,address=172.16.16.34:6379,slaves=2,sentinels=4
127.0.0.1:26379> sentinel failover localhost
OK
下面我们看一下redis强制故障转移以后的信息
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=localhost,status=ok,address=172.16.16.35:6379,slaves=2,sentinels=2
29042:X 28 Apr 10:55:14.340 # +try-failover master localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:14.394 # +vote-for-leader 51fc16eb8e0bf950a3f3ada8c1eb9d70145c9ffb 1
29042:X 28 Apr 10:55:14.395 # +elected-leader master localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:14.395 # +failover-state-select-slave master localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:14.457 # +selected-slave slave 172.16.16.35:6379 172.16.16.35 6379 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:14.457 * +failover-state-send-slaveof-noone slave 172.16.16.35:6379 172.16.16.35 6379 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:14.510 * +failover-state-wait-promotion slave 172.16.16.35:6379 172.16.16.35 6379 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:15.436 # +promoted-slave slave 172.16.16.35:6379 172.16.16.35 6379 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:15.436 # +failover-state-reconf-slaves master localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:15.507 * +slave-reconf-sent slave 172.16.16.35:6380 172.16.16.35 6380 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:16.465 * +slave-reconf-inprog slave 172.16.16.35:6380 172.16.16.35 6380 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:16.466 * +slave-reconf-done slave 172.16.16.35:6380 172.16.16.35 6380 @ localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:16.540 # +failover-end master localhost 172.16.16.34 6379
29042:X 28 Apr 10:55:16.540 # +switch-master localhost 172.16.16.34 6379 172.16.16.35 6379
29042:X 28 Apr 10:55:16.541 * +slave slave 172.16.16.35:6380 172.16.16.35 6380 @ localhost 172.16.16.35 6379
29042:X 28 Apr 10:55:16.541 * +slave slave 172.16.16.34:6379 172.16.16.34 6379 @ localhost 172.16.16.35 6379
redis复制+Sentinel搭建的更多相关文章
- Redis 复制、Sentinel的搭建和原理说明
背景: Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端) ...
- Redis 复制、Sentinel的搭建和原理说明(转)
Redis 复制.Sentinel的搭建和原理说明 转自:http://www.cnblogs.com/zhoujinyi/p/5570024.html. 背景: Redis-Sentinel是Re ...
- redis单点、redis主从、redis哨兵sentinel,redis集群cluster配置搭建与使用
目录 redis单点.redis主从.redis哨兵 sentinel,redis集群cluster配置搭建与使用 1 .redis 安装及配置 1.1 redis 单点 1.1.2 在命令窗口操作r ...
- Redis哨兵(sentinel)模式搭建
一.Sentinel介绍 之前骚了一波Redis的简介及应用场景,今天试了下他的哨兵模式: Sentinel是Redis的高可用性(HA)解决方案,由一个或多个Sentinel实例组成的Sentine ...
- Redis复制与可扩展集群搭建
抄自:http://www.infoq.com/cn/articles/tq-redis-copy-build-scalable-cluster 讨论了Redis的常用数据类型与存储机制,本文会讨论一 ...
- (转)Redis复制与可扩展集群搭建
讨论了Redis的常用数据类型与存储机制,本文会讨论一下Redis的复制功能以及Redis复制机制本身的优缺点以及集群搭建问题. Redis复制流程概述 Redis的复制功能是完全建立在之前我们讨论过 ...
- Redis复制与可扩展集群搭建【转】
本文会讨论一下Redis的复制功能以及Redis复制机制本身的优缺点以及集群搭建问题. Redis复制流程概述 Redis的复制功能是完全建立在之前我们讨论过的基于内存快照的持久化策略基础上的,也就是 ...
- redis复制集(sentinel)
https://www.jianshu.com/p/45ffd2a84143 内核配置 cat >> /etc/rc.local << EOF echo never > ...
- Redis集群搭建&访问
集群搭建步骤 1.创建多个节点: 2.为每个节点指派槽,并将多个节点连接起来,组成一个集群: 3.当集群数据库的16384个槽都有节点在处理时,集群进入上线状态: 要求:搭建一个包含6个节点的Redi ...
随机推荐
- Nearest Common Ancestors(LCA板子)
题目链接:http://poj.org/problem?id=1330 Nearest Common Ancestors Time Limit: 1000MS Memory Limit: 1000 ...
- CommandBehavior.CloseConnection有何作用
其用在ExecuteReader(c)中,返回对象前不能关闭数据库连接,须用CommandBehavior.CloseConnection: 这是一个关于实际知识点的问题,面试官考查的是应聘者数据库访 ...
- 国内Windows系统go get语言包
这时候我们需要设置代理.代理工具我推荐用 lantern https://github.com/getlantern/lantern 需要注意的是,它的代理地址是: http://127.0.0.1: ...
- Python数据类型(数字)
文章内容参考了教程:http://www.runoob.com/python/python-basic-syntax.html#commentform Python 变量类型 变量存储在内存中的值.这 ...
- 009-MailUtils工具类模板
版本一:JavaMail的一个工具类 package ${enclosing_package}; import java.security.GeneralSecurityException; impo ...
- [转]微信小程序登录数据解密以及状态维持
本文转自:http://www.cnblogs.com/cheesebar/p/6689326.html 学习过小程序的朋友应该知道,在小程序中是不支持cookie的,借助小程序中的缓存我们也可以存储 ...
- Vue-Render函数理解示例
对应文档节点: https://vuefe.cn/v2/guide/render-function.html#Slots <body> <div id="app" ...
- Newtonsoft.Json 全部配置
需要在序列化时候,忽略掉某些字段,对Newtonsoft.Json进行全局配置,如下: 1. 自定 ContractResolver public class MyContractResolver : ...
- dategrid快速录入一行数据的一波操作
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 使用 typeof 来检测对象是否undefined
需求 判断是否为undefined 解决 使用 typeof 来检测对象是否已定义: if (typeof Obj !== "undefined" && Obj ! ...