replica set 롤링 유지보수 (재시작, OS 패치, 마이너 업그레이드)
MongoDBReplica Set명령어
// 1) Before starting: all members healthy, low lag, and an oplog window longer than the maintenance
rs.printSecondaryReplicationInfo()
// 2) Clean shutdown on the SECONDARY under maintenance (then OS/binary work, restart with the same config):
db.getSiblingDB("admin").shutdownServer({ timeoutSecs: 60 })
// 3) Wait until the member is SECONDARY and lag has closed, then move to the next secondary:
rs.status().members.map(m => ({ host: m.name, state: m.stateStr, health: m.health }))
// 4) When all secondaries are done, on the PRIMARY: hand over to a secondary that catches up within 30 s
rs.stepDown(120, 30)
// 5) The old primary is now a SECONDARY: apply steps 2 and 3 to it하는 일
secondary를 먼저, primary를 마지막으로 하여 멤버를 하나씩 유지보수에 들이는 순서를 제공한다. set을 서비스에서 빼지 않고 재시작, OS 패치, 바이너리 업데이트를 수행한다.
사용 시점
계획된 OS/커널 업데이트, 마이너 버전 업그레이드, mongod 파라미터 변경, 디스크/하드웨어 유지보수 시.
주의
한 번에 둘 이상의 멤버를 종료하지 않는다. 3멤버 set에서 두 멤버를 잃으면 과반수를 잃는다. 각 멤버 후 SECONDARY 상태와 지연 해소를 확인한다. stepDown은 짧은 쓰기 중단을 일으키므로 드라이버가 retryable writes로 재연결하는지 확인한다. arbiter가 있으면 같은 순서로 처리한다.