본문 바로가기

리눅스

[리눅스] mongodb(shard) - 2

728x90

mongodb(shard) - 2

mongodb PRIMARY

docker-compose exec mongo1 bash
mongo --port 27011
rs.initiate(
   {
      _id: "rs0",
      members: [
         { _id: 0, host : "mongodb-201:27011" },
         { _id: 1, host : "mongodb-202:27011" },
         { _id: 2, host : "mongodb-203:27011" },
         { _id: 3, host : "mongodb-201:27012" },
         { _id: 4, host : "mongodb-202:27012" },
         { _id: 5, host : "mongodb-203:27012" },
         { _id: 6, host : "mongodb-203:27013", arbiterOnly:true }
      ]
   }
)
> rs.initiate(
...    {
...       _id: "rs0",
...       members: [
...          { _id: 0, host : "mongodb-201:27011" },
...          { _id: 1, host : "mongodb-202:27011" },
...          { _id: 2, host : "mongodb-203:27011" },
...          { _id: 3, host : "mongodb-201:27012" },
...          { _id: 4, host : "mongodb-202:27012" },
...          { _id: 5, host : "mongodb-203:27012" },
...          { _id: 6, host : "mongodb-203:27013", arbiterOnly:true }
...       ]
...    }
... )
{ "ok" : 1 }
rs.add("mongodb-201:27011")
rs.add("mongodb-202:27012")
rs.addArb("mongodb-203:27013")
use admin
rs0:PRIMARY> use admin
switched to db admin
db.createUser({user:"root",pwd:"changeme",roles:[{role:"root",db:"admin"}]});
rs0:PRIMARY> db.createUser({user:"root",pwd:"changeme",roles:[{role:"root",db:"admin"}]});
Successfully added user: {
	"user" : "root",
	"roles" : [
		{
			"role" : "root",
			"db" : "admin"
		}
	]
}
rs0:PRIMARY> exit
bye
mongo -u root -p changeme --port 27011
rs0:PRIMARY> rs.config();
{
	"_id" : "rs0",
	"version" : 1,
	"term" : 1,
	"members" : [
		{
			"_id" : 0,
			"host" : "mongodb-201:27011",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 1,
			"host" : "mongodb-202:27011",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 2,
			"host" : "mongodb-203:27011",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 3,
			"host" : "mongodb-201:27012",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 4,
			"host" : "mongodb-202:27012",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 5,
			"host" : "mongodb-203:27012",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 6,
			"host" : "mongodb-203:27013",
			"arbiterOnly" : true,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 0,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"protocolVersion" : NumberLong(1),
	"writeConcernMajorityJournalDefault" : true,
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : -1,
		"catchUpTakeoverDelayMillis" : 30000,
		"getLastErrorModes" : {

		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("6295fb465602431c5d2e5605")
	}
}

mongodb SECONDARY

docker-compose exec mongo1 bash
mongo -u root -p changeme --port 27011
rs.config();
rs0:SECONDARY> rs.config();
{
	"_id" : "rs0",
	"version" : 1,
	"term" : 1,
	"members" : [
		{
			"_id" : 0,
			"host" : "mongodb-201:27011",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 1,
			"host" : "mongodb-202:27011",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 2,
			"host" : "mongodb-203:27011",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 3,
			"host" : "mongodb-201:27012",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 4,
			"host" : "mongodb-202:27012",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 5,
			"host" : "mongodb-203:27012",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 6,
			"host" : "mongodb-203:27013",
			"arbiterOnly" : true,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 0,
			"tags" : {

			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"protocolVersion" : NumberLong(1),
	"writeConcernMajorityJournalDefault" : true,
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : -1,
		"catchUpTakeoverDelayMillis" : 30000,
		"getLastErrorModes" : {

		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("629ef1dbbfe5be1e53fa39de")
	}
}
rs0:SECONDARY>
728x90