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
'리눅스' 카테고리의 다른 글
[리눅스] 몽고디비 클러스터 구성하기(mongodb shard cluster) (0) | 2022.05.31 |
---|---|
[리눅스] mongodb(router) - 3 (0) | 2022.05.31 |
[리눅스] mongodb(config) - 1 (0) | 2022.05.31 |
Elasticsearch와 Kibana를 Docker를 사용하여 single-node로 실행하는 방법 (0) | 2022.05.26 |
Elasticsearch 클러스터와 Kibana를 Docker를 사용하여 실행하는 방법(elasticsearch cluster) (0) | 2022.05.26 |