https://www.jianshu.com/p/45ffd2a84143

内核配置

cat >> /etc/rc.local << EOF

echo never > /sys/kernel/mm/transparent_hugepage/enabled
EOF
cat >> /etc/sysctl.conf << EOF
vm.overcommit_memory = 1
EOF

静态解析

cat >> /etc/hosts << EOF

10.105.225.8    redis-master
10.154.146.25 redis-slave
EOF

优化

tcp-backlog 65536
timout 300
tcp-keepalive 300
maxclients 10000
maxmemory 2G
maxmemory-policy volatile-lru

配置复制

# master /etc/redis.conf

#daemonize no
daemonize yes #bind 127.0.0.1
bind 0.0.0.0 #protected-mode yes
protected-mode no #dir /var/lib/redis/
dir /opt/www/redis/ masterauth @sentinel
requirepass @sentinel
# slave /etc/redis.conf

#daemonize no
daemonize yes #bind 127.0.0.1
bind 0.0.0.0 #protected-mode yes
protected-mode no #dir /var/lib/redis/
dir /opt/www/redis/ # 从机多了slaveof配置,注意主从要匹配
slaveof redis-master 6379
masterauth @sentinel
requirepass @sentinel

启用服务

systemctl restart redis && systemctl enable redis

systemctl restart redis-sentinel && systemctl enable redis-sentinel

查看配置状态

#redis-cli -h redis-master -a @sentinel info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.154.146.25,port=6379,state=online,offset=29,lag=1
master_repl_offset:29
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:28 #redis-cli -h redis-slave -a @sentinel info replication
# Replication
role:slave
master_host:redis-master
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:15
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

配置sentinel

# 3台哨兵,2票选举

cat > /etc/redis-sentinel.conf << EOF
port 26379
protected-mode no
daemonize yes dir /tmp
sentinel monitor mymaster redis-master 6379 2
sentinel down-after-milliseconds mymaster 2000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 5000
sentinel auth-pass mymaster @sentinel logfile /var/log/redis/sentinel.log
EOF

cat > /etc/sentinel_26380.conf << EOF
port 26380
protected-mode no
daemonize yes dir /tmp
sentinel monitor mymaster redis-01-master 6379 2
sentinel down-after-milliseconds mymaster 2000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 5000
sentinel auth-pass mymaster @sentinel logfile /var/log/redis/sentinel_26380.log
EOF cat > /etc/sentinel_26381.conf << EOF
port 26381
protected-mode no
daemonize yes dir /tmp
sentinel monitor mymaster redis-02-master 6379 2
sentinel down-after-milliseconds mymaster 2000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 5000
sentinel auth-pass mymaster @sentinel logfile /var/log/redis/sentinel_26381.log
EOF cat > /etc/sentinel_26382.conf << EOF
port 26382
protected-mode no
daemonize yes dir /tmp
sentinel monitor mymaster redis-03-master 6379 2
sentinel down-after-milliseconds mymaster 2000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 5000
sentinel auth-pass mymaster @sentinel logfile /var/log/redis/sentinel_26382.log
EOF # /etc/rc.local
/usr/bin/redis-sentinel /etc/sentinel_26380.conf &
/usr/bin/redis-sentinel /etc/sentinel_26381.conf &
/usr/bin/redis-sentinel /etc/sentinel_26382.conf &

sentinel状态

#redis-cli -h redis-master -p 26379 -a @sentinel info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=redis-01,status=ok,address=10.105.225.8:6379,slaves=1,sentinels=3 #redis-cli -h redis-slave -p 26379 -a @sentinel info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master2:name=redis-01,status=ok,address=10.105.225.8:6379,slaves=1,sentinels=3

sentinel切换日志

sentinel日志
[20104] 28 Mar 17:29:54.042 # +sdown master mymaster 10.105.225.8 6379
[20104] 28 Mar 17:29:54.104 # +odown master mymaster 10.105.225.8 6379 #quorum 2/2
[20104] 28 Mar 17:29:54.104 # +new-epoch 1
[20104] 28 Mar 17:29:54.104 # +try-failover master mymaster 10.105.225.8 6379
[20104] 28 Mar 17:29:54.169 # +vote-for-leader 016236a44f1376e34b8e6696c1b7eb0d8ebc3e59 1
[20104] 28 Mar 17:29:54.169 # 10.154.146.25:26379 voted for b9d0dc3e20c5c138304419a17f572e56be61a3fd 1
[20104] 28 Mar 17:29:54.169 # 10.154.43.8:26379 voted for 27c052e9e9b3ad99edc6fe85f5566157e9865309 1
[20104] 28 Mar 17:29:54.169 # 10.154.162.125:26379 voted for b9d0dc3e20c5c138304419a17f572e56be61a3fd 1
[20104] 28 Mar 17:29:54.189 # 10.154.160.30:26379 voted for b9d0dc3e20c5c138304419a17f572e56be61a3fd 1
[20104] 28 Mar 17:29:54.195 # 10.105.93.170:26379 voted for 1823e7153adb3b302a6c05e2a79ce508217e5b9f 1
[20104] 28 Mar 17:30:04.361 # -failover-abort-not-elected master redis-01 10.105.225.8 6379
[20104] 28 Mar 17:30:04.416 # Next failover delay: I will not start a failover before Wed Mar 28 17:35:54 2018
[20104] 28 Mar 17:35:54.336 # +new-epoch 2
[20104] 28 Mar 17:35:54.341 # +vote-for-leader b9d0dc3e20c5c138304419a17f572e56be61a3fd 2
[20104] 28 Mar 17:35:54.341 # Next failover delay: I will not start a failover before Wed Mar 28 17:41:54 2018
[20104] 28 Mar 17:35:54.728 # +config-update-from sentinel 10.154.162.125:26379 10.154.162.125 26379 @ redis-01 10.105.225.8 6379
[20104] 28 Mar 17:35:54.728 # +switch-master redis-01 10.105.225.8 6379 10.154.146.25 6379
[20104] 28 Mar 17:35:54.728 * +slave slave 10.105.225.8:6379 10.105.225.8 6379 @ redis-01 10.154.146.25 6379
[20104] 28 Mar 17:36:24.754 # +sdown slave 10.105.225.8:6379 10.105.225.8 6379 @ redis-01 10.154.146.25 6379

redis复制集(sentinel)的更多相关文章

  1. Redis 复制、Sentinel的搭建和原理说明(转)

    Redis 复制.Sentinel的搭建和原理说明  转自:http://www.cnblogs.com/zhoujinyi/p/5570024.html. 背景: Redis-Sentinel是Re ...

  2. Redis 复制、Sentinel的搭建和原理说明

    背景: Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端) ...

  3. redis复制集

    应用场景:复制集作用的场景问题: 1.解决单点故障 2.读写分离 1.准备两台redis服务器 a) 一台做为注服务器,一台做为从服务器 b) 在从服务器中的redis.conf文件中添加 repli ...

  4. Redis高可用复制集群实现

    redis简单介绍 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库.Redis 与其他 key - value 缓存产品有以下三个特点: 支持数据的持久化,可以将 ...

  5. 02.Redis主从集群的Sentinel配置

    1.集群环境 1.Linux服务器列表 使用4台CentOS Linux服务器搭建环境,其IP地址如下: 192.168.110.100 192.168.110.101 192.168.110.102 ...

  6. Redis复制与可扩展集群搭建

    抄自:http://www.infoq.com/cn/articles/tq-redis-copy-build-scalable-cluster 讨论了Redis的常用数据类型与存储机制,本文会讨论一 ...

  7. (转)Redis复制与可扩展集群搭建

    讨论了Redis的常用数据类型与存储机制,本文会讨论一下Redis的复制功能以及Redis复制机制本身的优缺点以及集群搭建问题. Redis复制流程概述 Redis的复制功能是完全建立在之前我们讨论过 ...

  8. Redis复制与可扩展集群搭建【转】

    本文会讨论一下Redis的复制功能以及Redis复制机制本身的优缺点以及集群搭建问题. Redis复制流程概述 Redis的复制功能是完全建立在之前我们讨论过的基于内存快照的持久化策略基础上的,也就是 ...

  9. Redis的集群方案之Sentinel(哨兵模式)(待实践)

    哨兵模式是主从切换的一种方案,但是可以借助此方案实现集群,达到高可用. 先收集教程,待实践. 参考: https://redis.io/topics/sentinel(官方文档) http://ife ...

随机推荐

  1. ubuntu下安装和更新R语言

    R官网更新说明 https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/linux/ubuntu/README.html 本文主要讲解在ubuntu下如何安装和更新 ...

  2. 【算法笔记】B1027 打印沙漏

    1027 打印沙漏 (20 分) 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇 ...

  3. HDU - 1427 / UESTC - 1252 经典dfs

    很好奇为什么hzwer那种稍改一下还是无法过样例,代码我没看出问题 换了一种用桶组合挑取两个数不断回溯的做法 这是HDU1427的代码,后者改一改就行了 #include<bits/stdc++ ...

  4. JOB&paper

    我突然想到,不管我最终有没有获得一份可观的工作,但是每个公司都最终会收到我的一份简历 (3)熟悉面向对象编程: (4)熟悉TCP/IP, Http等网络协议和网络编程:   2.熟练掌握MFC.STL ...

  5. Win10安装MySQL5.7.22解压缩版的方法及手动配置讲解

    1.先去MYSQL官网下载安装包,解压放到C盘 2.新建一个my.ini文件放到bin文件夹下面,内容如下,路径对应自己的安装目录: [mysql] # 设置mysql客户端默认字符集 default ...

  6. 从fis中得来的数据结构,Object版,

    /* * config * caoke */ 'use strict'; //You can't use merge in util.js function merge(source, target) ...

  7. Flask项目出现html文件无法自动补全

    默认情况下我们使用Pycharm专业版创建一个Flask项目时就会自动创建一个简单的项目结构,Pycharm会自动关联起文件的语法,模版等.而自己手动创建的文件并没有关联起来.这就会出现上面说的无法补 ...

  8. PIE SDK矢量数据编辑事件的监听

    1.功能简介 通过IEditEvents接口,开发者可以监听到Editor对象的相关的事件,并且做出反应.包括Editor中开始编辑.结束编辑等操作,下面对矢量数据的编辑事件的监听功能进行介绍. 2. ...

  9. linux + eclipse C语言 开发环境搭建

    经常与linux系统打交道,了解学习一下C语言,下载eclipse c/c++ linux版,直接在虚拟机linux系统上安装http://www.eclipse.org/downloads/pack ...

  10. @font-face引用指定字体库(一)

    创建 文件夹 font 存放指定字体库 在css文件中使用字体库: html, body{ font-family: "Microsoft YaHei",Arial,Helveti ...