카이도스의 Tech Blog
Mongodb Shard Cluster 설치 - 2(연동 작업) 본문
728x90
반응형
2024.02.23 - [DB] - Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정)
2024.02.23 - [DB] - sharding 테스트
2024.02.26 - [DB] - Mongodb Shard Cluster - 구성 고도화
config server 실행
더보기
# config server
mongod --config /data/mongodb/conf/configsvr.conf &
# 확인
sudo netstat -nlp | grep 27050
tcp 0 0 0.0.0.0:27050 0.0.0.0:* LISTEN 5692/mongod
unix 2 [ ACC ] STREAM LISTENING 57915 5692/mongod /tmp/mongodb-27050.sock
# mongsh (레플리카셋 구성)
mongosh --port=27050
use admin
rs.initiate( {
_id : "configrs",
members: [
{ _id: 0, host: "10.10.X.181:27050" },
{ _id: 1, host: "10.10.X.184:27050" },
{ _id: 2, host: "10.10.X.187:27050" }
]
})
# 확인
rs.status()
{
set: 'configrs',
date: ISODate('2024-02-05T07:39:39.874Z'),
myState: 1,
term: Long('1'),
syncSourceHost: '',
syncSourceId: -1,
configsvr: true,
heartbeatIntervalMillis: Long('2000'),
majorityVoteCount: 2,
writeMajorityCount: 2,
votingMembersCount: 3,
writableVotingMembersCount: 3,
optimes: {
lastCommittedOpTime: { ts: Timestamp({ t: 1707118779, i: 1 }), t: Long('1') },
lastCommittedWallTime: ISODate('2024-02-05T07:39:39.043Z'),
readConcernMajorityOpTime: { ts: Timestamp({ t: 1707118779, i: 1 }), t: Long('1') },
appliedOpTime: { ts: Timestamp({ t: 1707118779, i: 1 }), t: Long('1') },
durableOpTime: { ts: Timestamp({ t: 1707118779, i: 1 }), t: Long('1') },
lastAppliedWallTime: ISODate('2024-02-05T07:39:39.043Z'),
lastDurableWallTime: ISODate('2024-02-05T07:39:39.043Z')
},
lastStableRecoveryTimestamp: Timestamp({ t: 1707118778, i: 1 }),
electionCandidateMetrics: {
lastElectionReason: 'electionTimeout',
lastElectionDate: ISODate('2024-02-05T07:38:48.955Z'),
electionTerm: Long('1'),
lastCommittedOpTimeAtElection: { ts: Timestamp({ t: 1707118718, i: 1 }), t: Long('-1') },
lastSeenOpTimeAtElection: { ts: Timestamp({ t: 1707118718, i: 1 }), t: Long('-1') },
numVotesNeeded: 2,
priorityAtElection: 1,
electionTimeoutMillis: Long('10000'),
numCatchUpOps: Long('0'),
newTermStartDate: ISODate('2024-02-05T07:38:48.973Z'),
wMajorityWriteAvailabilityDate: ISODate('2024-02-05T07:38:49.478Z')
},
....
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1707118779, i: 1 }),
signature: {
hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0),
keyId: Long('0')
}
},
operationTime: Timestamp({ t: 1707118779, i: 1 })
}
shard_1 server 실행
더보기
# shard_1 server
mongod --config /data/mongodb/conf/shard_1.conf &
# 확인
sudo netstat -nlp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 6022/mongod
unix 2 [ ACC ] STREAM LISTENING 2417 6022/mongod /tmp/mongodb-27017.sock
# mongsh (레플리카셋 구성)
mongosh --port=27017
use admin
rs.initiate( {
_id : "rs1",
members: [
{ _id: 0, host: "10.10.X.181:27017" },
{ _id: 1, host: "10.10.X.182:27017" },
{ _id: 2, host: "10.10.X.183:27017" }
]
})
# 확인
rs.status()
{
set: 'rs1',
date: ISODate('2024-02-05T07:49:08.089Z'),
myState: 2,
term: Long('0'),
syncSourceHost: '',
syncSourceId: -1,
heartbeatIntervalMillis: Long('2000'),
majorityVoteCount: 2,
writeMajorityCount: 2,
votingMembersCount: 3,
writableVotingMembersCount: 3,
optimes: {
lastCommittedOpTime: { ts: Timestamp({ t: 1707119344, i: 1 }), t: Long('-1') },
lastCommittedWallTime: ISODate('2024-02-05T07:49:04.551Z'),
readConcernMajorityOpTime: { ts: Timestamp({ t: 1707119344, i: 1 }), t: Long('-1') },
appliedOpTime: { ts: Timestamp({ t: 1707119344, i: 1 }), t: Long('-1') },
durableOpTime: { ts: Timestamp({ t: 1707119344, i: 1 }), t: Long('-1') },
lastAppliedWallTime: ISODate('2024-02-05T07:49:04.551Z'),
lastDurableWallTime: ISODate('2024-02-05T07:49:04.551Z')
},
lastStableRecoveryTimestamp: Timestamp({ t: 1707119344, i: 1 }),
....
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1707119344, i: 1 }),
signature: {
hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0),
keyId: Long('0')
}
},
operationTime: Timestamp({ t: 1707119344, i: 1 })
}
shard_2 server 실행
더보기
# shard_2 server
mongod --config /data/mongodb/conf/shard_2.conf &
# 확인
sudo netstat -nlp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 6022/mongod
unix 2 [ ACC ] STREAM LISTENING 2417 6022/mongod /tmp/mongodb-27017.sock
# mongsh (레플리카셋 구성)
mongosh --port=27017
use admin
rs.initiate( {
_id : "rs2",
members: [
{ _id: 0, host: "10.10.X.184:27017" },
{ _id: 1, host: "10.10.X.185:27017" },
{ _id: 2, host: "10.10.X.186:27017" }
]
})
# 확인
rs.status()
{
set: 'rs2',
date: ISODate('2024-02-05T07:50:46.886Z'),
myState: 2,
term: Long('0'),
syncSourceHost: '',
syncSourceId: -1,
heartbeatIntervalMillis: Long('2000'),
majorityVoteCount: 2,
writeMajorityCount: 2,
votingMembersCount: 3,
writableVotingMembersCount: 3,
optimes: {
lastCommittedOpTime: { ts: Timestamp({ t: 1707119443, i: 1 }), t: Long('-1') },
lastCommittedWallTime: ISODate('2024-02-05T07:50:43.235Z'),
readConcernMajorityOpTime: { ts: Timestamp({ t: 1707119443, i: 1 }), t: Long('-1') },
appliedOpTime: { ts: Timestamp({ t: 1707119443, i: 1 }), t: Long('-1') },
durableOpTime: { ts: Timestamp({ t: 1707119443, i: 1 }), t: Long('-1') },
lastAppliedWallTime: ISODate('2024-02-05T07:50:43.235Z'),
lastDurableWallTime: ISODate('2024-02-05T07:50:43.235Z')
},
lastStableRecoveryTimestamp: Timestamp({ t: 1707119443, i: 1 }),
....
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1707119443, i: 1 }),
signature: {
hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0),
keyId: Long('0')
}
},
operationTime: Timestamp({ t: 1707119443, i: 1 })
}
shard_3 server 실행
더보기
# shard_3 server
mongod --config /data/mongodb/conf/shard_3.conf &
# 확인
sudo netstat -nlp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 6022/mongod
unix 2 [ ACC ] STREAM LISTENING 2417 6022/mongod /tmp/mongodb-27017.sock
# mongsh (레플리카셋 구성)
mongosh --port=27017
use admin
rs.initiate( {
_id : "rs3",
members: [
{ _id: 0, host: "10.10.X.187:27017" },
{ _id: 1, host: "10.10.X.188:27017" },
{ _id: 2, host: "10.10.X.189:27017" }
]
})
# 확인
rs.status()
{
set: 'rs3',
date: ISODate('2024-02-05T07:52:47.224Z'),
myState: 2,
term: Long('1'),
syncSourceHost: '10.10.X.189:27017',
syncSourceId: 2,
heartbeatIntervalMillis: Long('2000'),
majorityVoteCount: 2,
writeMajorityCount: 2,
votingMembersCount: 3,
writableVotingMembersCount: 3,
optimes: {
lastCommittedOpTime: { ts: Timestamp({ t: 1707119567, i: 6 }), t: Long('1') },
lastCommittedWallTime: ISODate('2024-02-05T07:52:47.111Z'),
readConcernMajorityOpTime: { ts: Timestamp({ t: 1707119567, i: 6 }), t: Long('1') },
appliedOpTime: { ts: Timestamp({ t: 1707119567, i: 6 }), t: Long('1') },
durableOpTime: { ts: Timestamp({ t: 1707119567, i: 6 }), t: Long('1') },
lastAppliedWallTime: ISODate('2024-02-05T07:52:47.111Z'),
lastDurableWallTime: ISODate('2024-02-05T07:52:47.111Z')
},
lastStableRecoveryTimestamp: Timestamp({ t: 1707119555, i: 1 }),
electionParticipantMetrics: {
votedForCandidate: true,
electionTerm: Long('1'),
lastVoteDate: ISODate('2024-02-05T07:52:46.563Z'),
electionCandidateMemberId: 2,
voteReason: '',
lastAppliedOpTimeAtElection: { ts: Timestamp({ t: 1707119555, i: 1 }), t: Long('-1') },
maxAppliedOpTimeInSet: { ts: Timestamp({ t: 1707119555, i: 1 }), t: Long('-1') },
priorityAtElection: 1,
newTermStartDate: ISODate('2024-02-05T07:52:46.578Z'),
newTermAppliedDate: ISODate('2024-02-05T07:52:47.087Z')
},
....
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1707119567, i: 6 }),
signature: {
hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0),
keyId: Long('0')
}
},
operationTime: Timestamp({ t: 1707119567, i: 6 })
}
user 생성
더보기
# shard 서버
mongosh --port=27017
# config 서버
mongosh --port=27050
#
use admin
admin = db.getSiblingDB("admin")
admin.createUser(
{
user: "admin",
pwd: "admin",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }]
}
)
db.getSiblingDB("admin").createUser(
{
"user" : "clusterAdmin",
"pwd" : "clusterAdmin",
roles: [ { "role" : "clusterAdmin", "db" : "admin" } ]
}
)
mongos server 실행
더보기
# mongos server
mongos --config /data/mongodb/conf/mongos.conf &
# 확인
sudo netstat -nlp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1485/mongos
unix 2 [ ACC ] STREAM LISTENING 31999 1485/mongos /tmp/mongodb-27017.sock
# mongsh (레플리카셋 구성)
mongosh --port=27017
use admin
db.auth("admin","admin")
# addshard
sh.addShard("rs1/10.10.X.181:27017")
sh.addShard("rs2/10.10.X.184:27017")
sh.addShard("rs3/10.10.X.187:27017")
# 확인
sh.status()
shardingVersion
{ _id: 1, clusterId: ObjectId('65c090891d0bee9d6261745a') }
---
shards
[
{
_id: 'rs1',
host: 'rs1/10.10.X.181:27017,10.10.X.182:27017,10.10.X.183:27017',
state: 1,
topologyTime: Timestamp({ t: 1707124359, i: 2 })
},
{
_id: 'rs2',
host: 'rs2/10.10.X.184:27017,10.10.X.185:27017,10.10.X.186:27017',
state: 1,
topologyTime: Timestamp({ t: 1707124817, i: 1 })
},
{
_id: 'rs3',
host: 'rs3/10.10.X.187:27017,10.10.X.188:27017,10.10.X.189:27017',
state: 1,
topologyTime: Timestamp({ t: 1707124828, i: 2 })
}
]
---
active mongoses
[ { '7.0.5': 1 } ]
---
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
[
{
database: { _id: 'config', primary: 'config', partitioned: true },
collections: {
'config.system.sessions': {
shardKey: { _id: 1 },
unique: false,
balancing: true,
chunkMetadata: [ { shard: 'rs1', nChunks: 1 } ],
chunks: [
{ min: { _id: MinKey() }, max: { _id: MaxKey() }, 'on shard': 'rs1', 'last modified': Timestamp({ t: 1, i: 0 }) }
],
tags: []
}
}
}
]
728x90
반응형
'DB' 카테고리의 다른 글
Mongodb Shard Cluster - 구성 고도화 (0) | 2024.02.26 |
---|---|
sharding 테스트 (0) | 2024.02.23 |
Mongodb Shard Cluster 설치 - 1(기본 셋팅 + conf 설정) (0) | 2024.02.23 |
Redis 설치 (1) | 2024.02.04 |
op로그 덤프&&복구 (0) | 2024.02.04 |
Comments