Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaffarc/6c815f2d28d29581cc6cd07e9be2c0b5 to your computer and use it in GitHub Desktop.
Save jaffarc/6c815f2d28d29581cc6cd07e9be2c0b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @davisford davisford renamed this gist Dec 21, 2018. 1 changed file with 0 additions and 0 deletions.
  2. @davisford davisford revised this gist Mar 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion instructions.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ replication:
    Restart mongod (I use brew):

    ```sh
    $ brew services mongodb restart
    $ brew services restart mongodb
    ```

    Connect with local mongo shell and initiate the replica set:
  3. @davisford davisford revised this gist Jan 6, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions instructions.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,12 @@ replication:
    replSetName: replocal
    ```

    Restart mongod (I use brew):

    ```sh
    $ brew services mongodb restart
    ```

    Connect with local mongo shell and initiate the replica set:

    ```
  4. @davisford davisford renamed this gist Jan 6, 2017. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions gistfile1.txt → instructions.md
    Original file line number Diff line number Diff line change
    @@ -15,15 +15,19 @@ replication:
    replSetName: replocal
    ```

    Connect with local mongo shell:
    Connect with local mongo shell and initiate the replica set:

    ```
    $mongo
    MongoDB shell version: 3.2.9
    connecting to: test
    > rs.initiate({_id: "replocal", members: [{_id: 0, host: "127.0.0.1:27017"}] })
    { "ok" : 1 }
    ```

    Now you'll be secondary, but then it will promote you to primary since you're the only one:

    ```
    replocal:SECONDARY> rs.status
    function () {
    return db._adminCommand("replSetGetStatus");
    @@ -67,4 +71,6 @@ You can tail the oplog at
    replocal:PRIMARY> use local
    switched to db local
    replocal:PRIMARY> db.getCollection('oplog.rs').find()
    ```
    ```

    ...lots of output here
  5. @davisford davisford created this gist Jan 6, 2017.
    70 changes: 70 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    Add the `replication` section to the mongod.conf file:

    ```
    $cat /usr/local/etc/mongod.conf
    systemLog:
    destination: file
    path: /usr/local/var/log/mongodb/mongo.log
    logAppend: true
    storage:
    engine: mmapv1
    dbPath: /usr/local/var/repl-emagine-data
    net:
    bindIp: 127.0.0.1
    replication:
    replSetName: replocal
    ```

    Connect with local mongo shell:

    ```
    $mongo
    MongoDB shell version: 3.2.9
    connecting to: test
    > rs.initiate({_id: "replocal", members: [{_id: 0, host: "127.0.0.1:27017"}] })
    { "ok" : 1 }

    replocal:SECONDARY> rs.status
    function () {
    return db._adminCommand("replSetGetStatus");
    }

    replocal:PRIMARY> rs.status()
    {
    "set" : "replocal",
    "date" : ISODate("2017-01-06T16:16:27.323Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
    {
    "_id" : 0,
    "name" : "127.0.0.1:27017",
    "health" : 1,
    "state" : 1,
    "stateStr" : "PRIMARY",
    "uptime" : 2022,
    "optime" : {
    "ts" : Timestamp(1483719372, 1),
    "t" : NumberLong(1)
    },
    "optimeDate" : ISODate("2017-01-06T16:16:12Z"),
    "infoMessage" : "could not find member to sync from",
    "electionTime" : Timestamp(1483719371, 2),
    "electionDate" : ISODate("2017-01-06T16:16:11Z"),
    "configVersion" : 1,
    "self" : true
    }
    ],
    "ok" : 1
    }

    ```

    You can tail the oplog at

    ```
    replocal:PRIMARY> use local
    switched to db local
    replocal:PRIMARY> db.getCollection('oplog.rs').find()
    ```