docker-compose安装redis-sentinel集群(1主+2副+2哨兵)
前提:本试验环境已经提前安装了docker和docker-compose
说明:本次部署是单机伪集群,想要部署真正的集群,需要将秒个主件拆分到各个机器上去部署,只修改ip地址
1、下载redis的相关镜像
本人已经将做好的redis镜像放到阿里云的仓库了,要下载,直接执行下面的命令即可
docker pull registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis-sentinel:
docker pull registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:
2、创建redis的data目录,主要是为了持久化保存redis的数据
mkdir -p /home/redis-sentinel-cluster/data/master
mkdir -p /home/redis-sentinel-cluster/data/slave1
mkdir -p /home/redis-sentinel-cluster/data/slave2
mkdir -p /home/redis-sentinel-cluster/data/sentinel-
mkdir -p /home/redis-sentinel-cluster/data/sentinel-
3、创建2个哨兵的配置文件 (集群启动后会自动更新该配置文件 )
/home/redis-sentinel-cluster/sentinel-1.conf
port dir "/data"
sentinel monitor mymaster 172.16.1.11
sentinel down-after-milliseconds mymaster
sentinel failover-timeout mymaster
sentinel parallel-syncs mymaster 1
/home/redis-sentinel-cluster/sentinel-2.conf
port dir "/data"
sentinel monitor mymaster 172.16.1.11
sentinel down-after-milliseconds mymaster
sentinel failover-timeout mymaster
sentinel parallel-syncs mymaster
1)monitor 指的是初始化的监控主切点,ip和端口,后面的数字2代表,必须2个sentinel才能判断主节点是否失败
2)down-after-milliseconds 指的是超过5000秒,且没有回复,则判定主节点不可达
3)failover-timeout 指的是故障转移时间
4)parallel-syncs 指的是故障转移到新的主节点时,从节点的复制节点数量
4、创建 /home/redis-sentinel-cluster/docker-compose.yml
version: '2.1'
services:
master:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:
container_name: master
restart: always
network_mode: "host"
volumes:
- ./data/master:/data
command: redis-server --port
slave1:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:
container_name: slave1
restart: always
network_mode: "host"
volumes:
- ./data/slave1:/data
command: redis-server --port --slaveof 172.16.1.11
slave2:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:
container_name: slave2
restart: always
network_mode: "host"
volumes:
- ./data/slave2:/data
command: redis-server --port --slaveof 172.16.1.11
sentinel-:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis-sentinel:
container_name: sentinel-
restart: always
network_mode: "host"
volumes:
- ./sentinel-.conf:/etc/redis/sentinel.conf
- ./data/sentinel-:/data
sentinel-:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis-sentinel:
container_name: sentinel-
restart: always
network_mode: "host"
volumes:
- ./sentinel-.conf:/etc/redis/sentinel.conf
- ./data/sentinel-:/data
5、启动redis集群
cd /home/redis-sentinel-cluster
docker-compose up -d
6、验证集群
1)连接基本一个sentinel
docker exec -it sentinel- redis-cli -h 172.16.1.11 -p
2) 查看基本信息
172.16.1.11:> info
# Server
redis_version:3.2.
redis_git_sha1:
redis_git_dirty:
redis_build_id:b0df607ad3315254
redis_mode:sentinel
os:Linux 3.10.-.el7.x86_64 x86_64
arch_bits:
multiplexing_api:epoll
gcc_version:6.3.
process_id:
run_id:ff490c3e11d3b9f8c4ca6fd2456c4d2cffa20bdc
tcp_port:
uptime_in_seconds:
uptime_in_days:
hz:
lru_clock:
executable:/data/redis-server
config_file:/etc/redis/sentinel.conf # Clients
connected_clients:
client_longest_output_list:
client_biggest_input_buf:
blocked_clients: # CPU
used_cpu_sys:4.11
used_cpu_user:3.45
used_cpu_sys_children:0.01
used_cpu_user_children:0.00 # Stats
total_connections_received:
total_commands_processed:
instantaneous_ops_per_sec:
total_net_input_bytes:
total_net_output_bytes:
instantaneous_input_kbps:0.13
instantaneous_output_kbps:0.01
rejected_connections:
sync_full:
sync_partial_ok:
sync_partial_err:
expired_keys:
evicted_keys:
keyspace_hits:
keyspace_misses:
pubsub_channels:
pubsub_patterns:
latest_fork_usec:
migrate_cached_sockets: # Sentinel
sentinel_masters:
sentinel_tilt:
sentinel_running_scripts:
sentinel_scripts_queue_length:
sentinel_simulate_failure_flags:
master0:name=mymaster,status=ok,address=172.16.1.11:16379,slaves=2,sentinels=2
3)相看master
172.16.1.11:> sentinel masters
) ) "name"
) "mymaster"
) "ip"
) "172.16.1.11"
) "port"
) "16379"
) "runid"
) "657bd7c958c8a2267efd5d0148eac74db6dac780"
) "flags"
) "master"
) "link-pending-commands"
) "0"
) "link-refcount"
) "1"
) "last-ping-sent"
) "0"
) "last-ok-ping-reply"
) "1025"
) "last-ping-reply"
) "1025"
) "down-after-milliseconds"
) "5000"
) "info-refresh"
) "4163"
) "role-reported"
) "master"
) "role-reported-time"
) "4209375"
) "config-epoch"
) "0"
) "num-slaves"
) "2"
) "num-other-sentinels"
) "1"
) "quorum"
) "2"
) "failover-timeout"
) "5000"
) "parallel-syncs"
) "1"
4)查看slaves
172.16.1.11:> sentinel slaves mymaster
) ) "name"
) "172.16.1.11:16380"
) "ip"
) "172.16.1.11"
) "port"
) "16380"
) "runid"
) "07c0f9d673db676594da6ec38f12d9e7bbea32b2"
) "flags"
) "slave"
) "link-pending-commands"
) "0"
) "link-refcount"
) "1"
) "last-ping-sent"
) "0"
) "last-ok-ping-reply"
) "759"
) "last-ping-reply"
) "759"
) "down-after-milliseconds"
) "5000"
) "info-refresh"
) "4278"
) "role-reported"
) "slave"
) "role-reported-time"
) "4319936"
) "master-link-down-time"
) "0"
) "master-link-status"
) "ok"
) "master-host"
) "172.16.1.11"
) "master-port"
) "16379"
) "slave-priority"
) "100"
) "slave-repl-offset"
) "584317"
) ) "name"
) "172.16.1.11:16381"
) "ip"
) "172.16.1.11"
) "port"
) "16381"
) "runid"
) "6a1038dc76a386fe4137fe22f1dca7286f0774c6"
) "flags"
) "slave"
) "link-pending-commands"
) "0"
) "link-refcount"
) "1"
) "last-ping-sent"
) "0"
) "last-ok-ping-reply"
) "759"
) "last-ping-reply"
) "759"
) "down-after-milliseconds"
) "5000"
) "info-refresh"
) "4278"
) "role-reported"
) "slave"
) "role-reported-time"
) "4319936"
) "master-link-down-time"
) "0"
) "master-link-status"
) "ok"
) "master-host"
) "172.16.1.11"
) "master-port"
) "16379"
) "slave-priority"
) "100"
) "slave-repl-offset"
) "584317"
5)连接master,并存入一个key和value
[root@localhost redis-sentinel-cluster]# docker exec -it master redis-cli -h 172.16.1.11 -p 16379
172.16.1.11:> set boshen_name boshenboshen
OK
6)连接slave1,获取boshen_name的值
[root@localhost redis-sentinel-cluster]#
[root@localhost redis-sentinel-cluster]# docker exec -it slave1 redis-cli -h 172.16.1.11 -p 16380
172.16.1.11:> get boshen_name
"boshenboshen"
172.16.1.11:>
由报错可知,从节点,不能写数据
7) 停掉master容器,查看是否能切换主节点
由以上结果可知:master节点迁移到了slave1上
docker-compose安装redis-sentinel集群(1主+2副+2哨兵)的更多相关文章
- Docker Compose 搭建 Redis Cluster 集群环境
在前文<Docker 搭建 Redis Cluster 集群环境>中我已经教过大家如何搭建了,本文使用 Docker Compose 再带大家搭建一遍,其目的主要是为了让大家感受 Dock ...
- helm安装redis+Sentinel集群搭建
一.redis集群特点 数据 在多个Redis节点之间自动分片 sentinel特点: 它的主要功能有以下几点 不时地监控redis是否按照预期良好地运行; 如果发现某个redis节点运行出现状况,能 ...
- Redis Sentinel 集群安装 step by step
一. 准备材料 服务器 IP address 操作系统 位数 Redis 版本 CNT06CAH05 192.168.3.47 CentOS 6.5 x64 Redis-3.2.6 sentine ...
- redis sentinel集群的搭建
背景说明: 这里采用1主2从的redis集群,3个sentinel搭建高可用redis集群. 一,关于搭建redis-sentinel高可用之前,我们必须要了解redis主从搭建redis-senti ...
- docker1.12 安装redis第三方集群方案 codis
docker1.12 安装redis第三方集群方案 codis
- redis sentinel 集群监控 配置
环境: ip 172.16.1.31 26379 redis sentinel ip 172.16.1.30 6379 主 1 ip 172.16.1.31 6380 从 1 ip ...
- CentOS7 安装Redis Cluster集群
上一篇中已经讲到了如何安装单击版Redis,这一篇我们来说下如何安装Cluster,关于哨兵模式这里我就不写文章安装了,有兴趣的同学可以自己去研究,哨兵模式可以在主从模式下在创建三台机器的哨兵集群监控 ...
- Redis Sentinel集群双机房容灾实施步骤
概要目标防止双机房情况下任一个机房完全无法提供服务时如何让Redis继续提供服务.架构设计A.B两机房,其中A机房有一Master一Slave和两个Sentinel,B机房只有2个Sentinel,如 ...
- Centos6 安装 Redis 和集群配置
Redis安装 先确认gcc和tcl已经安装 sudo yum install gcc-c++ sudo yum install tcl 解压, 编译和安装 .tar.gz /usr/src/ cd ...
- docker下创建redis cluster集群
概述 在Redis中,集群的解决方案有三种 主从复制 哨兵机制 Cluster Redis Cluster是Redis的分布式解决方案,在 3.0 版本正式推出. 准备工作 1.确定本机IP地址 2. ...
随机推荐
- 1816647 - Error "Data file of SAP Note is incomplete" uploading a note in SNOTE
ymptom When uploading an SAP Note in transaction SNOTE you receive the error "Data file of SAP ...
- pandas 存取数据小笔记
import pandas as pd 1. 读取和保存 csv文件 #读 df = pd.read_csv(read_file_path, header=0) # 其中read_file_pat ...
- 在VMware中为Redhat HAT配置本地yum源
在VMware中为Redhat HAT配置本地yum源 今天准备使用CM安装大数据环境,到需要几台机器都使用同一套yum源才可以,所以想到将Redhat镜像文件拷贝到虚拟机中,在挂起使用,最后通过ht ...
- VMware 2017 v14.x 永久许可证激活密钥
FF31K-AHZD1-H8ETZ-8WWEZ-WUUVA CV7T2-6WY5Q-48EWP-ZXY7X-QGUWD
- 子页面调整父亲页面的iframe元素
$('iframe', parent.document).attr('scrolling','no');
- leetcode76
class Solution: def minWindow(self, s: str, t: str) -> str: n = len(s) if n==0: return "&quo ...
- OKHttp使用详解
一,OKHttp介绍 okhttp是一个第三方类库,用于android中请求网络. 这是一个开源项目,是安卓端最火热的轻量级框架,由移动支付Square公司贡献(该公司还贡献了Picasso和Leak ...
- cmd与linux使用curl差异
其中在用windows下的cmd 进行curl命令,出现415报错,见下,请求头使用json形式,但报错却依然提示使用的是form表单形式: 一直以为问题出在springboot的转换器做string ...
- swift 监测内存泄漏 MLeaksFinder
使用MLeaksFinder检测项目内存泄露总结 https://www.cnblogs.com/ocarol/p/5288497.html
- 定时执行自动化脚本-(二)ant发送邮件及邮件中添加附件
发送邮件及邮件添加附件均需要用java来实现 1.idea创建一个maven的java项目,目录结构如下 2.pom.xml文件添加依赖的javax.mail <dependencies> ...