본문 바로가기

리눅스

[리눅스] mongodb(config) - 1

728x90

mongodb(config) - 1

mongodb PRIMARY

docker-compose exec config bash
mongo --port 27018

ReplicaSet 초기화

rs.initiate(
   {
      _id: "configserver",
      members: [
         { _id: 0, host : "mongodb-201:27018" },
         { _id: 1, host : "mongodb-202:27018" },
         { _id: 2, host : "mongodb-203:27018" }
      ]
   }
)
use admin
configserver:PRIMARY> use admin
switched to db admin
db.createUser({user:"root",pwd:"changeme",roles:[{role:"root",db:"admin"}]});
configserver:PRIMARY> db.createUser({user:"root",pwd:"password",roles:[{role:"root",db:"admin"}]});
Successfully added user: {
	"user" : "root",
	"roles" : [
		{
			"role" : "root",
			"db" : "admin"
		}
	]
}
** secondary 추가
rs.add("mongodb-201:27011")
rs.add("mongodb-202:27012")
** arbiter 추가
rs.addArb("mongodb-203:27013")
mongo -u root -p changeme --port 27018
rs.config();
configserver:PRIMARY> rs.config();
{
	"_id" : "configserver",
	"version" : 1,
	"term" : 1,
	"members" : [
		{
			"_id" : 0,
			"host" : "mongodb-201:27018",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {

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

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

			},
			"secondaryDelaySecs" : NumberLong(0),
			"votes" : 1
		}
	],
	"configsvr" : true,
	"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("6295ec5ea306b29456e81bdf")
	}
}

mongodb SECONDARY

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

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

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

			},
			"secondaryDelaySecs" : NumberLong(0),
			"votes" : 1
		}
	],
	"configsvr" : true,
	"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("629ef0296075e6fadc5a1165")
	}
}
configserver:SECONDARY>
728x90