kubernetes生产实践之mongodb (2)

3、验证集群状态及读写

# 获取账号密码 kubectl get secrets -n demo mongo-sh-auth -o jsonpath='{.data.\username}' | base64 -d root kubectl get secrets -n demo mongo-sh-auth -o jsonpath='{.data.\password}' | base64 -d 123456 # 连接mongo root@mongo-sharding-mongos-0:/# mongo admin -u root -p MongoDB shell version v4.2.3 Enter password: connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("948eadef-87b6-4ab2-ba5a-c8f4e23689a7") } MongoDB server version: 4.2.3 Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see Questions? Try the support group Server has startup warnings: 2021-03-12T08:10:48.173+0000 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended. 2021-03-12T08:10:48.173+0000 I CONTROL [main] mongos> # 查看分片集群状态 mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "minCompatibleVersion" : 5, "currentVersion" : 6, "clusterId" : ObjectId("604b201f7fb058e04bb03ef0") } shards: { "_id" : "shard0", "host" : "shard0/mongo-sharding-shard0-0.mongo-sharding-shard0-pods.op.svc.cluster.local:27017,mongo-sharding-shard0-1.mongo-sharding-shard0-pods.op.svc.cluster.local:27017,mongo-sharding-shard0-2.mongo-sharding-shard0-pods.op.svc.cluster.local:27017", "state" : 1 } { "_id" : "shard1", "host" : "shard1/mongo-sharding-shard1-0.mongo-sharding-shard1-pods.op.svc.cluster.local:27017,mongo-sharding-shard1-1.mongo-sharding-shard1-pods.op.svc.cluster.local:27017,mongo-sharding-shard1-2.mongo-sharding-shard1-pods.op.svc.cluster.local:27017", "state" : 1 } active mongoses: "4.2.3" : 2 autosplit: Currently enabled: yes balancer: Currently enabled: yes Currently running: no Failed balancer rounds in last 5 attempts: 0 Migration Results for the last 24 hours: No recent migrations databases: { "_id" : "config", "primary" : "config", "partitioned" : true } config.system.sessions shard key: { "_id" : 1 } unique: false balancing: true chunks: shard0 1 { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0 Timestamp(1, 0) #创建分片 mongos> sh.enableSharding("test"); { "ok" : 1, "operationTime" : Timestamp(1615538870, 3), "$clusterTime" : { "clusterTime" : Timestamp(1615538870, 3), "signature" : { "hash" : BinData(0,"CTnuwtgOIn+ke0qqarLQIi+VXz8="), "keyId" : NumberLong("6938674968410456068") } } } # 创建集合 mongos> sh.shardCollection("test.testcoll", {"myfield": 1}); { "collectionsharded" : "test.testcoll", "collectionUUID" : UUID("313cacbe-014c-4e0a-9112-427de2351bdd"), "ok" : 1, "operationTime" : Timestamp(1615539067, 9), "$clusterTime" : { "clusterTime" : Timestamp(1615539067, 9), "signature" : { "hash" : BinData(0,"1RQN94R6yHvUa0SqBHkiV2hUXNM="), "keyId" : NumberLong("6938674968410456068") } } } # 写入数据 mongos> db.testcoll.insert({"myfield": "scofield", "agefield": "18"}); WriteResult({ "nInserted" : 1 }) mongos> db.testcoll.insert({"myfield": "amos", "otherfield": "d", "kube" : "db" }); WriteResult({ "nInserted" : 1 }) # 获取数据 mongos> db.testcoll.find(); { "_id" : ObjectId("604b2d099446ca80f20bab7f"), "myfield" : "scofield", "agefield" : "18" } { "_id" : ObjectId("604b2d4d9446ca80f20bab80"), "myfield" : "amos", "otherfield" : "d", "kube" : "db" }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wspfgz.html