mongodb 단일 노드 던전 집합 중재 추가

9097 단어

서버 정보


ip
계통
프로비저닝
서비스
카탈로그
172.24.32.201
centos7.7
2c4g
mongo-primary
/var/lib/mongo (the data directory)/var/log/mongodb (the log directory)
172.24.32.201
centos7.7
2c4g
mongo-secondary
/var/lib/mongo27018 (the data directory)/var/log/mongodb27018 (the log directory)
172.24.32.201
centos7.7
2c4g
mongo-abiter
/var/lib/mongo27019 (the data directory)/var/log/mongodb27019 (the log directory)
새로운 몬고 실례를 만듭니다. 27019, 구체적인 문서는 몬고 단점을 참고하여 단일 노드 던전으로 업그레이드합니다. 여기에 직접 지령을 붙입니다.
mkdir -p /var/log/mongodb27019/
mkdir -p /var/lib/mongo27019
chown mongod:mongod /var/log/mongodb27019/ &&chmod 0755 /var/log/mongodb27019/
chown mongod:mongod /var/lib/mongo27019/ &&chmod 0755 /var/lib/mongo27019/

-------------------------------------------------------------------------
cat >>/etc/mongod27019.conf<>/usr/lib/systemd/system/mongod27019.service<

시작 및 켜기 시작
systemctl daemon-reload
systemctl start mongod27019
systemctl enable mongod27019


중재 추가


mongo27017(primary 노드) 진입
중재 추가
rs.addArb('172.24.32.201:27019')

결과는 다음과 같습니다.
lugotestrepl:PRIMARY> db.auth('admin','test123')
1
lugotestrepl:PRIMARY> rs.addArb('172.24.32.201:27019')
{ "ok" : 1 }


복사본 세트 토폴로지 구조 보기
rs.status()
lugotestrepl:PRIMARY> rs.status()
{
    "set" : "lugotestrepl",
    "date" : ISODate("2020-05-14T08:10:49.745Z"),
    "myState" : 1,
    "term" : NumberLong(2),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1589443843, 1),
            "t" : NumberLong(2)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1589443843, 1),
            "t" : NumberLong(2)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1589443843, 1),
            "t" : NumberLong(2)
        }
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "172.24.32.201:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 3989,
            "optime" : {
                "ts" : Timestamp(1589443843, 1),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-14T08:10:43Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1589439871, 1),
            "electionDate" : ISODate("2020-05-14T07:04:31Z"),
            "configVersion" : 3,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "172.24.32.201:27018",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 3978,
            "optime" : {
                "ts" : Timestamp(1589443843, 1),
                "t" : NumberLong(2)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1589443843, 1),
                "t" : NumberLong(2)
            },
            "optimeDate" : ISODate("2020-05-14T08:10:43Z"),
            "optimeDurableDate" : ISODate("2020-05-14T08:10:43Z"),
            "lastHeartbeat" : ISODate("2020-05-14T08:10:49.635Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-14T08:10:49.672Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "172.24.32.201:27017",
            "syncSourceHost" : "172.24.32.201:27017",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 3
        },
        {
            "_id" : 2,
            "name" : "172.24.32.201:27019",
            "health" : 1,
            "state" : 7,
            "stateStr" : "ARBITER",
            "uptime" : 78,
            "lastHeartbeat" : ISODate("2020-05-14T08:10:49.635Z"),
            "lastHeartbeatRecv" : ISODate("2020-05-14T08:10:46.739Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "configVersion" : 3
        }
    ],
    "ok" : 1
}


데이터 가용성 확인, 데이터 삽입, 모든 데이터 보기
lugotestrepl:PRIMARY> use lugotest;
switched to db lugotest
lugotestrepl:PRIMARY> db.auth('lugo','test123')
1
lugotestrepl:PRIMARY> show collections;
movie
lugotestrepl:PRIMARY> db.movie.insert({"moviename":" ","points":"9.0"});

보기
lugotestrepl:PRIMARY> db.movie.find().pretty()
{
    "_id" : ObjectId("5ebbbca5692adbface98b2af"),
    "moviename" : " ",
    "points" : "9.5"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b0"),
    "moviename" : " ",
    "points" : "9.2"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b1"),
    "moviename" : " ",
    "points" : "9.9"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b2"),
    "moviename" : " ",
    "points" : "9.1"
}
{
    "_id" : ObjectId("5ebcff34df72ed1bb0505234"),
    "moviename" : " ",
    "points" : "9.0"
}


secondary 노드로 데이터 보기
lugotestrepl:SECONDARY> rs.slaveOk();
lugotestrepl:SECONDARY> db.auth('lugo','test123')
1
lugotestrepl:SECONDARY> db.movie.find().pretty()
{
    "_id" : ObjectId("5ebbbca5692adbface98b2af"),
    "moviename" : " ",
    "points" : "9.5"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b0"),
    "moviename" : " ",
    "points" : "9.2"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b1"),
    "moviename" : " ",
    "points" : "9.9"
}
{
    "_id" : ObjectId("5ebbbca5692adbface98b2b2"),
    "moviename" : " ",
    "points" : "9.1"
}
{
    "_id" : ObjectId("5ebcff34df72ed1bb0505234"),
    "moviename" : " ",
    "points" : "9.0"
}


데이터 일치

좋은 웹페이지 즐겨찾기