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. ...
随机推荐
- Docker基本命令与使用 —— Docker容器的网络连接(四)
一.Docker容器的网络基础 通过ifconfig查看docker0的网络设备,docker守护进程就是通过docker0为docker的容器提供网络连接的各种服务. docker0是Linux虚拟 ...
- JS基础——变量
引用类型:对象 数组 函数 }; var b =a ; b.age = ; console.log(a.age);// 21 传递的是地址, a,b同地址 值类型: var a =100; var ...
- 一、python基本语法元素(温度转换)
#C=(F-32)/1.8 ; F = C * 1.8 + 32 TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['f','F ...
- python使用细节
python的函数位置参数在调用时可以直接传参,也可以a=5,b=7的形式传参,原以为kw参数才可以. >>> def f(a,b): print a+b >>> ...
- epoll的LT和ET(转)
1 socket IO事件 1.1 读事件 读事件:句柄从不可读变成可读,或者句柄写缓冲区有新的数据进来且超过SO_RCVLOWAT. 常见的产生读事件有如下几种: socket有一个未清除的错误.如 ...
- 思维导图-mysql log
- pyspider--post
#!/usr/bin/env python# -*- encoding: utf-8 -*-# Created on 2018-08-19 14:47:28# Project: HBGGZY_SBJ ...
- 根据文件夹更改样本文件名小程序.py
#按照文件名设置标签并将其插入文件名中import osimport shutil#获取目标文件夹的路径a= r'C:\Users\yy\Desktop\tianchi大赛\guangdong_rou ...
- 简化Getter 与 Setter 的插件 Lombok
参考文档:https://www.jianshu.com/p/365ea41b3573 第一步:添加依赖 <dependency> <groupId>org.projectlo ...
- web服务,下载https链接的文件,提示javax.net.ssl.SSLKeyException: RSA premaster secret error
问题: 在服务器上,下载https的链接文件,报错javax.net.ssl.SSLKeyException: RSA premaster secret error 在本地运行的时候没报错,但是在 ...