Setting up MongoDB Read Only Replica Set and Write Only Replica Set

2,162 views
Skip to first unread message

Rahsaan Page

unread,
Jul 18, 2011, 11:34:49 AM7/18/11
to mongod...@googlegroups.com
Hello Support Team,

I have a new project to setup a Read only Replica Set and a Write only Replica, i will only be administrating to setup and the developers will do the rest..
My question, if i setup a Read Only Replica Set how will it know about the write only Replica set that will be updating the database?

we are trying to separate reads and write on different mongodb instances, any help will be appreciated..

Scott Hernandez

unread,
Jul 18, 2011, 12:25:50 PM7/18/11
to mongod...@googlegroups.com
There is one writer node in a replicaset, the primary. The other nodes
are read only. If you specify slave_okay in the driver then reads will
come from the secondaries (non-primary).

You might glean more information from reading here:
http://mongodb.org/display/DOCS/Replica+Sets

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/szbS4esXLF4J.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>

Rahsaan Page

unread,
Jul 18, 2011, 1:05:20 PM7/18/11
to mongod...@googlegroups.com
can we dynamically make nodes become primary?

Scott Hernandez

unread,
Jul 18, 2011, 1:39:26 PM7/18/11
to mongod...@googlegroups.com
Sorta, you can dynamically step nodes down a node which is primary.
There is an election process which chooses the primary and you can't
short-circuit that but you can give hints to who to elect:
http://www.mongodb.org/display/DOCS/Forcing+a+Member+to+be+Primary

On Mon, Jul 18, 2011 at 1:05 PM, Rahsaan Page <rahsaa...@gmail.com> wrote:
> can we dynamically make nodes become primary?
>

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/xkZgwst1D-MJ.

Rahsaan Page

unread,
Jul 19, 2011, 8:18:56 PM7/19/11
to mongod...@googlegroups.com
Hi Scott,

I appreciate your help alot, you have pointed me in a good direction.. Question is there any /etc/init.d - scripts for MongoDB?

Scott Hernandez

unread,
Jul 19, 2011, 11:04:24 PM7/19/11
to mongod...@googlegroups.com
Yes, if you install the package from our repo they come with
init/upstart scripts:
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/kN1ppozrM-0J.

Rahsaan Page

unread,
Jul 19, 2011, 11:52:09 PM7/19/11
to mongod...@googlegroups.com
I installed the binaries for Linux 64bit, i am running CentOS.. do these init.d script work with Replica Set?

Scott Hernandez

unread,
Jul 20, 2011, 12:36:46 AM7/20/11
to mongod...@googlegroups.com
You have to configure the settings yourself, but yes. There is nothing
special about a replicaset node except the settings and configuration
-- it is still just a mongod instance.

On Tue, Jul 19, 2011 at 11:52 PM, Rahsaan Page <rahsaa...@gmail.com> wrote:
> I installed the binaries for Linux 64bit, i am running CentOS.. do these
> init.d script work with Replica Set?
>

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/hhxHsRRfneIJ.

Rahsaan Page

unread,
Jul 21, 2011, 4:55:36 PM7/21/11
to mongod...@googlegroups.com
Hi Scott,

where are the config stored for the ReplSet to be remembered?

Scott Hernandez

unread,
Jul 21, 2011, 8:15:02 PM7/21/11
to mongod...@googlegroups.com
They are stored in the local db on each replica but the
config/settings I was referring to were for the init script, and then
the replicaset commands.

On Thu, Jul 21, 2011 at 4:55 PM, Rahsaan Page <rahsaa...@gmail.com> wrote:
> Hi Scott,
> where are the config stored for the ReplSet to be remembered?
>

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/lipdscywW-oJ.

Rahsaan Page

unread,
Jul 27, 2011, 2:01:22 PM7/27/11
to mongod...@googlegroups.com
Hi Scott,

i was working on forcing a member to be primary, i get some error when i followed the following steps:


./mongo 127.0.0.1:27017/admin -u admin -p
MongoDB shell version: 1.8.2
Enter password:
connecting to: 127.0.0.1:27017/admin
MyReplSet:PRIMARY> rs.stepDown(120)
Wed Jul 27 10:31:16 DBClientCursor::init call() failed
Wed Jul 27 10:31:16 query failed : admin.$cmd { replSetStepDown: 120.0 } to: 127.0.0.1:27017
Wed Jul 27 10:31:16 Error: error doing query: failed shell/collection.js:150
Wed Jul 27 10:31:16 trying reconnect to 127.0.0.1:27017
Wed Jul 27 10:31:16 reconnect 127.0.0.1:27017 ok

Scott Hernandez

unread,
Jul 27, 2011, 3:27:45 PM7/27/11
to mongod...@googlegroups.com
Was it an error, or just the primary changing to a secondary and
closing the connections? Did it not step down?

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/mongodb-user/-/CJDmvYR1nw8J.

Abdur Rahman

unread,
Sep 21, 2016, 9:12:26 AM9/21/16
to mongodb-user
Hi Scott, can you please help me out on this "what we want is a read only replica in a different node.. and we can then give access to developers to that node" so this will be feasible...

William Hagan

unread,
Sep 21, 2016, 12:30:34 PM9/21/16
to mongodb-user
Hi,

Secondary nodes are read-only nodes. You may want to have the developers set their query Read Preference to "secondary" while you disable access to the primary unless access is coming from the secondary or some other permitted IP address.

Also consider tag sets to direct queries to specific nodes.

Regards,

Abdur Rahman

unread,
Sep 22, 2016, 1:01:26 PM9/22/16
to mongodb-user
sure thanks a lot  William...
Reply all
Reply to author
Forward
0 new messages