1인 MongodB University 12/21 - 복제품 세트 디자인

이 기록은 달력 형식의 몬godb University 학습 과정을 부가한 기록입니다. 21일째!
현재 진행 중인 노선: M103[1].하루에 3개 정도 챕터2를 진행하고 싶어요.
목표는 25일까지 15 step.
  • 추가 달력 / 1인 MongodB University 준비
  • Chapter 2: Lab: Deploya Replica Set(연습 문제)


    Problem
    Launch a replica set with three members:
    세 개의 던전집을 시작합시다!
  • There are three configuration files in your IDE workspace, but they are incomplete.
  • Update these configuration files so that all three mongod processes:
    authenticate internally using the keyfile/var/mongodb/pki/m103-keyfile
    belong to the replica set m103-repl
    참조 정보를 설정하려면 다음과 같이 하십시오.
  • Deploy a Replica Se
  • https://docs.mongodb.com/manual/tutorial/deploy-replica-set/
  • Deploy Replica Set With Keyfile Authentication
  • https://docs.mongodb.com/manual/tutorial/deploy-replica-set-with-keyfile-access-control/#deploy-repl-set-with-auth
  • Once your configuration files are complete, start a mongod process using one of them.
  • 하나만 시작
  • When this node is running, use the mongo shell to connect and initiate your replica set with rs.initiate(). The shell prompt will read PRIMARY when the election is complete.
  • 포트 27001을 통해 연결!
  • rs.initiate()는 무엇입니까?
  • https://docs.mongodb.com/manual/reference/method/rs.initiate/
  • Initiates a replica set. 복제본 세트를 초기화합니다.
  • Optionally, the method can take an argument in the form of a document that holds the configuration of a replica set.
    - 매개변수를 사용하여 복사본 세트 조정 가능
  • # 接続してみる!
    bash-4.4# mongo --port 27001
    MongoDB shell version v4.0.5
    connecting to: mongodb://127.0.0.1:27001/?gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("5930a10f-7f68-4282-869e-dd14001f66da") }
    MongoDB server version: 4.0.5
    Welcome to the MongoDB shell.
    For interactive help, type "help".
    For more comprehensive documentation, see
            http://docs.mongodb.org/
    Questions? Try the support group
            http://groups.google.com/group/mongodb-user
    >
    
    던전집의 초기화.
    > rs.initiate()
    {
            "info2" : "no configuration specified. Using a default configuration for the set",
            "me" : "localhost:27001",
            "ok" : 1
    }
    
    잡아라.프롬프트에 "PRIMARY"가 표시됩니다!
  • Because the replica set uses a keyfile for internal authentication, clients must authenticate before performing any actions.
  • db.createUser({
      user: "m103-admin",
      pwd: "m103-pass",
      roles: [
        {role: "root", db: "admin"}
      ]
    })
    
    실제 처리.
    # mongo shellのプロンプトが変わりました!
    m103-repl:OTHER>
    
    
    # まずはユーザ作成 (さらにmongo shellのプロンプトが変わりました!)
    m103-repl:PRIMARY> use admin
    switched to db admin
    m103-repl:PRIMARY> db.createUser({
       user: "m103-admin",
       pwd: "m103-pass",
       roles: [
         {role: "root", db: "admin"}
       ]
     })
    Successfully added user: {
            "user" : "m103-admin",
            "roles" : [
                    {
                            "role" : "root",
                            "db" : "admin"
                    }
            ]
    }
    
  • Once m103-admin is created, exit the mongo shell and start the other two mongod processes with their respective configuration files.
  • # 残り2つ起動
    bash-4.4# mongod -f mongod_2.conf
    bash-4.4# mongod -f mongod_3.conf
    
    bash-4.4# netstat -a
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State
    tcp        0      0 localhost:27001         0.0.0.0:*               LISTEN
    tcp        0      0 localhost:27002         0.0.0.0:*               LISTEN
    tcp        0      0 localhost:27003         0.0.0.0:*               LISTEN
    tcp        0      0 localhost:53672         localhost:27001         TIME_WAIT
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags       Type       State         I-Node Path
    unix  3      [ ]         DGRAM                    1150502782 /dev/log
    unix  2      [ ACC ]     STREAM     LISTENING     1150659984 /tmp/mongodb-27002.sock
    unix  2      [ ACC ]     STREAM     LISTENING     1150573201 /tmp/mongodb-27001.sock
    unix  2      [ ACC ]     STREAM     LISTENING     1150658340 /tmp/mongodb-27003.sock
    unix  2      [ ]         DGRAM                    1150502814
    bash-4.4#
    
  • Reconnect to your primary node as m103-admin and add the other two nodes to your replica set using rs.add().
  • 마스터 노드에 재접속하고 복제본 세트에 추가
  • rs.add()
  • Ref. https://docs.mongodb.com/manual/reference/method/rs.add/index.html
  • Adds a member to a replica set. To run the method, you must connect to the primary of the replica set.
  • 던전집을 추가한 구성원
  • 복제본 세트의 주요 섹션에 연결해야 함
  • rs.add(host, arbiterOnly)
  • bash-4.4# mongo --port 27001 -u m103-admin -p m103-pass
    
    ---
    
    # primaryに接続
    m103-repl:PRIMARY>
    m103-repl:PRIMARY> rs.add( { host: "localhost:27002" } )
    {
            "ok" : 1,
            "operationTime" : Timestamp(1608562007, 1),
            "$clusterTime" : {
                    "clusterTime" : Timestamp(1608562007, 1),
                    "signature" : {
                            "hash" : BinData(0,"CjAYCI3CxKlruG818lnvta3FkdU="),
                            "keyId" : NumberLong("6908718490643857410")
                    }
            }
    }
    
    m103-repl:PRIMARY>
    m103-repl:PRIMARY> rs.add( { host: "localhost:27003" } )
    {
            "ok" : 1,
            "operationTime" : Timestamp(1608562027, 1),
            "$clusterTime" : {
                    "clusterTime" : Timestamp(1608562027, 1),
                    "signature" : {
                            "hash" : BinData(0,"ih1GVxuhUrGc4nL6Zz0K5uCtGs8="),
                            "keyId" : NumberLong("6908718490643857410")
                    }
            }
    }
    
    포획은 이런 느낌이에요.
  • Once your other two members have been successfully added, run rs.status() to check that the members array has three nodes - one labeled PRIMARY and two labeled SECONDARY.
  • 주요 연결 상태에서 결과 확인!
    "stateStar"확인: "SECONDARY"2개 "stateStar": "PRIMARY"1개!
    m103-repl:PRIMARY> rs.status()
    {
            "set" : "m103-repl",
            "date" : ISODate("2020-12-21T14:48:05.453Z"),
            "myState" : 1,
            "term" : NumberLong(1),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "heartbeatIntervalMillis" : NumberLong(2000),
            "optimes" : {
                    "lastCommittedOpTime" : {
                            "ts" : Timestamp(1608562083, 1),
                            "t" : NumberLong(1)
                    },
                    "readConcernMajorityOpTime" : {
                            "ts" : Timestamp(1608562083, 1),
                            "t" : NumberLong(1)
                    },
                    "appliedOpTime" : {
                            "ts" : Timestamp(1608562083, 1),
                            "t" : NumberLong(1)
                    },
                    "durableOpTime" : {
                            "ts" : Timestamp(1608562083, 1),
                            "t" : NumberLong(1)
                    }
            },
            "lastStableCheckpointTimestamp" : Timestamp(1608562027, 1),
            "members" : [
                    {
                            "_id" : 0,
                            "name" : "localhost:27001",
                            "health" : 1,
                            "state" : 1,
                            "stateStr" : "PRIMARY",
                            "uptime" : 986,
                            "optime" : {
                                    "ts" : Timestamp(1608562083, 1),
                                    "t" : NumberLong(1)
                            },
                            "optimeDate" : ISODate("2020-12-21T14:48:03Z"),
                            "syncingTo" : "",
                            "syncSourceHost" : "",
                            "syncSourceId" : -1,
                            "infoMessage" : "",
                            "electionTime" : Timestamp(1608561372, 2),
                            "electionDate" : ISODate("2020-12-21T14:36:12Z"),
                            "configVersion" : 3,
                            "self" : true,
                            "lastHeartbeatMessage" : ""
                    },
                    {
                            "_id" : 1,
                            "name" : "localhost:27002",
                            "health" : 1,
                            "state" : 2,
                            "stateStr" : "SECONDARY",
                            "uptime" : 77,
                            "optime" : {
                                    "ts" : Timestamp(1608562083, 1),
                                    "t" : NumberLong(1)
                            },
                            "optimeDurable" : {
                                    "ts" : Timestamp(1608562083, 1),
                                    "t" : NumberLong(1)
                            },
                            "optimeDate" : ISODate("2020-12-21T14:48:03Z"),
                            "optimeDurableDate" : ISODate("2020-12-21T14:48:03Z"),
                            "lastHeartbeat" : ISODate("2020-12-21T14:48:05.065Z"),
                            "lastHeartbeatRecv" : ISODate("2020-12-21T14:48:04.089Z"),
                            "pingMs" : NumberLong(0),
                            "lastHeartbeatMessage" : "",
                            "syncingTo" : "localhost:27001",
                            "syncSourceHost" : "localhost:27001",
                            "syncSourceId" : 0,
                            "infoMessage" : "",
                            "configVersion" : 3
                    },
                    {
                            "_id" : 2,
                            "name" : "localhost:27003",
                            "health" : 1,
                            "state" : 2,
                            "stateStr" : "SECONDARY",
                            "uptime" : 58,
                            "optime" : {
                                    "ts" : Timestamp(1608562083, 1),
                                    "t" : NumberLong(1)
                            },
                            "optimeDurable" : {
                                    "ts" : Timestamp(1608562083, 1),
                                    "t" : NumberLong(1)
                            },
                            "optimeDate" : ISODate("2020-12-21T14:48:03Z"),
                            "optimeDurableDate" : ISODate("2020-12-21T14:48:03Z"),
                            "lastHeartbeat" : ISODate("2020-12-21T14:48:05.066Z"),
                            "lastHeartbeatRecv" : ISODate("2020-12-21T14:48:04.338Z"),
                            "pingMs" : NumberLong(0),
                            "lastHeartbeatMessage" : "",
                            "syncingTo" : "localhost:27001",
                            "syncSourceHost" : "localhost:27001",
                            "syncSourceId" : 0,
                            "infoMessage" : "",
                            "configVersion" : 3
                    }
            ],
            "ok" : 1,
            "operationTime" : Timestamp(1608562083, 1),
            "$clusterTime" : {
                    "clusterTime" : Timestamp(1608562083, 1),
                    "signature" : {
                            "hash" : BinData(0,"rXS8Wjw1L/KN/HVCUX4TCVdDm9Y="),
                            "keyId" : NumberLong("6908718490643857410")
                    }
            }
    }
    
  • Click "Run Tests"to run a suite of tests that will check the configuration of your replica set. The results of these tests will let you know which steps you've yet to complete.
  • 테스트 실행.
    다행이다!!!!통과했어!!!!!

    복습할 필요가 있었지만 드디어 통과했어!

    오늘의 진전


    단 하나, 훈련 문제 완성.
    처음으로 복제품 세트 시작!

    오늘의 젠.


    계속 같은 방법으로 진행되고 있다.
    업데이트된 통지가 왔다.감사합니다!!
    각주
    M103: Basic Cluster Administration세트.수업을 시작하면 이수까지의 기한은 두 달 이내이다.↩︎

    좋은 웹페이지 즐겨찾기