我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Redis-3.2.1 sentinel安装和配置小记

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Redis-3.2.1 sentinel安装和配置小记

环境描述:

三台机器 192.168.21.6/7/8

redis版本: redis-3.2.1


分别在三台机器上安装redis:

解压:

# tar zxvf  redis-3.2.1.tar.gz -C /usr/local


重命名:

# mv /usr/local/redis-3.2.1 /usr/local/redis


安装:

# cd /usr/local/redis

# make 

# make install


# mkdir -p /usr/local/redis/etc

# cp /usr/local/redis/redis.conf /usr/local/redis/sentinel.conf /usr/local/redis/etc


登陆192.168.21.6,修改redis.conf:

#bind 127.0.0.1

bind 0.0.0.0


登陆192.168.21.7/8,修改redis.conf:

#bind 127.0.0.1

bind 0.0.0.0

slaveof  10.10.10.11  6379


保存退出,然后在三台机器上启动redis


/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf &


登陆192.168.21.6查看redis复制状态:

# redis-cli info replication

# Replication

role:master

connected_slaves:2

slave0:ip=192.168.21.8,port=6379,state=online,offset=198371,lag=0

slave1:ip=192.168.21.7,port=6379,state=online,offset=198371,lag=1


哨兵配置:

新建目录:

# mkdir -p /usr/local/redis/db_26379

三台机器上修改/usr/local/redis/sentinel.conf,加入如下配置:


dir "/usr/local/redis/db_26379"


pidfile "/usr/local/redis/db_26379/redis_26379.pid"


loglevel notice


logfile "/usr/local/redis/db_26379/sentinel.log"


bind 0.0.0.0


:x保存退出.

备注:其他配置的地方保持不变.


然后在192.168.21.6/7/8上分别启动哨兵sentinel:

/usr/local/bin/redis-server /usr/local/redis/etc/sentinel.conf --sentinel &



然后在三台机器192.168.21.6/7/8上执行手动添加master的操作:

# redis-cli  -p 26379 sentinel monitor chenfeng 192.168.21.6 6379 2

OK



查看日志:


# tail -f /data/redis/db_26379/sentinel.log 

24177:X 20 Sep 10:06:06.563 * +sentinel sentinel 4eca392422764f3e3f4c0df7aaafc71c416c1a33 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:06:07.816 * +sentinel-invalid-addr sentinel 4eca392422764f3e3f4c0df7aaafc71c416c1a33 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:06:07.816 * +sentinel sentinel 40df350a0e705be6cbafbd83ae18ba51964f3a21 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:06:08.573 * +sentinel-address-switch master mymaster 127.0.0.1 6379 ip 127.0.0.1 port 26379 for 1ecb5a5c14cb85b33935037182fb04d107b47c82

24177:X 20 Sep 10:06:09.854 * +sentinel-address-switch master mymaster 127.0.0.1 6379 ip 127.0.0.1 port 26379 for 4eca392422764f3e3f4c0df7aaafc71c416c1a33

24177:X 20 Sep 10:06:40.396 # +monitor master chenfeng 192.168.21.6 6379 quorum 2

24177:X 20 Sep 10:06:40.446 * +slave slave 192.168.21.7:6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:06:40.447 * +slave slave 192.168.21.8:6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:06:52.383 * +sentinel sentinel 1ecb5a5c14cb85b33935037182fb04d107b47c82 192.168.21.7 26379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:06:54.482 * +sentinel sentinel 4eca392422764f3e3f4c0df7aaafc71c416c1a33 127.0.0.1 26379 @ chenfeng 192.168.21.6 6379





登陆192.168.21.6,手动模拟主库故障:


#redis-cli -p 6379 shutdown


查看日志:

# tail -f /data/redis/db_26379/sentinel.log 

24177:X 20 Sep 10:08:11.071 # +sdown master mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:11.071 # +sdown master chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.172 # +odown master mymaster 127.0.0.1 6379 #quorum 4/2

24177:X 20 Sep 10:08:11.172 # +new-epoch 1

24177:X 20 Sep 10:08:11.172 # +try-failover master mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:11.181 # +vote-for-leader 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.181 # +odown master chenfeng 192.168.21.6 6379 #quorum 3/2

24177:X 20 Sep 10:08:11.181 # +new-epoch 2

24177:X 20 Sep 10:08:11.181 # +try-failover master chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.198 # +vote-for-leader 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:11.198 # 4eca392422764f3e3f4c0df7aaafc71c416c1a33 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.198 # 4eca392422764f3e3f4c0df7aaafc71c416c1a33 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:11.198 # 40df350a0e705be6cbafbd83ae18ba51964f3a21 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.198 # 1ecb5a5c14cb85b33935037182fb04d107b47c82 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.198 # 1ecb5a5c14cb85b33935037182fb04d107b47c82 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:11.260 # +elected-leader master chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.260 # +failover-state-select-slave master chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.360 # +selected-slave slave 192.168.21.7:6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.361 * +failover-state-send-slaveof-noone slave 192.168.21.7:6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.451 * +failover-state-wait-promotion slave 192.168.21.7:6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.898 # +promoted-slave slave 192.168.21.7:6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.898 # +failover-state-reconf-slaves master chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:11.948 * +slave-reconf-sent slave 192.168.21.8:6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:12.269 # +vote-for-leader 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.270 # 4eca392422764f3e3f4c0df7aaafc71c416c1a33 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.270 # 40df350a0e705be6cbafbd83ae18ba51964f3a21 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.270 # 1ecb5a5c14cb85b33935037182fb04d107b47c82 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.353 # +elected-leader master mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:12.353 # +failover-state-select-slave master mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:12.424 # +selected-slave slave 192.168.21.7:6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:12.424 * +failover-state-send-slaveof-noone slave 192.168.21.7:6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:12.491 * +failover-state-wait-promotion slave 192.168.21.7:6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:12.916 * +slave-reconf-inprog slave 192.168.21.8:6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:12.916 * +slave-reconf-done slave 192.168.21.8:6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:13.015 # +failover-end master chenfeng 192.168.21.6 6379

24177:X 20 Sep 10:08:13.015 # +switch-master chenfeng 192.168.21.6 6379 192.168.21.7 6379

24177:X 20 Sep 10:08:13.016 * +slave slave 192.168.21.8:6379 192.168.21.8 6379 @ chenfeng 192.168.21.7 6379

24177:X 20 Sep 10:08:13.016 * +slave slave 192.168.21.6:6379 192.168.21.6 6379 @ chenfeng 192.168.21.7 6379

24177:X 20 Sep 10:08:13.297 # +promoted-slave slave 192.168.21.7:6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:13.297 # +failover-state-reconf-slaves master mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:13.352 * +slave-reconf-sent slave 192.168.21.8:6379 192.168.21.8 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:14.345 * +slave-reconf-inprog slave 192.168.21.8:6379 192.168.21.8 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:14.345 * +slave-reconf-done slave 192.168.21.8:6379 192.168.21.8 6379 @ mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:14.420 # +failover-end master mymaster 127.0.0.1 6379

24177:X 20 Sep 10:08:14.420 # +switch-master mymaster 127.0.0.1 6379 192.168.21.7 6379

24177:X 20 Sep 10:08:14.420 * +slave slave 192.168.21.8:6379 192.168.21.8 6379 @ mymaster 192.168.21.7 6379

24177:X 20 Sep 10:08:14.420 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 192.168.21.7 6379

24177:X 20 Sep 10:08:43.065 # +sdown slave 192.168.21.6:6379 192.168.21.6 6379 @ chenfeng 192.168.21.7 6379

24177:X 20 Sep 10:08:44.465 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 192.168.21.7 6379

24177:X 20 Sep 10:09:13.307 # -sdown slave 192.168.21.6:6379 192.168.21.6 6379 @ chenfeng 192.168.21.7 6379

24177:X 20 Sep 10:09:13.595 # -sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 192.168.21.7 6379

24177:X 20 Sep 10:09:23.221 * +convert-to-slave slave 192.168.21.6:6379 192.168.21.6 6379 @ chenfeng 192.168.21.7 6379

24177:X 20 Sep 10:09:25.310 * +slave slave 192.168.21.6:6379 192.168.21.6 6379 @ mymaster 192.168.21.7 6379


从以上日志里可以发现哨兵自动选举出了新的主库192.168.21.7,故障切换成功。



再次启动原主库192.168.21.6,成为了192.168.21.7的从库:

# redis-cli info replication

# Replication

role:slave

master_host:192.168.21.7

master_port:6379

master_link_status:up

master_last_io_seconds_ago:1

master_sync_in_progress:0

slave_repl_offset:25901

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


至此,哨兵模式安装和测试完毕。





免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Redis-3.2.1 sentinel安装和配置小记

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

CentOS 6.6下Redis安装配置记录

在先前的文章中介绍过redis,以下内容为自己在CentOS上安装Redis的记录。供后期在做改进。 1、安装需要的支持环境 在安装Redis之前首要先做的是安装Unix的Tcl工具,如果不安装的话后期将无法对Redis进行测试。在后期执行
2022-06-04

怎么在Ubuntu 18.04上安装和配置Redis

这篇文章主要介绍怎么在Ubuntu 18.04上安装和配置Redis,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!为什么要使用Redis?如上所述,Redis的性能和卓越功能使其比传统数据库更好。Redis的典型用法
2023-06-16

docker安装redis 5.0.7并挂载外部配置和数据

环境CentOS Linux release 7.7.1908 (Core)拉取redis 5.0.7 镜像docker pull redis:5.0.7创建挂载目录mkdir -p /home/app/redis/confmkdir -p /home/ap
docker安装redis 5.0.7并挂载外部配置和数据
2020-10-18

redis安装和配置_动力节点Java学院整理

在Ubuntu上安装Redis要安装Redis在Ubuntu上,打开终端,然后键入以下命令:$sudo apt-get update $sudo apt-get install redis-server这将在您的计算机上安装Redis。启动
2022-06-04

CentOS系统下Redis安装和自启动配置的步骤

一. 安装Redis Redis的安装其实相当简单,推荐的方式是下载redis的源码,并在本机编译后安装。 首次进入主文件夹的下载目录下,执行wget下载源码[zhxilin@localhost ~]$ cd 下载 [zhxilin@loc
2022-06-04

CentOS Linux系统下安装Redis过程和配置参数说明

安装过程:wget http://code.google.com/p/redis/downloads/detailname=redis-2.0.4.tar.gztar xvzf redis-2.0.4.tar.gzcd redis-2.0
2022-06-04

在CenOS系统下安装和配置Redis数据库的教程

一:安装rediswget http://redis.googlecode.com/files/redis-2.6.14.tar.gz tar zxvf redis-2.6.14.tar.gz cd redis-2.6.14 make PR
2022-06-04

编程热搜

目录