博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
redis 4.0.9 master slave + sentinel 实战测试
阅读量:6081 次
发布时间:2019-06-20

本文共 7766 字,大约阅读时间需要 25 分钟。

  hot3.png

1:install$ wget http://download.redis.io/releases/redis-4.0.9.tar.gz$ tar xzf redis-4.0.9.tar.gz$ cd redis-4.0.9编译构造$ make#启动服务器命令$ src/redis-server客户端连接$ src/redis-cliredis> set foo barOKredis> get foo"bar"
2设置redis服务器在后台运行并开启认证$mv redis.conf /etc/redis#找到配置文件中daemonize 并修改为yse,在后台运行daemonize yes#开启认证requirepass xxxxx#设置日志级别和日志路径loglevel debuglogfile /usr/local/redis-4.0.9/logs/redis-m.log客户端连接认证开启protected-mode yes#启动服务器$./redis-server /etc/redis/redis.conf#启动客户端$./redis-cli$auth xxxxx$set foo bar$get foo
3:redis master slave 单机模式下1>:复制redis-m.conf 文件两份2>:修改端口port 6380修改日志文件logfile /usr/local/redis-4.0.9/logs/redis-6380.log修改redis运行进程文件名字pidfile /var/run/redis_6380.pid#在slave 指定master ip port slaveof 10.25.40.235 6379#认证master时需要的密码。必须和master配置的requirepass 保持一致masterauth redispass#重新启动服务器$./redis-server /etc/redis/redis-m.conf$./redis-server /etc/redis/redis-6380.conf$./redis-server /etc/redis/redis-6381.conf#查看日志是否配置master slave 成功 Master replied to PING, replication can continue...Trying a partial resynchronization (request ad32f6080acb072dd6c4c5afc2942e4f6538948d:4052).Successful partial resynchronization with master.MASTER <-> SLAVE sync: Master accepted a Partial Resynchronization#test  master set slave getmaster 存储$./redis-cli -h 10.25.40.235 -p 6379$auth redispass$set test hello $./redis-cli -h 10.25.40.235 -p 6380$auth redispass$get test$./redis-cli -h 10.25.40.235 -p 6381$auth redispass$get test
#sentinel模式集群#设置ip地址bind 10.25.40.235#以守护进程方式运行daemonize yes#连接认证protected-mode yes#端口号port 26379#文件地址logfile /usr/local/redis-4.0.9/logs/redis-sentinel-26379.log#日志输出目录dir /usr/local/redis-4.0.9/logs/#2的含义:当开启的sentinel server认为当前master主观下线的(+sdown)数量达到2时,则sentinel server认为当前master客观下线(+odown)系统开始自动迁移。2的计算(建议):sentinel #server数量的大多数,至少为count(sentinel server)/2 向上取整。2>3/2(主观下线与客观下线)sentinel monitor mymaster 10.25.40.235 6379 2#别名和认证密码。这就提醒了用户,在master-slave系统中,各服务的认证密码应该保持一致。sentinel auth-pass mymaster redispass#:指定了Sentinel认为Redis实例已经失效所需的毫秒数。当实例超过该时间没有返回PING,或者直接返回错误,那么Sentinel将这个实例标记为主观下线。只有一个 Sentinel进程将实例标记为主观下线并不一定会引起实例的自动故障迁移:只有在足够数量的Sentinel都将一个实例标记为主观下线之后,实例才会被标记为客观下线,这时自动故障迁移才会执行sentinel down-after-milliseconds mymaster 3000#如果在该时间(ms)内未能完成failover操作,则认为该failover失败sentinel failover-timeout mymaster 18000
#启动监听服务$./redis-sentinel /etc/redis/sentinel-26379.conf $./redis-sentinel /etc/redis/sentinel-26380.conf $./redis-sentinel /etc/redis/sentinel-26381.conf
查看服务ps -ef|grep redis[root@iZ11ez4q5vcZ src]# ps -ef|grep redisroot     31949     1  0 14:14 ?        00:00:05 src/redis-server 10.25.40.235:6379      root     32080     1  0 15:14 ?        00:00:04 ./redis-server 10.25.40.235:6380         root     32085     1  0 15:14 ?        00:00:04 ./redis-server 10.25.40.235:6381         root     32158     1  0 17:46 ?        00:00:00 ./redis-sentinel 10.25.40.235:26379 [sentinel] root     32163     1  0 17:46 ?        00:00:00 ./redis-sentinel 10.25.40.235:26380 [sentinel] root     32168     1  0 17:46 ?        00:00:00 ./redis-sentinel 10.25.40.235:26381 [sentinel] root     32177 25368  0 17:49 pts/0    00:00:00 tail -f redis-sentinel-26379.logroot     32179 31993  0 17:49 pts/1    00:00:00 grep redis
查看日志[root@iZ11ez4q5vcZ logs]# cat redis-sentinel-26379.log 32157:X 04 Jun 17:46:28.771 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo32157:X 04 Jun 17:46:28.771 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=32157, just started32157:X 04 Jun 17:46:28.771 # Configuration loaded32158:X 04 Jun 17:46:28.773 * Running mode=sentinel, port=26379.32158:X 04 Jun 17:46:28.773 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.32158:X 04 Jun 17:46:28.784 # Sentinel ID is 239d80e2ff0cdb9afc5ff563c0bcc38bd182281e32158:X 04 Jun 17:46:28.785 # +monitor master mymaster 10.25.40.235 6379 quorum 232158:X 04 Jun 17:46:28.785 * +slave slave 10.25.40.235:6380 10.25.40.235 6380 @ mymaster 10.25.40.235 637932158:X 04 Jun 17:46:28.793 * +slave slave 10.25.40.235:6381 10.25.40.235 6381 @ mymaster 10.25.40.235 637932158:X 04 Jun 17:46:38.392 * +sentinel sentinel e98caa8fdab9b5841adf540ca30a093f3fcd28f1 10.25.40.235 26380 @ mymaster 10.25.40.235 637932158:X 04 Jun 17:46:41.339 * +sentinel sentinel 39b20a921cc868c4f4f4169a75568ce97970f3fc 10.25.40.235 26381 @ mymaster 10.25.40.235 6379
结束master 进程 进行测试kill - 9 31949在查看日志变化[root@iZ11ez4q5vcZ logs]# tail -f redis-sentinel-26379.log 32158:X 04 Jun 17:46:28.793 * +slave slave 10.25.40.235:6381 10.25.40.235 6381 @ mymaster 10.25.40.235 637932158:X 04 Jun 17:46:38.392 * +sentinel sentinel e98caa8fdab9b5841adf540ca30a093f3fcd28f1 10.25.40.235 26380 @ mymaster 10.25.40.235 637932158:X 04 Jun 17:46:41.339 * +sentinel sentinel 39b20a921cc868c4f4f4169a75568ce97970f3fc 10.25.40.235 26381 @ mymaster 10.25.40.235 637932190:X 04 Jun 17:54:41.536 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo32190:X 04 Jun 17:54:41.536 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=32190, just started32190:X 04 Jun 17:54:41.537 # Configuration loaded32191:X 04 Jun 17:54:41.539 * Running mode=sentinel, port=26379.32191:X 04 Jun 17:54:41.539 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.32191:X 04 Jun 17:54:41.539 # Sentinel ID is 239d80e2ff0cdb9afc5ff563c0bcc38bd182281e32191:X 04 Jun 17:54:41.539 # +monitor master mymaster 10.25.40.235 6379 quorum 232191:X 04 Jun 17:55:32.644 # +sdown master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:32.744 # +odown master mymaster 10.25.40.235 6379 #quorum 2/232191:X 04 Jun 17:55:32.745 # +new-epoch 132191:X 04 Jun 17:55:32.745 # +try-failover master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:32.753 # +vote-for-leader 239d80e2ff0cdb9afc5ff563c0bcc38bd182281e 132191:X 04 Jun 17:55:32.760 # 39b20a921cc868c4f4f4169a75568ce97970f3fc voted for 239d80e2ff0cdb9afc5ff563c0bcc38bd182281e 132191:X 04 Jun 17:55:32.760 # e98caa8fdab9b5841adf540ca30a093f3fcd28f1 voted for 239d80e2ff0cdb9afc5ff563c0bcc38bd182281e 132191:X 04 Jun 17:55:32.824 # +elected-leader master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:32.824 # +failover-state-select-slave master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:32.914 # +selected-slave slave 10.25.40.235:6380 10.25.40.235 6380 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:32.914 * +failover-state-send-slaveof-noone slave 10.25.40.235:6380 10.25.40.235 6380 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:32.997 * +failover-state-wait-promotion slave 10.25.40.235:6380 10.25.40.235 6380 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:33.797 # +promoted-slave slave 10.25.40.235:6380 10.25.40.235 6380 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:33.797 # +failover-state-reconf-slaves master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:33.849 * +slave-reconf-sent slave 10.25.40.235:6381 10.25.40.235 6381 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:34.811 * +slave-reconf-inprog slave 10.25.40.235:6381 10.25.40.235 6381 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:34.811 * +slave-reconf-done slave 10.25.40.235:6381 10.25.40.235 6381 @ mymaster 10.25.40.235 637932191:X 04 Jun 17:55:34.900 # -odown master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:34.900 # +failover-end master mymaster 10.25.40.235 637932191:X 04 Jun 17:55:34.900 # +switch-master mymaster 10.25.40.235 6379 10.25.40.235 638032191:X 04 Jun 17:55:34.901 * +slave slave 10.25.40.235:6381 10.25.40.235 6381 @ mymaster 10.25.40.235 638032191:X 04 Jun 17:55:34.901 * +slave slave 10.25.40.235:6379 10.25.40.235 6379 @ mymaster 10.25.40.235 638032191:X 04 Jun 17:55:37.959 # +sdown slave 10.25.40.235:6379 10.25.40.235 6379 @ mymaster 10.25.40.235 6380

转载于:https://my.oschina.net/cpy/blog/1824066

你可能感兴趣的文章
浅谈加密技术
查看>>
centOS7下安装GUI图形界面
查看>>
一张图透析阿里云API应用创新大赛
查看>>
sql重复行求和
查看>>
Microsoft Dynamics CRM 2013 and 2011 Update Rollups and Service Packs
查看>>
transient的理解
查看>>
python中if __name__ == '__main__': 介绍
查看>>
HackRF实现无线门铃信号分析重放
查看>>
Windows源码安装PyTorch 0.4
查看>>
AI开发者福音!阿里云推出国内首个基于英伟达NGC的GPU优化容器
查看>>
CentOS6安装和配置rsync
查看>>
在真机里安装 ubuntu 14.04和一些常用的软件(二)
查看>>
python2.6升级到2.7
查看>>
Unity SLua 如何调用Unity中C#方法
查看>>
MyBatis排序时使用order by 动态参数时需要注意,用$而不是#
查看>>
linux基础命令-查看系统状态-free -m以及top命令详解
查看>>
动态代理
查看>>
批量删除redis key
查看>>
被嫌弃的eval和with
查看>>
人工智能抢饭碗,未来怎么养活家庭?
查看>>