MongoDB version 3.4.4 (Windows 버전)에서의 샤딩 설정 관련

2017. 4. 23. 13:27서버 프로그래밍

* mongos 실행 시, configdb는 반드시 replicaset으로 구성되어 있어야 함


C:\mongodb\bin>mongod -configsvr -dbpath c:\mongodb\config1 -port 20001 -replSet configSet

C:\mongodb\bin>mongod -configsvr -dbpath c:\mongodb\config2 -port 20002 -replSet configSet

C:\mongodb\bin>mongod -configsvr -dbpath c:\mongodb\config3 -port 20003 -replSet configSet

C:\mongodb\bin>mongo localhost:20001

MongoDB shell version v3.4.4

connecting to: localhost:20001

MongoDB server version: 3.4.4

Welcome to the MongoDB shell.

For interactive help, type "help".

For more comprehensive documentation, see

        http://docs.mongodb.org/

Questions? Try the support group

        http://groups.google.com/group/mongodb-user

Server has startup warnings:

2017-04-23T12:35:33.537+0900 I CONTROL  [initandlisten]

2017-04-23T12:35:33.537+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2017-04-23T12:35:33.539+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2017-04-23T12:35:33.540+0900 I CONTROL  [initandlisten]

> var config={_id:'configSet',members:[{_id:0,host:'localhost:20001'},{_id:1,host:'localhost:20002'},{_id:2,host:'localhost:20003'}]};

> rs.initiate(config);

{ "ok" : 1 }

configSet:OTHER>

configSet:SECONDARY>


C:\mongodb\bin>mongos --configdb configSet/localhost:20001,localhost:20002,localhost:20003 -port 20000


* mongos 에서 chunksize 값 설정하는 방법

https://docs.mongodb.com/manual/tutorial/modify-chunk-size-in-sharded-cluster/

  1. Connect to any mongos in the cluster using the mongo shell.

  2. Issue the following command to switch to the Config Database:

    use config
    
  3. Issue the following save() operation to store the global chunk size configuration value:

    db.settings.save( { _id:"chunksize", value: <sizeInMB> } )

C:\mongodb\bin>mongo localhost:20000

MongoDB shell version v3.4.4

connecting to: localhost:20000

MongoDB server version: 3.4.4

Server has startup warnings:

2017-04-23T12:43:52.645+0900 I CONTROL  [main]

2017-04-23T12:43:52.646+0900 I CONTROL  [main] ** WARNING: Access control is not enabled for the database.

2017-04-23T12:43:52.647+0900 I CONTROL  [main] **          Read and write access to data and configuration is unrestricted.

2017-04-23T12:43:52.648+0900 I CONTROL  [main]

mongos> use config

switched to db config

mongos> db.settings.save({_id:'chunksize',value:1});

WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : "chunksize" })

mongos> db.settings.find();

{ "_id" : "chunksize", "value" : 1 }