使用redis-sentinel实现redis的主从快速切换

一、redis入门

1.1redis简介

  Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由VMware主持。
  Redis能运行在大多数POSIX(Linux, *BSD, OS X 和Solaris等)系统上,官方没有支持Windows的版本。目前最新的版本是2.2.11,这个版本主要是修复了一个2.2.7版本中遍历方式优化带来的一个bug。
  和普通的Key-Value结构不同,Redis的Key支持灵活的数据结构,除了strings,还有hashes、lists、 sets 和sorted sets等结构。正是这些灵活的数据结构,丰富了Redis的应用场景,能满足更多业务上的灵活存储需求。
  Redis的数据都保存在内存中,而且底层实现上是自己写了epoll event loop部分,而没有采用开源的libevent等通用框架,所以读写效率很高。为了实现数据的持久化,Redis支持定期刷新(可通过配置实现)或写日志的方式来保存数据到磁盘。

1.2redis支持的数据类型

  作为Key-value型数据库,Redis也提供了键(Key)和键值(Value)的映射关系。但是,除了常规的数值或字符串,Redis的键值还可以是以下形式之一:
  ●Lists (列表)
  ●Sets (集合)
  ●Sorted sets (有序集合)
  ●Hashes (哈希表)
  键值的数据类型决定了该键值支持的操作。Redis支持诸如列表、集合或有序集合的交集、并集、查集等高级原子操作;同时,如果键值的类型是普通数字,Redis则提供自增等原子操作。

1.3持久化

Redis 提供了多种不同级别的持久化方式

  • RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照(point-in-time snapshot)。
  • AOF 持久化记录服务器执行的所有写操作命令,并在服务器启动时,通过重新执行这些命令来还原数据集。 AOF 文件中的命令全部以 Redis 协议的格式来保存,新命令会被追加到文件的末尾。 Redis 还可以在后台对 AOF 文件进行重写(rewrite),使得 AOF 文件的体积不会超出保存数据集状态所需的实际大小。
  • Redis 还可以同时使用 AOF 持久化和 RDB 持久化。 在这种情况下, 当 Redis 重启时, 它会优先使用 AOF 文件来还原数据集, 因为 AOF 文件保存的数据集通常比 RDB 文件所保存的数据集更完整。
  • 你甚至可以关闭持久化功能,让数据只在服务器运行时存在。详情请移步redis持久化

1.5主从复制

  为了使得集群在一部分节点下线或者无法与集群的大多数(majority)节点进行通讯的情况下, 仍然可以正常运作, Redis 集群对节点使用了主从复制功能: 集群中的每个节点都有 1 个至 N 个复制品(replica), 其中一个复制品为主节点(master), 而其余的 N-1 个复制品为从节点(slave)。
  在之前列举的节点 A 、B 、C 的例子中, 如果节点 B 下线了, 那么集群将无法正常运行, 因为集群找不到节点来处理 5501 号至 11000 号的哈希槽。另一方面, 假如在创建集群的时候(或者至少在节点 B 下线之前), 我们为主节点 B 添加了从节点 B1 , 那么当主节点 B 下线的时候, 集群就会将 B1 设置为新的主节点, 并让它代替下线的主节点 B , 继续处理 5501 号至 11000 号的哈希槽, 这样集群就不会因为主节点 B 的下线而无法正常运作了。
  不过如果节点 B 和 B1 都下线的话, Redis 集群还是会停止运作。详情请移步redis主从复制

1.6redis集群

Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施(installation)。
Redis 集群不支持那些需要同时处理多个键的 Redis 命令, 因为执行这些命令需要在多个 Redis 节点之间移动数据, 并且在高负载的情况下, 这些命令将降低 Redis 集群的性能, 并导致不可预测的行为。
Redis 集群通过分区(partition)来提供一定程度的可用性(availability): 即使集群中有一部分节点失效或者无法进行通讯, 集群也可以继续处理命令请求。
Redis 集群提供了以下两个好处:

  • 将数据自动切分(split)到多个节点的能力。
  • 当集群中的一部分节点失效或者无法进行通讯时, 仍然可以继续处理命令请求的能力,详情请移步redis集群

二、redis sentinel详细讲解

请移步redis-sentinel

三、环境准备

四、使用saltstack快速部署redis主从复制

salt-master的redis应用目录结构

  1. [root@salt-master devops_redis]# tree
  2. .
  3. ├── files
  4. ├── redis
  5. └── redis-3.0.7.tar.gz
  6. └── install.sls

查看文件install.sls

  1. [root@salt-master devops_redis]# cat install.sls
  2. redis-install:
  3. file.managed:
  4. - name: /usr/local/src/redis-3.0.7.tar.gz
  5. - source: salt://devops_redis/files/redis-3.0.7.tar.gz
  6. - user: root
  7. - group: root
  8. - mode: 644
  9. - backup: minion
  10. cmd.run:
  11. - name: cd /usr/local/src/ && tar xf redis-3.0.7.tar.gz && cd redis-3.0.7 && make && make install && cd /usr/local/src/ && mv redis-3.0.7/ /usr/local/ && ln -sf /usr/local/redis-3.0.7/ /usr/local/redis && cp /usr/local/redis/src/redis-server /usr/local/bin/ && cp /usr/local/redis/src/redis-cli /usr/local/bin/
  12. - unless: test -d /usr/local/redis-3.0.7
  13. - require:
  14. - file: redis-install
  15. vm.overcommit_memory:
  16. sysctl.present:
  17. - value: 1
  18. redis-conf-dir:
  19. file.directory:
  20. - name: /etc/redis
  21. - user: root
  22. - group: root
  23. - mode: 755
  24. redis-init:
  25. file.managed:
  26. - name: /etc/init.d/redis
  27. - source: salt://devops_redis/files/redis
  28. - user: root
  29. - group: root
  30. - mode: 755
  31. - backup: minion
  32. - require:
  33. - cmd: redis-install

查看redis的启动文件

  1. [root@salt-master devops_redis]# cat files/redis
  2. #!/bin/bash
  3. #
  4. # Init file for redis
  5. #
  6. # chkconfig: - 80 12
  7. # description: redis daemon
  8. #
  9. # processname: redis
  10. # config: /etc/redis.conf
  11. # pidfile: /var/run/redis.pid
  12. source /etc/init.d/functions
  13. BIN="/usr/local/bin"
  14. CONFIG="/etc/redis/redis.conf"
  15. PIDFILE="/var/run/redis.pid"
  16. ### Read configuration
  17. [ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
  18. RETVAL=0
  19. prog="redis-server"
  20. desc="Redis Server"
  21. start() {
  22. if [ -e $PIDFILE ];then
  23. echo "$desc already running...."
  24. exit 1
  25. fi
  26. echo -n $"Starting $desc: "
  27. daemon $BIN/$prog $CONFIG
  28. RETVAL=$?
  29. echo
  30. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
  31. return $RETVAL
  32. }
  33. stop() {
  34. echo -n $"Stop $desc: "
  35. killproc $prog
  36. RETVAL=$?
  37. echo
  38. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
  39. return $RETVAL
  40. }
  41. restart() {
  42. stop
  43. sleep 2
  44. start
  45. }
  46. case "$1" in
  47. start)
  48. start
  49. ;;
  50. stop)
  51. stop
  52. ;;
  53. restart)
  54. restart
  55. ;;
  56. condrestart)
  57. [ -e /var/lock/subsys/$prog ] && restart
  58. RETVAL=$?
  59. ;;
  60. status)
  61. status $prog
  62. RETVAL=$?
  63. ;;
  64. *)
  65. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  66. RETVAL=1
  67. esac
  68. exit $RETVAL

查看redis-master的配置sls

  1. [root@salt-master devops_redis]# cat redis-master-conf.sls
  2. include:
  3. - devops_redis.install
  4. redis-master-conf:
  5. file.managed:
  6. - name: /etc/redis/redis.conf
  7. - source: salt://cluster/devops_redis/files/redis-master.conf
  8. - user: root
  9. - group: root
  10. - mode: 644
  11. - backup: minion
  12. - template: jinja
  13. - require_in:
  14. - cmd: redis-init
  15. - require:
  16. - file: redis-conf-dir
  17. cmd.run:
  18. - name: mkdir /var/log/redis && touch /var/log/redis/redis.log
  19. - unless:
  20. - test -d /var/log/redis
  21. service.running:
  22. - name: redis
  23. - enable: True
  24. - restart: True
  25. - watch:
  26. - file: redis-master-conf

查看redis-conf的配置文件目录结构

  1. [root@salt-master devops_redis]# tree
  2. .
  3. ├── files
  4. ├── redis-master.conf
  5. └── redis-slave.conf
  6. ├── redis-master-conf.sls
  7. └── redis-slave-conf.sls
  8. 1 directory, 4 files

查看redis-slave的配置sls

  1. [root@salt-master devops_redis]# cat redis-slave-conf.sls
  2. include:
  3. - devops_redis.install
  4. redis-slave-conf:
  5. file.managed:
  6. - name: /etc/redis/redis.conf
  7. - source: salt://cluster/devops_redis/files/redis-slave.conf
  8. - user: root
  9. - group: root
  10. - mode: 644
  11. - backup: minion
  12. - template: jinja
  13. - require_in:
  14. - cmd: redis-init
  15. - require:
  16. - file: redis-conf-dir
  17. cmd.run:
  18. - name: mkdir /var/log/redis && touch /var/log/redis/redis.log
  19. - unless:
  20. - test -d /var/log/redis
  21. service.running:
  22. - name: redis
  23. - enable: True
  24. - restart: True
  25. - watch:
  26. - file: redis-slave-conf

执行高级状态完成对主从的自动化安装

  1. [root@salt-master devops_redis]#salt -L 'redis-3,redis-4' state.highstate

查看master和slave的启动状态

  • master
  1. [root@redis-3 ~]# ps -ef|grep redis|grep -v grep
  2. root 20274 1 0 01:40 ? 00:00:12 /usr/local/bin/redis-server 10.0.0.4:6379
  3. [root@redis-3 ~]# netstat -lntup|grep 6379
  4. tcp 0 0 10.0.0.4:6379 0.0.0.0:* LISTEN 20274/redis-server
  • slave
  1. [root@redis-4 ~]# ps -ef|grep redis|grep -v grep
  2. root 20274 1 0 01:40 ? 00:00:12 /usr/local/bin/redis-server 10.0.0.4:6379
  3. [root@redis-4 ~]# netstat -lntup|grep 6379
  4. tcp 0 0 10.0.0.4:6379 0.0.0.0:* LISTEN 20274/redis-server

五、使用saltstack快速部署redis-sentinel

salt-master的redis-sentinel应用目录结构

  1. [root@salt-master devops_redis_sentinel]# tree
  2. ├── files
  3. └── redis-3.0.7.tar.gz
  4. └── install.sls
  5. 1 directory, 2 files

查看文件install.sls

  1. [root@salt-master devops_redis_sentinel]# cat install.sls
  2. redis-sentinel-install:
  3. file.managed:
  4. - name: /usr/local/src/redis-3.0.7.tar.gz
  5. - source: salt://devops_redis_sentinel/files/redis-3.0.7.tar.gz
  6. - user: root
  7. - group: root
  8. - mode: 644
  9. - backup: minion
  10. cmd.run:
  11. - name: cd /usr/local/src/ && tar xf redis-3.0.7.tar.gz && cd redis-3.0.7 && make && make install && cd /usr/local/src/ && mv redis-3.0.7/ /usr/local/ && ln -sf /usr/local/redis-3.0.7/ /usr/local/redis && cp /usr/local/redis/src/redis-server /usr/local/bin/ && cp /usr/local/redis/src/redis-cli /usr/local/bin/ && cp /usr/local/redis/src/redis-sentinel /usr/local/bin/
  12. - unless: test -d /usr/local/redis
  13. - require:
  14. - file: redis-sentinel-install
  15. redis-sentinel-conf-dir:
  16. file.directory:
  17. - name: /etc/redis-sentinel
  18. - user: root
  19. - group: root
  20. - mode: 755
  21. - require:
  22. - file: redis-sentinel-install

查看salt-master上redis-sentinel配置文件目录结构

  1. [root@salt-master devops_redis_sentinel]# tree
  2. .
  3. ├── files
  4. └── redis_sentinel.conf
  5. └── redis-sentinel-conf.sls
  6. 1 directory, 4 files

查看sentinel配置文件

  1. [root@salt-master devops_redis_sentinel]# cat files/redis-sentinel.conf
  2. ##sentinel for 10.0.0.3 ,its slave is 10.0.0.4
  3. #master1
  4. port 26379
  5. sentinel monitor master1 10.0.0.3 6379 2 #指定master的ip地址
  6. sentinel down-after-milliseconds master1 30000
  7. sentinel failover-timeout master1 900000
  8. sentinel parallel-syncs master1 1

查看redis-sentinel-conf.sls

  1. [root@salt-master devops_redis_sentinel]# cat redis-sentinel-conf.sls
  2. include:
  3. - devops_redis_sentinel.install
  4. redis-sentinel-conf:
  5. file.managed:
  6. - name: /etc/redis-sentinel/redis-sentinel.conf
  7. - source: salt://cluster/devops_redis_sentinel/files/redis-sentinel.conf
  8. - user: root
  9. - group: root
  10. - mode: 644
  11. - backup: minion
  12. - require:
  13. - file: redis-sentinel-conf-dir

执行高级状态完成对主从的自动化安装

  1. [root@salt-master devops_redis]#salt -L 'redis-5,redis-6,redis-7' state.highstate

启动三台redis-sentinel

  1. [root@redis-5 redis-sentinel]# /usr/local/bin/redis-server /etc/redis-sentinel/redis-sentinel.conf --sentinel &
  2. [root@redis-6 redis-sentinel]# /usr/local/bin/redis-server /etc/redis-sentinel/redis-sentinel.conf --sentinel &
  3. [root@redis-7 redis-sentinel]# /usr/local/bin/redis-server /etc/redis-sentinel/redis-sentinel.conf --sentinel &

查看进程和端口占用情况

  1. [root@redis-5 redis-sentinel]# ps -fe|grep redis|grep -v grep
  2. root 23867 1 0 09:27 ? 00:00:17 /usr/local/bin/redis-server *:26379 [sentinel]
  3. [root@redis-5 redis-sentinel]# netstat -lntup|grep 26379
  4. tcp 0 0 0.0.0.0:26379 0.0.0.0:* LISTEN 23867/redis-server
  5. [root@redis-6 redis-sentinel]# ps -fe|grep redis|grep -v grep
  6. root 23867 1 0 09:27 ? 00:00:17 /usr/local/bin/redis-server *:26379 [sentinel]
  7. [root@redis-6 redis-sentinel]# netstat -lntup|grep 26379
  8. tcp 0 0 0.0.0.0:26379 0.0.0.0:* LISTEN 23867/redis-server
  9. [root@redis-7 redis-sentinel]# ps -fe|grep redis|grep -v grep
  10. root 23867 1 0 09:27 ? 00:00:17 /usr/local/bin/redis-server *:26379 [sentinel]
  11. [root@redis-7 redis-sentinel]# netstat -lntup|grep 26379
  12. tcp 0 0 0.0.0.0:26379 0.0.0.0:* LISTEN 23867/redis-server

六、测试redis主从切换

手动关闭10.0.0.3上的redis-master

  1. [root@redis-3 ~]# /etc/init.d/redis stop
  2. Stop Redis Server: [ OK ]

查看10.0.0.4的info状态

  1. [root@redis-4 ~]# redis-cli -h 10.0.0.4 -p 6379
  2. 10.0.0.4:6379> info
  3. # Server
  4. redis_version:3.0.7
  5. redis_git_sha1:00000000
  6. redis_git_dirty:0
  7. redis_build_id:660d4263a6943aef
  8. redis_mode:standalone
  9. os:Linux 2.6.32-573.el6.x86_64 x86_64
  10. arch_bits:64
  11. multiplexing_api:epoll
  12. gcc_version:4.4.7
  13. process_id:20274
  14. run_id:87dbdb3120a4070d5d0666ae2976d3aaeb65fc38
  15. tcp_port:6379
  16. uptime_in_seconds:17593
  17. uptime_in_days:0
  18. hz:10
  19. lru_clock:11769033
  20. config_file:/etc/redis/redis.conf
  21. # Clients
  22. connected_clients:7
  23. client_longest_output_list:0
  24. client_biggest_input_buf:0
  25. blocked_clients:0
  26. # Memory
  27. used_memory:1072616
  28. used_memory_human:1.02M
  29. used_memory_rss:9211904
  30. used_memory_peak:1109472
  31. used_memory_peak_human:1.06M
  32. used_memory_lua:36864
  33. mem_fragmentation_ratio:8.59
  34. mem_allocator:jemalloc-3.6.0
  35. # Persistence
  36. loading:0
  37. rdb_changes_since_last_save:0
  38. rdb_bgsave_in_progress:0
  39. rdb_last_save_time:1471370133
  40. rdb_last_bgsave_status:ok
  41. rdb_last_bgsave_time_sec:0
  42. rdb_current_bgsave_time_sec:-1
  43. aof_enabled:1
  44. aof_rewrite_in_progress:0
  45. aof_rewrite_scheduled:0
  46. aof_last_rewrite_time_sec:0
  47. aof_current_rewrite_time_sec:-1
  48. aof_last_bgrewrite_status:ok
  49. aof_last_write_status:ok
  50. aof_current_size:0
  51. aof_base_size:0
  52. aof_pending_rewrite:0
  53. aof_buffer_length:0
  54. aof_rewrite_buffer_length:0
  55. aof_pending_bio_fsync:0
  56. aof_delayed_fsync:0
  57. # Stats
  58. total_connections_received:3224
  59. total_commands_processed:112264
  60. instantaneous_ops_per_sec:3
  61. total_net_input_bytes:7818051
  62. total_net_output_bytes:41389834
  63. instantaneous_input_kbps:0.20
  64. instantaneous_output_kbps:0.52
  65. rejected_connections:0
  66. sync_full:0
  67. sync_partial_ok:0
  68. sync_partial_err:0
  69. expired_keys:0
  70. evicted_keys:0
  71. keyspace_hits:0
  72. keyspace_misses:0
  73. pubsub_channels:1
  74. pubsub_patterns:0
  75. latest_fork_usec:1122
  76. migrate_cached_sockets:0
  77. # Replication
  78. role:slave
  79. master_host:10.0.0.3
  80. master_port:6379
  81. master_link_status:down #显示10.0.0.3处于down状态
  82. master_last_io_seconds_ago:-1
  83. master_sync_in_progress:0
  84. slave_repl_offset:3503610
  85. master_link_down_since_seconds:5
  86. slave_priority:100
  87. slave_read_only:1
  88. connected_slaves:0
  89. master_repl_offset:0
  90. repl_backlog_active:0
  91. repl_backlog_size:1048576
  92. repl_backlog_first_byte_offset:0
  93. repl_backlog_histlen:0
  94. # CPU
  95. used_cpu_sys:9.66
  96. used_cpu_user:6.15
  97. used_cpu_sys_children:0.00
  98. used_cpu_user_children:0.00
  99. # Cluster
  100. cluster_enabled:0
  101. # Keyspace

约5庙后,10.0.0.4的info发生变化,变为master

  1. 10.0.0.4:6379> info
  2. # Server
  3. redis_version:3.0.7
  4. redis_git_sha1:00000000
  5. redis_git_dirty:0
  6. redis_build_id:660d4263a6943aef
  7. redis_mode:standalone
  8. os:Linux 2.6.32-573.el6.x86_64 x86_64
  9. arch_bits:64
  10. multiplexing_api:epoll
  11. gcc_version:4.4.7
  12. process_id:20274
  13. run_id:87dbdb3120a4070d5d0666ae2976d3aaeb65fc38
  14. tcp_port:6379
  15. uptime_in_seconds:17650
  16. uptime_in_days:0
  17. hz:10
  18. lru_clock:11769090
  19. config_file:/etc/redis/redis.conf
  20. # Clients
  21. connected_clients:7
  22. client_longest_output_list:0
  23. client_biggest_input_buf:0
  24. blocked_clients:0
  25. # Memory
  26. used_memory:1014896
  27. used_memory_human:991.11K
  28. used_memory_rss:9129984
  29. used_memory_peak:1109472
  30. used_memory_peak_human:1.06M
  31. used_memory_lua:36864
  32. mem_fragmentation_ratio:9.00
  33. mem_allocator:jemalloc-3.6.0
  34. # Persistence
  35. loading:0
  36. rdb_changes_since_last_save:0
  37. rdb_bgsave_in_progress:0
  38. rdb_last_save_time:1471386850
  39. rdb_last_bgsave_status:ok
  40. rdb_last_bgsave_time_sec:0
  41. rdb_current_bgsave_time_sec:-1
  42. aof_enabled:1
  43. aof_rewrite_in_progress:0
  44. aof_rewrite_scheduled:0
  45. aof_last_rewrite_time_sec:0
  46. aof_current_rewrite_time_sec:-1
  47. aof_last_bgrewrite_status:ok
  48. aof_last_write_status:ok
  49. aof_current_size:52
  50. aof_base_size:0
  51. aof_pending_rewrite:0
  52. aof_buffer_length:0
  53. aof_rewrite_buffer_length:0
  54. aof_pending_bio_fsync:0
  55. aof_delayed_fsync:0
  56. # Stats
  57. total_connections_received:3244
  58. total_commands_processed:112565
  59. instantaneous_ops_per_sec:4
  60. total_net_input_bytes:7832904
  61. total_net_output_bytes:41503789
  62. instantaneous_input_kbps:0.13
  63. instantaneous_output_kbps:4.10
  64. rejected_connections:0
  65. sync_full:0
  66. sync_partial_ok:0
  67. sync_partial_err:0
  68. expired_keys:0
  69. evicted_keys:0
  70. keyspace_hits:0
  71. keyspace_misses:0
  72. pubsub_channels:1
  73. pubsub_patterns:0
  74. latest_fork_usec:1053
  75. migrate_cached_sockets:0
  76. # Replication
  77. role:master #10.0.0.4已升为master
  78. connected_slaves:0
  79. master_repl_offset:0
  80. repl_backlog_active:0
  81. repl_backlog_size:1048576
  82. repl_backlog_first_byte_offset:0
  83. repl_backlog_histlen:0
  84. # CPU
  85. used_cpu_sys:9.69
  86. used_cpu_user:6.17
  87. used_cpu_sys_children:0.00
  88. used_cpu_user_children:0.00
  89. # Cluster
  90. cluster_enabled:0
  91. # Keyspace

手动start10.0.0.3上的redis

  1. [root@redis-3 ~]# /etc/init.d/redis start
  2. Stop Redis Server: [ OK ]

查看10.0.0.3的info

  1. 10.0.0.3:6379> info
  2. # Server
  3. redis_version:3.0.7
  4. redis_git_sha1:00000000
  5. redis_git_dirty:0
  6. redis_build_id:f0c9513907cc8c69
  7. redis_mode:standalone
  8. os:Linux 2.6.32-573.el6.x86_64 x86_64
  9. arch_bits:64
  10. multiplexing_api:epoll
  11. gcc_version:4.4.7
  12. process_id:8778
  13. run_id:1dc38ced5224d118772e928d55a891784c4fe78d
  14. tcp_port:6379
  15. uptime_in_seconds:12
  16. uptime_in_days:0
  17. hz:10
  18. lru_clock:11769675
  19. config_file:/etc/redis/redis.conf
  20. # Clients
  21. connected_clients:8
  22. client_longest_output_list:0
  23. client_biggest_input_buf:0
  24. blocked_clients:0
  25. # Memory
  26. used_memory:962056
  27. used_memory_human:939.51K
  28. used_memory_rss:9719808
  29. used_memory_peak:1105488
  30. used_memory_peak_human:1.05M
  31. used_memory_lua:36864
  32. mem_fragmentation_ratio:10.10
  33. mem_allocator:jemalloc-3.6.0
  34. # Persistence
  35. loading:0
  36. rdb_changes_since_last_save:1
  37. rdb_bgsave_in_progress:0
  38. rdb_last_save_time:1471387455
  39. rdb_last_bgsave_status:ok
  40. rdb_last_bgsave_time_sec:-1
  41. rdb_current_bgsave_time_sec:-1
  42. aof_enabled:1
  43. aof_rewrite_in_progress:0
  44. aof_rewrite_scheduled:0
  45. aof_last_rewrite_time_sec:1
  46. aof_current_rewrite_time_sec:-1
  47. aof_last_bgrewrite_status:ok
  48. aof_last_write_status:ok
  49. aof_current_size:0
  50. aof_base_size:0
  51. aof_pending_rewrite:0
  52. aof_buffer_length:0
  53. aof_rewrite_buffer_length:0
  54. aof_pending_bio_fsync:0
  55. aof_delayed_fsync:0
  56. # Stats
  57. total_connections_received:11
  58. total_commands_processed:80
  59. instantaneous_ops_per_sec:4
  60. total_net_input_bytes:4003
  61. total_net_output_bytes:25428
  62. instantaneous_input_kbps:0.30
  63. instantaneous_output_kbps:0.76
  64. rejected_connections:0
  65. sync_full:0
  66. sync_partial_ok:0
  67. sync_partial_err:0
  68. expired_keys:0
  69. evicted_keys:0
  70. keyspace_hits:0
  71. keyspace_misses:0
  72. pubsub_channels:1
  73. pubsub_patterns:0
  74. latest_fork_usec:1543
  75. migrate_cached_sockets:0
  76. # Replication
  77. role:slave
  78. master_host:10.0.0.4
  79. master_port:6379
  80. master_link_status:up
  81. master_last_io_seconds_ago:0
  82. master_sync_in_progress:0
  83. slave_repl_offset:160
  84. slave_priority:100
  85. slave_read_only:1
  86. connected_slaves:0
  87. master_repl_offset:0
  88. repl_backlog_active:0
  89. repl_backlog_size:1048576
  90. repl_backlog_first_byte_offset:0
  91. repl_backlog_histlen:0
  92. # CPU
  93. used_cpu_sys:0.01
  94. used_cpu_user:0.00
  95. used_cpu_sys_children:0.00
  96. used_cpu_user_children:0.00
  97. # Cluster
  98. cluster_enabled:0
  99. # Keyspace
  100. 10.0.0.3:6379> info
  101. # Server
  102. redis_version:3.0.7
  103. redis_git_sha1:00000000
  104. redis_git_dirty:0
  105. redis_build_id:f0c9513907cc8c69
  106. redis_mode:standalone
  107. os:Linux 2.6.32-573.el6.x86_64 x86_64
  108. arch_bits:64
  109. multiplexing_api:epoll
  110. gcc_version:4.4.7
  111. process_id:8778
  112. run_id:1dc38ced5224d118772e928d55a891784c4fe78d
  113. tcp_port:6379
  114. uptime_in_seconds:13
  115. uptime_in_days:0
  116. hz:10
  117. lru_clock:11769676
  118. config_file:/etc/redis/redis.conf
  119. # Clients
  120. connected_clients:8
  121. client_longest_output_list:0
  122. client_biggest_input_buf:0
  123. blocked_clients:0
  124. # Memory
  125. used_memory:962104
  126. used_memory_human:939.55K
  127. used_memory_rss:9719808
  128. used_memory_peak:1105488
  129. used_memory_peak_human:1.05M
  130. used_memory_lua:36864
  131. mem_fragmentation_ratio:10.10
  132. mem_allocator:jemalloc-3.6.0
  133. # Persistence
  134. loading:0
  135. rdb_changes_since_last_save:1
  136. rdb_bgsave_in_progress:0
  137. rdb_last_save_time:1471387455
  138. rdb_last_bgsave_status:ok
  139. rdb_last_bgsave_time_sec:-1
  140. rdb_current_bgsave_time_sec:-1
  141. aof_enabled:1
  142. aof_rewrite_in_progress:0
  143. aof_rewrite_scheduled:0
  144. aof_last_rewrite_time_sec:1
  145. aof_current_rewrite_time_sec:-1
  146. aof_last_bgrewrite_status:ok
  147. aof_last_write_status:ok
  148. aof_current_size:0
  149. aof_base_size:0
  150. aof_pending_rewrite:0
  151. aof_buffer_length:0
  152. aof_rewrite_buffer_length:0
  153. aof_pending_bio_fsync:0
  154. aof_delayed_fsync:0
  155. # Stats
  156. total_connections_received:11
  157. total_commands_processed:88
  158. instantaneous_ops_per_sec:6
  159. total_net_input_bytes:4603
  160. total_net_output_bytes:29359
  161. instantaneous_input_kbps:0.47
  162. instantaneous_output_kbps:2.67
  163. rejected_connections:0
  164. sync_full:0
  165. sync_partial_ok:0
  166. sync_partial_err:0
  167. expired_keys:0
  168. evicted_keys:0
  169. keyspace_hits:0
  170. keyspace_misses:0
  171. pubsub_channels:1
  172. pubsub_patterns:0
  173. latest_fork_usec:1543
  174. migrate_cached_sockets:0
  175. # Replication #启动后成为了10.0.0.4的slave
  176. role:slave
  177. master_host:10.0.0.4
  178. master_port:6379
  179. master_link_status:up
  180. master_last_io_seconds_ago:0
  181. master_sync_in_progress:0
  182. slave_repl_offset:296
  183. slave_priority:100
  184. slave_read_only:1
  185. connected_slaves:0
  186. master_repl_offset:0
  187. repl_backlog_active:0
  188. repl_backlog_size:1048576
  189. repl_backlog_first_byte_offset:0
  190. repl_backlog_histlen:0
  191. # CPU
  192. used_cpu_sys:0.01
  193. used_cpu_user:0.00
  194. used_cpu_sys_children:0.00
  195. used_cpu_user_children:0.00
  196. # Cluster
  197. cluster_enabled:0
  198. # Keyspace

再查看10.0.0.4的info

  1. 10.0.0.4:6379> info
  2. # Server
  3. redis_version:3.0.7
  4. redis_git_sha1:00000000
  5. redis_git_dirty:0
  6. redis_build_id:660d4263a6943aef
  7. redis_mode:standalone
  8. os:Linux 2.6.32-573.el6.x86_64 x86_64
  9. arch_bits:64
  10. multiplexing_api:epoll
  11. gcc_version:4.4.7
  12. process_id:20274
  13. run_id:87dbdb3120a4070d5d0666ae2976d3aaeb65fc38
  14. tcp_port:6379
  15. uptime_in_seconds:17650
  16. uptime_in_days:0
  17. hz:10
  18. lru_clock:11769090
  19. config_file:/etc/redis/redis.conf
  20. # Clients
  21. connected_clients:7
  22. client_longest_output_list:0
  23. client_biggest_input_buf:0
  24. blocked_clients:0
  25. # Memory
  26. used_memory:1014896
  27. used_memory_human:991.11K
  28. used_memory_rss:9129984
  29. used_memory_peak:1109472
  30. used_memory_peak_human:1.06M
  31. used_memory_lua:36864
  32. mem_fragmentation_ratio:9.00
  33. mem_allocator:jemalloc-3.6.0
  34. # Persistence
  35. loading:0
  36. rdb_changes_since_last_save:0
  37. rdb_bgsave_in_progress:0
  38. rdb_last_save_time:1471386850
  39. rdb_last_bgsave_status:ok
  40. rdb_last_bgsave_time_sec:0
  41. rdb_current_bgsave_time_sec:-1
  42. aof_enabled:1
  43. aof_rewrite_in_progress:0
  44. aof_rewrite_scheduled:0
  45. aof_last_rewrite_time_sec:0
  46. aof_current_rewrite_time_sec:-1
  47. aof_last_bgrewrite_status:ok
  48. aof_last_write_status:ok
  49. aof_current_size:52
  50. aof_base_size:0
  51. aof_pending_rewrite:0
  52. aof_buffer_length:0
  53. aof_rewrite_buffer_length:0
  54. aof_pending_bio_fsync:0
  55. aof_delayed_fsync:0
  56. # Stats
  57. total_connections_received:3244
  58. total_commands_processed:112565
  59. instantaneous_ops_per_sec:4
  60. total_net_input_bytes:7832904
  61. total_net_output_bytes:41503789
  62. instantaneous_input_kbps:0.13
  63. instantaneous_output_kbps:4.10
  64. rejected_connections:0
  65. sync_full:0
  66. sync_partial_ok:0
  67. sync_partial_err:0
  68. expired_keys:0
  69. evicted_keys:0
  70. keyspace_hits:0
  71. keyspace_misses:0
  72. pubsub_channels:1
  73. pubsub_patterns:0
  74. latest_fork_usec:1053
  75. migrate_cached_sockets:0
  76. # Replication
  77. role:master
  78. connected_slaves:0
  79. master_repl_offset:0
  80. repl_backlog_active:0
  81. repl_backlog_size:1048576
  82. repl_backlog_first_byte_offset:0
  83. repl_backlog_histlen:0
  84. # CPU
  85. used_cpu_sys:9.69
  86. used_cpu_user:6.17
  87. used_cpu_sys_children:0.00
  88. used_cpu_user_children:0.00
  89. # Cluster
  90. cluster_enabled:0
  91. # Keyspace
  92. 10.0.0.4:6379> info
  93. # Server
  94. redis_version:3.0.7
  95. redis_git_sha1:00000000
  96. redis_git_dirty:0
  97. redis_build_id:660d4263a6943aef
  98. redis_mode:standalone
  99. os:Linux 2.6.32-573.el6.x86_64 x86_64
  100. arch_bits:64
  101. multiplexing_api:epoll
  102. gcc_version:4.4.7
  103. process_id:20274
  104. run_id:87dbdb3120a4070d5d0666ae2976d3aaeb65fc38
  105. tcp_port:6379
  106. uptime_in_seconds:18318
  107. uptime_in_days:0
  108. hz:10
  109. lru_clock:11769758
  110. config_file:/etc/redis/redis.conf
  111. # Clients
  112. connected_clients:7
  113. client_longest_output_list:0
  114. client_biggest_input_buf:0
  115. blocked_clients:0
  116. # Memory
  117. used_memory:2010680
  118. used_memory_human:1.92M
  119. used_memory_rss:9256960
  120. used_memory_peak:2120344
  121. used_memory_peak_human:2.02M
  122. used_memory_lua:36864
  123. mem_fragmentation_ratio:4.60
  124. mem_allocator:jemalloc-3.6.0
  125. # Persistence
  126. loading:0
  127. rdb_changes_since_last_save:0
  128. rdb_bgsave_in_progress:0
  129. rdb_last_save_time:1471387466
  130. rdb_last_bgsave_status:ok
  131. rdb_last_bgsave_time_sec:0
  132. rdb_current_bgsave_time_sec:-1
  133. aof_enabled:1
  134. aof_rewrite_in_progress:0
  135. aof_rewrite_scheduled:0
  136. aof_last_rewrite_time_sec:0
  137. aof_current_rewrite_time_sec:-1
  138. aof_last_bgrewrite_status:ok
  139. aof_last_write_status:ok
  140. aof_current_size:52
  141. aof_base_size:0
  142. aof_pending_rewrite:0
  143. aof_buffer_length:0
  144. aof_rewrite_buffer_length:0
  145. aof_pending_bio_fsync:0
  146. aof_delayed_fsync:0
  147. # Stats
  148. total_connections_received:3366
  149. total_commands_processed:115873
  150. instantaneous_ops_per_sec:5
  151. total_net_input_bytes:7999749
  152. total_net_output_bytes:42607889
  153. instantaneous_input_kbps:0.31
  154. instantaneous_output_kbps:1.03
  155. rejected_connections:0
  156. sync_full:1
  157. sync_partial_ok:0
  158. sync_partial_err:0
  159. expired_keys:0
  160. evicted_keys:0
  161. keyspace_hits:0
  162. keyspace_misses:0
  163. pubsub_channels:1
  164. pubsub_patterns:0
  165. latest_fork_usec:964
  166. migrate_cached_sockets:0
  167. # Replication
  168. role:master
  169. connected_slaves:1
  170. slave0:ip=10.0.0.3,port=6379,state=online,offset=16592,lag=1
  171. master_repl_offset:16606
  172. repl_backlog_active:1
  173. repl_backlog_size:1048576
  174. repl_backlog_first_byte_offset:2
  175. repl_backlog_histlen:16605
  176. # CPU
  177. used_cpu_sys:10.03
  178. used_cpu_user:6.36
  179. used_cpu_sys_children:0.00
  180. used_cpu_user_children:0.00
  181. # Cluster
  182. cluster_enabled:0
  183. # Keyspace

主从切换成功,说明redis-sentinel工作正常,到此为止,sentinel配置完毕

2
未经许可,不得转载,否则将受到作者追究,博主联系方式见首页右上角

该文章由 发布

这货来去如风,什么鬼都没留下!!!
发表我的评论
取消评论
代码 贴图 加粗 链接 删除线 签到

(3)条精彩评论:
  1. 匿名
    :eek:
    匿名2016-08-30 15:13 回复
  2. 匿名
    sss
    匿名2016-09-22 15:25 回复
    • admin
      谢谢
      admin2016-10-19 11:12 回复