MongoDB下rs.status()命令

最近经常遇到数据库卡顿,连接异常问题,需要链接到数据库内,常用到rs.status()复制集状态查询命令,故借鉴前辈的文章,在此记录下来,供后续查看,此处有官人的链接和ID,敬请关注下该博主,谢谢

   本文为   wei-xh   的博文,请多多关注博主,链接http://blog.itpub.net/22034023/viewspace-1074651/

 

{

        "set" : "wxh",
        "date" : ISODate("2014-01-23T09:34:23Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "wxlab31:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",          #  stateStr用户描述服务器状态的字符串。有SECONDARY,PRIMARY,RECOVERING等
                        "uptime" : 30060,                           #  uptime 从成员可到达一直到现在经历的时间,单位是秒。
                        "optime" : Timestamp(1390450194, 3),        #  optimeDate 每个成员oplog最后一次操作发生的时间,这个时间是心跳报上来的,因此可能会存在延迟
                        "optimeDate" : ISODate("2014-01-23T04:09:54Z"),
                        "lastHeartbeat" : ISODate("2014-01-23T09:34:21Z"),    #  lastHeartbeat 当前服务器最后一次收到其他成员心跳的时间,如果网络故障等可能这个时间会大于2秒
                        "lastHeartbeatRecv" : ISODate("2014-01-23T09:34:21Z"),
                        "pingMs" : 0,                #  pinMs 心跳从当前服务器达到某个成员所花费的平均时间
                        "syncingTo" : "wxlab31:27018"        # syncingTo表示当前服务器从哪个节点在做同步
                },
                {
                        "_id" : 1,
                        "name" : "wxlab31:27018",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY", 
                        "uptime" : 30067,
                        "optime" : Timestamp(1390450194, 3),
                        "optimeDate" : ISODate("2014-01-23T04:09:54Z"),
                        "self" : true            # self 这个信息出现在执行rs.status( )函数的成员信息中
           },
                {
                        "_id" : 2,
                        "name" : "wxlab31:27019",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 30066,            
                        "optime" : Timestamp(1390450194, 3),   
                        "optimeDate" : ISODate("2014-01-23T04:09:54Z"),
                        "lastHeartbeat" : ISODate("2014-01-23T09:34:22Z"),   
                        "lastHeartbeatRecv" : ISODate("2014-01-23T09:34:21Z"),
                        "pingMs" : 0, 
                        "syncingTo" : "wxlab31:27018"   
                },
                {
                        "_id" : 3,
                        "name" : "wxlab31:27020",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 30066,
                        "optime" : Timestamp(1390450194, 3),
                        "optimeDate" : ISODate("2014-01-23T04:09:54Z"),
                        "lastHeartbeat" : ISODate("2014-01-23T09:34:21Z"),
                        "lastHeartbeatRecv" : ISODate("2014-01-23T09:34:22Z"),
                        "pingMs" : 0,
                        "syncingTo" : "wxlab31:27018"
                }
        ],
        "ok" : 1
}

字段解释:

  • name是副本集节点的ip和端口信息
  • health表示副本集中该节点是否正常,0表示不正常,1表示正常
  • state表示节点的身份,0表示非主节点,1表示主节点
  • stateStr用于对节点身份进行字符描述,PRIMARY表示主节点,SECONDARY表示副节点
  • uptime 从成员可到达一直到现在经历的时间,单位是秒。
  • optimeDate 每个成员oplog最后一次操作发生的时间,这个时间是心跳报上来的,因此可能会存在延迟
  • lastHeartbeat 当前服务器最后一次收到其他成员心跳的时间,如果网络故障等可能这个时间会大于2秒
  • pinMs 心跳从当前服务器达到某个成员所花费的平均时间
  • syncingTo 当前服务器从哪个节点在做同步
  • self 这个信息出现在执行rs.status()函数的成员信息中
  • errmsg 成员在心跳请求中返回的状态信息,通过是一些状态信息,不全是错误信息。

health表示服务器是否可达,可达是1,不可达是0
optime与optimeDate表达的信息也是一样的,只是表示的方式不同,一个是用新纪元开始的毫秒数表示的,一个是用一种更容易阅读的方式表示。
由于rs.status()是从执行命令成员本身的角度得出的,由于网路等故障,这份报告可能不准确或者有些过时。

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=db-mongo-rs.public-component:4031, type=UNKNOWN, roundTripTime=11.1 ms, state=CONNECTED, exception={com.mongodb.MongoConfigurationException: Replica set name 'null' does not match required replica set name of 'mongo-rs'}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=db-mongo-rs.public-component:4031, type=UNKNOWN, roundTripTime=11.1 ms, state=CONNECTED, exception={com.mongodb.MongoConfigurationException: Replica set name 'null' does not match required replica set name of 'mongo-rs'}}] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.29.jar:5.3.29] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.29.jar:5.3.29] ... 33 common frames omitted Caused by: org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=db-mongo-rs.public-component:4031, type=UNKNOWN, roundTripTime=11.1 ms, state=CONNECTED, exception={com.mongodb.MongoConfigurationException: Replica set name 'null' does not match required replica set name of 'mongo-rs'}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=db-mongo-rs.public-component:4031, type=UNKNOWN, roundTripTime=11.1 ms, state=CONNECTED, exception={com.mongodb.MongoConfigurationException: Replica set name 'null' does not match required replica set name of 'mongo-rs'}}] at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:95) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:3029) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:581) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.DefaultIndexOperations.execute(DefaultIndexOperations.java:215) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.DefaultIndexOperations.ensureIndex(DefaultIndexOperations.java:121) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.createIndex(MongoPersistentEntityIndexCreator.java:157) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForAndCreateIndexes(MongoPersistentEntityIndexCreator.java:147) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForIndexes(MongoPersistentEntityIndexCreator.java:131) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.<init>(MongoPersistentEntityIndexCreator.java:96) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.<init>(MongoPersistentEntityIndexCreator.java:73) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.MongoTemplate.<init>(MongoTemplate.java:224) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.boot.autoconfigure.data.mongo.MongoDatabaseFactoryDependentConfiguration.mongoTemplate(MongoDatabaseFactoryDependentConfiguration.java:63) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.29.jar:5.3.29] ... 34 common frames omitted Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=db-mongo-rs.public-component:4031, type=UNKNOWN, roundTripTime=11.1 ms, state=CONNECTED, exception={com.mongodb.MongoConfigurationException: Replica set name 'null' does not match required replica set name of 'mongo-rs'}}] at com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:180) ~[mongodb-driver-core-4.6.1.jar:na] at com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:44) ~[mongodb-driver-core-4.6.1.jar:na] at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:144) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:101) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:291) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:207) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.executeCreateIndexes(MongoCollectionImpl.java:848) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:831) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:826) ~[mongodb-driver-sync-4.6.1.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.createIndex(MongoCollectionImpl.java:811) ~[mongodb-driver-sync-4.6.1.jar:na] at org.springframework.data.mongodb.core.DefaultIndexOperations.lambda$ensureIndex$0(DefaultIndexOperations.java:131) ~[spring-data-mongodb-3.4.15.jar:3.4.15] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:579) ~[spring-data-mongodb-3.4.15.jar:3.4.15] ... 46 common frames omitted、
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值