Forked from leommoore/mongodb_setting_up_a_replica_set.md
Last active
August 29, 2015 14:17
-
-
Save dhatawesomedude/0e52fe90b8c5d8367ee2 to your computer and use it in GitHub Desktop.
Revisions
-
leommoore revised this gist
May 29, 2014 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,8 @@ You need to connect to one of the database sets and setup the configuration. The ###Initialize the Replica Set The rs stands for replica set. rs.initiate(demoConfig) Please note that this can take some time to setup the databases initially. When it is complete it will return back: @@ -83,4 +85,10 @@ You may get an initial error ```error: { "$err" : "not master and slaveOk=false" You should then be able to access the data. ###Replica Set Status To check on the status of a replica set just use: rs.status()
-
leommoore revised this gist
May 29, 2014 . 1 changed file with 16 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,22 @@ ###Configuration You need to connect to one of the database sets and setup the configuration. The mongo client is a javascript repl so you can do all the usual javascript commands. var demoConfig = { _id: "demo", members: [ { _id: 0, host: 'localhost: 30000', priority: 10 }, { _id: 1, host: 'localhost: 40000' }, { _id: 2, host: 'localhost: 50000', arbiterOnly: true } ] }; ###Initialize the Replica Set -
leommoore revised this gist
May 29, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ db.getMongo() ###Configuration You need to connect to one of the database sets and setup the configuration. The mongo client is a javascript repl so you can do all the usual javascript commands. var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] }; -
leommoore revised this gist
Sep 28, 2013 . 1 changed file with 30 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,4 +38,33 @@ Please note that this can take some time to setup the databases initially. When The prompt will change to ```demo:PRIMARY>```. ###Test To test add some data to the primary: db.foo.save({_id:1, value:'hello world'}) Check that the data is saved on the primary: db.foo.find() This will return: { "_id" : 1, "value" : "hello world" } Then log onto the secondary. This will have a prompt of ```demo:SECONDARY>```. db.foo.find() This will return: { "_id" : 1, "value" : "hello world" } ####Error not master and slaveOk=false You may get an initial error ```error: { "$err" : "not master and slaveOk=false", "code" : 13435 }``` when you are trying to run ```db.foo.find()```. This is because the secondary (ie the Slave) is not setup to perform reads. This can be enabled using the following command: db.setSlaveOk() You should then be able to access the data.
-
leommoore revised this gist
Sep 28, 2013 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,4 +26,16 @@ ###Initialize the Replica Set rs.initiate(demoConfig) Please note that this can take some time to setup the databases initially. When it is complete it will return back: { "info" : "Config now saved locally. Should come online in about a minute.", "ok" : 1 } The prompt will change to ```demo:PRIMARY>```. ###Test To t -
leommoore revised this gist
Sep 28, 2013 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #MongoDB - Setting up a Replica Set cd \mongodbdir\ @@ -20,4 +20,10 @@ db.getMongo() ###Configuration var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] }; ###Initialize the Replica Set rs.initiate(demoConfig) -
leommoore renamed this gist
Sep 28, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
leommoore revised this gist
Sep 28, 2013 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,22 +2,22 @@ cd \mongodbdir\ mkdir db1 mkdir db2 mkdir db3 ###Primary mongod --dbpath ./db1 --port 30000 --replSet "demo" ###Secondary mongod --dbpath ./db2 --port 40000 --replSet "demo" ###Arbiter mongod --dbpath ./db3 --port 50000 --replSet "demo" mongo --port 3000 db.getMongo() var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] }; -
leommoore revised this gist
Sep 28, 2013 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,23 @@ #MongoDB - Setting up a cluster cd \mongodbdir\ md \\mongodbdir\db1 md \\mongodbdir\db2 md \\mongodbdir\db3 ###Primary start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo" ###Secondary start "b" mongod --dbpath ./db2 --port 40000 --replSet "demo" ###Arbiter start "c" mongod --dbpath ./db3 --port 50000 --replSet "demo" mongo --port 3000 db.getMongo() var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly}] }; -
leommoore revised this gist
Sep 28, 2013 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ #MongoDB - Setting up a cluster cd \mongodbdir\ md \\mongodbdir\db1 md \\mongodbdir\db2 md \\mongodbdir\db3 -
leommoore created this gist
Sep 28, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ cd \mongodbdir\ #MongoDB - Setting up a cluster md \\mongodbdir\db1 md \\mongodbdir\db2 md \\mongodbdir\db3 @REM Primary start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo" @REM Secondary start "b" mongod --dbpath ./db2 --port 40000 --replSet "demo" @REM Arbiter start "c" mongod --dbpath ./db3 --port 50000 --replSet "demo" mongo --port 3000 db.getMongo() var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly}] };