Redis - 如何查看 Redis 主从信息?

Posted 放羊的牧码

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis - 如何查看 Redis 主从信息?相关的知识,希望对你有一定的参考价值。

方法一

如下命令

redis-cli -h 10.218.223.147 -p 16380 info

结果如下

# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b2d74fe5fff7657d
redis_mode:standalone
os:Linux 2.6.32-696.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:3945
run_id:c37f073621e201bad8d708cfdd9a40be68964e2f
tcp_port:16380
uptime_in_seconds:26878
uptime_in_days:0
hz:10
lru_clock:909298
executable:/opt/redis-sentinel/redis-server
config_file:/opt/redis-sentinel/redis02.conf

# Clients
connected_clients:27
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:53727848
used_memory_human:51.24M
used_memory_rss:61210624
used_memory_rss_human:58.38M
used_memory_peak:65461048
used_memory_peak_human:62.43M
total_system_memory:16725540864
total_system_memory_human:15.58G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.14
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1594736112
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:5989
total_commands_processed:239517
instantaneous_ops_per_sec:6
total_net_input_bytes:117115403
total_net_output_bytes:1407208564
instantaneous_input_kbps:0.39
instantaneous_output_kbps:1.43
rejected_connections:0
sync_full:2
sync_partial_ok:0
sync_partial_err:0
expired_keys:11
evicted_keys:0
keyspace_hits:9505
keyspace_misses:235
pubsub_channels:1
pubsub_patterns:0
latest_fork_usec:11480
migrate_cached_sockets:0

# Replication 红色部分说明
role:master
connected_slaves:2
slave0:ip=10.218.223.147,port=16379,state=online,offset=99380539,lag=0
slave1:ip=10.218.223.147,port=16381,state=online,offset=99380539,lag=1
master_repl_offset:99380841
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:98332266
repl_backlog_histlen:1048576

# CPU
used_cpu_sys:42.66
used_cpu_user:24.21
used_cpu_sys_children:0.16
used_cpu_user_children:0.56

# Cluster
cluster_enabled:0

# Keyspace
db5:keys=26,expires=0,avg_ttl=0
  • 标记红色部分说明 IP 为10.218.223.147,port为16380的实例为主,16379和16381的实例都是从。

 

方法二

[root@template ~]# redis-cli -p 36379
127.0.0.1:36379> SENTINEL get-master-addr-by-name mymaster
1) "192.168.205.151"
2) "6379"
127.0.0.1:36379> 
  • Ps:这个命令好处在于定位精准,无论是在主还是从服务器上,都可以准确定位出谁是主!

以上是关于Redis - 如何查看 Redis 主从信息?的主要内容,如果未能解决你的问题,请参考以下文章

Redis - 如何查看 Redis 主从信息?

主机怎么查看redis主从节点

Redis Cluster集群扩容主从节点详细教程

redis sentinel介绍

Redis——主从复制哨兵模式集群服务

redis主从切换