redis集群简易实验

来源:互联网 发布:永诚网络 编辑:程序博客网 时间:2024/07/17 21:12

Redis官方文档
http://redis.io/documentation
http://redis.io/topics/sentinel

实验环境:rhel6.5 x86_64

Node1:192.168.122.101 sentinel
Node2:192.168.122.102 slave
Node3:192.168.122.103 master

在配置好node2和node3之后启动集群

@node1:

# cat /etc/sentinel.confport 26379logfile "/var/log/redis/sentinel.log"sentinel monitor mymaster 127.0.0.1 6379 2sentinel down-after-milliseconds mymaster 60000sentinel failover-timeout mymaster 180000sentinel parallel-syncs mymaster 1sentinel monitor resque 192.168.122.103 6379 1sentinel down-after-milliseconds resque 10000sentinel failover-timeout resque 180000sentinel parallel-syncs resque 5

启动redis集群工具

# redis-sentinel /etc/sentinel.conf

把master的服务停止后再启动,可以从log中看到,sentinel工具自动将master转到slave上。

# tailf /var/log/redis/sentinel.log [8062] 26 Feb 09:24:42.838 # +failover-state-reconf-slaves master master-7001 192.168.122.103 6379[8062] 26 Feb 09:24:42.864 # +failover-end master master-7001 192.168.122.103 6379[8062] 26 Feb 09:24:42.865 # +switch-master master-7001 192.168.122.103 6379 192.168.122.102 6379[8062] 26 Feb 09:24:42.865 * +slave slave 192.168.122.103:6379 192.168.122.103 6379 @ master-7001 192.168.122.102 6379[8062] 26 Feb 09:25:12.887 # +sdown slave 192.168.122.103:6379 192.168.122.103 6379 @ master-7001 192.168.122.102 6379[8062] 26 Feb 09:25:41.626 # -sdown slave 192.168.122.103:6379 192.168.122.103 6379 @ master-7001 192.168.122.102 6379[8062] 26 Feb 09:25:51.574 * +convert-to-slave slave 192.168.122.103:6379 192.168.122.103 6379 @ master-7001 192.168.122.102 6379[8062 | signal handler] (1424913959) Received SIGINT scheduling shutdown...[8062] 26 Feb 09:25:59.428 # User requested shutdown...[8062] 26 Feb 09:25:59.428 # Sentinel is now ready to exit, bye bye...

停止服务:

# redis-cli shutdown

查看状态:

# redis-cli -p 26379 info# Serverredis_version:2.8.19redis_git_sha1:00000000redis_git_dirty:0redis_build_id:3f558ddf573ff627redis_mode:sentinelos:Linux 2.6.32-431.el6.x86_64 x86_64arch_bits:64multiplexing_api:epollgcc_version:4.4.7process_id:8090run_id:261db3e9ddf7da7c5aa4071b236828a1cd3f41cetcp_port:26379uptime_in_seconds:38uptime_in_days:0hz:18lru_clock:15638747config_file:/root/redis-2.8.19/sentinel.conf# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0master0:name=master-7001,status=ok,address=192.168.122.102:6379,slaves=1,sentinels=1

从中可以看出master的ip地址

0 0
原创粉丝点击