Replica set setup with chef


#1

Is anyone doing Mongo sharding or replica sets with chef? As far as I can
tell, you need to run some commands interactively (ie. rs.initialize) in
the mongo shell to initialize a replica set. I think I could probably do
this with chef by piping the commands directly to the shell, but is there an
easier way? Some kind of config file settings I could use? Otherwise, I need
to wait for the server to come up, send it the command, and then hope that
everything works.

Thanks,
Micah


#2

We’re using mongo replica sets with chef but, like you, don’t yet have a
good solution for initializing the replica set. I was headed down the
path of having chef create a .js file that could be passed into mongo
shell. I’d be interested in seeing what you’ve come up with though.
Perhaps we could collaborate on a solution?

Here’s a link to our mongodb cookbook -
https://github.com/customink/cookbooks

Thanks,
Nathen

On 1/21/11 6:49 PM, Micah Wedemeyer wrote:

Is anyone doing Mongo sharding or replica sets with chef? As far as I
can tell, you need to run some commands interactively (ie.
rs.initialize) in the mongo shell to initialize a replica set. I
think I could probably do this with chef by piping the commands
directly to the shell, but is there an easier way? Some kind of config
file settings I could use? Otherwise, I need to wait for the server to
come up, send it the command, and then hope that everything works.

Thanks,
Micah


#3

Hello, Micah.

On Jan 21, 2011, at 6:49 PM, Micah Wedemeyer wrote:

Is anyone doing Mongo sharding or replica sets with chef?
You may be interested in some code from a mongoDB recipe we have used at Aranetic. Within our mongoDB cookbook, the regular default.rb recipe file takes care of the usual business of installing the software and writing the replica set name into the config file. That’s the easy part.

Otherwise, I need to wait for the server to come up, send it the command, and then hope that everything works.
Exactly. As you say, the tricky part is waiting for the server to come up (which can take a LONG time, depending on the size of the data you’re replicating, and your disk speed), and then sending the proper commands needed to establish replication. One wrinkle is that establishing the server as a slave involves contacting the master, and altering its configuration directly. To determine which nodes might be the master, this recipe searches the Chef server for all existing nodes with the same attribute vale [:mongodb][:repl_set].

The following code attempts to do all of that, in the context of a Chef recipe:
https://gist.github.com/793295

One thing this recipe does NOT do is to remove no-longer-reachable nodes from the master’s replication config. Another is sharding. Further collaboration on both aspects is welcome.

Good luck,

  • benton

Benton Roberts
benton@bentonroberts.com
PGP Key ID 0x133E098F