[MongoDB] replicaset priority 설정

Seunghyun Moon·2022년 10월 26일
0

database

목록 보기
4/5

rs 최초 생성 시priority 를 정해주지 않았을 때

조치방법

ReplicaSet 멤버의 property 중에 priority 라는 것이 있는데, PRIMARY를 선출할 때 영향을 미치는 요소이다.

(priority가 높은 멤버가 PRIMARY로 선출된다)

 

priority는 0부터 1000까지의 부동소수점 값이고, 기본값은 1이다.

 

compaction 등을 위해 ReplicaSet 멤버서버를 내렸다 올렸다 하다보면 PRIMARY가 지 맘대로 될텐데,

언제나 항상 내가 지정한 서버만 PRIMARY이길 원한다면 해당 서버의 priority를 높게 설정해주면 된다.

 

만약 현재 PRIMARY가 아닌 서버를 PRIMARY로 만들기 위해 priority를 재설정한다면,

priority를 재설정한 직후에 바로 PRIMARY 선출이 일어나므로 주의가 필요함.

// ReplicaSet 설정확인.

// priority가 설정되어 있지 않으므로 내렸다 올렸다 하다보면 누가 PRIMARY가 될지 알 수 없다.

shard_001:PRIMARY> rs.conf()

{

    "_id" : "shard_001",

    "version" : "3",

    "members" : [

        {

            "_id" : 0,

            "host" : "shard-001-primary.bloodguy.com:27018"

        },

        {

            "_id" : 1,

            "host" : "shard-001-secondary.bloodguy..com:27018"

        },

        {

            "_id" : 2,

            "host" : "shard-001-arbiter.bloodguy.com:27018",

            "arbiterOnly" : true

        }

    ]

}

 

// 설정을 변수로 복사

shard_001:PRIMARY> cfg = rs.conf()

 

// 항상 PRIMARY로 세팅할 서버의 priority를 설정

shard_001:PRIMARY> cfg.members[0].priority = 2

 

// 재설정

shard_001:PRIMARY> rs.reconfig(cfg)

 

// 확인

shard_001:PRIMARY> rs.conf()

{

    "_id" : "shard_001",

    "version" : 4,

    "members" : [

        {

            "_id" : 0,

            "host" : "shard-001-primary.bloodguy.com:27018",

            // priority가 세팅되었으므로 이 서버가 살아있기만 하면 PRIMARY로 설정됨

            "priority" : 2

        },

        {

            "_id" : 1,

            "host" : "shard-001-secondary.bloodguy.com:27018"

        },

        {

            "_id" : 2,

            "host" : "shard-001-arbiter.bloodguy.com:27018",

            "arbiterOnly" : true

        }

    ]

}
profile
I live fullest

0개의 댓글