Running replication on Mongo DB issues

3,217 views
Skip to first unread message

ad

unread,
Mar 13, 2012, 9:35:44 AM3/13/12
to mongod...@googlegroups.com
Hi All,

I am new to mongo and am trying the code example given in the tutorail on Mongo site but am facing the issue below. According to the tutorial it should be fairly simple.
But i am getting  --replSet error even though I have given it while creating a host. I am developing on a standalone machine with fedora linux.
Also can some one tell me how do I reset/remove the host once they are assigned.

[root@localhost data]#  mongod --replSet cluster1 --port 27019 --dbpath /data/r2
Tue Mar 13 18:40:40 
Tue Mar 13 18:40:40 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Mar 13 18:40:40 
Tue Mar 13 18:40:40 [initandlisten] MongoDB starting : pid=9849 port=27019 dbpath=/data/r2 32-bit host=localhost.localdomain
Tue Mar 13 18:40:40 [initandlisten] 
Tue Mar 13 18:40:40 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Mar 13 18:40:40 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Mar 13 18:40:40 [initandlisten] **       with --journal, the limit is lower
Tue Mar 13 18:40:40 [initandlisten] 
Tue Mar 13 18:40:40 [initandlisten] db version v2.0.3, pdfile version 4.5
Tue Mar 13 18:40:40 [initandlisten] git version: 05bb8aa793660af8fce7e36b510ad48c27439697
Tue Mar 13 18:40:40 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_41
Tue Mar 13 18:40:40 [initandlisten] options: { dbpath: "/data/r2", port: 27019, replSet: "cluster1" }
Tue Mar 13 18:40:40 [initandlisten] waiting for connections on port 27019
Tue Mar 13 18:40:40 [websvr] admin web console waiting for connections on port 28019
Tue Mar 13 18:40:40 [initandlisten] connection accepted from 127.0.0.1:56898 #1
Tue Mar 13 18:40:40 [rsStart] replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
Tue Mar 13 18:40:40 [rsStart] replSet info you may need to run replSetInitiate -- rs.initiate() in the shell -- if that is not already done
Tue Mar 13 18:40:50 [rsStart] replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
^CTue Mar 13 18:41:00 [rsStart] replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
Tue Mar 13 18:41:00 got kill or ctrl c or hup signal 2 (Interrupt), will terminate after current cmd ends
Tue Mar 13 18:41:00 [interruptThread] now exiting
Tue Mar 13 18:41:00 dbexit: 
Tue Mar 13 18:41:00 [interruptThread] shutdown: going to close listening sockets...
Tue Mar 13 18:41:00 [interruptThread] closing listening socket: 6
Tue Mar 13 18:41:00 [interruptThread] closing listening socket: 8
Tue Mar 13 18:41:00 [interruptThread] closing listening socket: 9
Tue Mar 13 18:41:00 [interruptThread] removing socket file: /tmp/mongodb-27019.sock
Tue Mar 13 18:41:00 [interruptThread] shutdown: going to flush diaglog...
Tue Mar 13 18:41:00 [interruptThread] shutdown: going to close sockets...
Tue Mar 13 18:41:00 [interruptThread] shutdown: waiting for fs preallocator...
Tue Mar 13 18:41:00 [interruptThread] shutdown: closing all files...
Tue Mar 13 18:41:00 [interruptThread] closeAllFiles() finished
Tue Mar 13 18:41:00 [interruptThread] shutdown: removing fs lock...
Tue Mar 13 18:41:00 [conn1] end connection 127.0.0.1:56898
Tue Mar 13 18:41:00 dbexit: really exiting now
[root@localhost data]# mongo myhost:27017
MongoDB shell version: 2.0.3
connecting to: myhost:27017/test
Tue Mar 13 18:41:13 getaddrinfo("myhost") failed: Name or service not known
Tue Mar 13 18:41:13 Error shell/mongo.js:86
exception: connect failed
[root@localhost data]# mongo localhost:27017
MongoDB shell version: 2.0.3
connecting to: localhost:27017/test
> config = {_id: 'cluster1', members: [
...                           {_id: 0, host: 'myhost1:27017'},
...                           {_id: 1, host: 'myhost2:27018'},
...                           {_id: 2, host: 'myhost3:27019'}]
... }
{
"_id" : "cluster1",
"members" : [
{
"_id" : 0,
"host" : "myhost1:27017"
},
{
"_id" : 1,
"host" : "myhost2:27018"
},
{
"_id" : 2,
"host" : "myhost3:27019"
}
]
}
> rs.initiate(config);
{ "errmsg" : "server is not running with --replSet", "ok" : 0 }
> exit
bye


Thanks

Nat

unread,
Mar 13, 2012, 9:40:37 AM3/13/12
to mongod...@googlegroups.com
if you have only one machine and you want to try out replicaset, follow the step from this tutorial.

You should, by the way, use 64-bit version of mongo on 64-bit operating system though. Otherwise, you will run into 32-bit limit pretty quickly.

ad

unread,
Mar 13, 2012, 11:40:02 AM3/13/12
to mongod...@googlegroups.com
Hi, 
It is the same tutorails I have followed. But I am getting an error here, also I was aware of the 32 bit limitation but its not important here since I am just testing it out on my 
local machine. Also I tries it out on a 64 bit and got the same error.
So please let me know whats is wrong. If anyone has tries this tutorial and faced the same problem.

Thanks

Marc

unread,
Mar 13, 2012, 2:24:33 PM3/13/12
to mongodb-user
When creating a replica set locally, you must use
localhost:port_number in the "host" field of the configuration file.
From your output, "myhost" is unrecognized, which is most likely where
the issue lies.

Here are the steps that you can follow to get your replica set up and
running localy:

Create your three data directories: /data/r1, /data/r2, and /data/r3.
If they already exist, make sure they are empty; we will create the
replica set from scratch. (I imagine that because you are just
testing, you do not have any valuable data in these folders, but if
you do, please relocate the files, instead of deleting them!)

In a terminal, start up the first mongod:

$ ./mongod --replSet mySet --dbpath /data/r1 --port 27017 --oplogSize
700

Adding --oplogSize 700 will limit the size of the oplog for each
mongod to 700MB, instead of taking up the default 5% of the free disk
space on the volume.
More data on the oplog may be found here: http://www.mongodb.org/display/DOCS/Replica+Sets+-+Oplog

When you start each Replica set member, you should get log messages
like this:
Tue Mar 13 13:33:06 [rsStart] replSet can't get local.system.replset
config from self or any seed (EMPTYCONFIG)
Tue Mar 13 13:33:06 [rsStart] replSet info you may need to run
replSetInitiate -- rs.initiate() in the shell -- if that is not
already done

This is expected.

Now open up two new terminal windows and start up the other mongo
instances, one process per window. Be sure to change the dbpath and
port variables appropriately

$ ./mongod --replSet mySet --dbpath /data/r2 --port 27018 --oplogSize
700

$ ./mongod --replSet mySet --dbpath /data/r3 --port 27019 --oplogSize
700

You now have three mongod processes up and running, but the Repica set
is not yet configured.

In a fourth terminal window, start mongo, and connect to the first
process that was started. In mongo, port 27017 is the default port,
but I have included it just to be explicit, in case any other users
may be following this example and using different port numbers.

$ ./mongo --port 27017
MongoDB shell version: 2.0.2
connecting to: 127.0.0.1:27017/test
>

Now we create our config object as per the documentation: Be sure to
keep the _id the same as the value for --replSet that you started all
of the mongod processes with:

> cfg = {
_id : "mySet",
members : [
{ _id : 0, host : "localhost:27017" },
{ _id : 1, host : "localhost:27018" },
{ _id : 2, host : "localhost:27019" } ] }

Now, initiate the replica set with this configuration document:

> rs.initiate(cfg)
{
"info" : "Config now saved locally. Should come online in about a
minute.",
"ok" : 1
}
> # At this point, a simple ">" is returned. Hitting "return" a few times should cause ">" to change to "PRIMARY>", indicating that mongo is connected to the Primary member of a replica set. We can then run rs.status() to see the configuration of our replica set.

PRIMARY> rs.status()
{
"set" : "mySet",
"date" : ISODate("2012-03-13T18:08:08Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1331662006000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-13T18:06:46Z"),
"self" : true
},
{
"_id" : 1,
"name" : "localhost:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 79,
"optime" : {
"t" : 1331662006000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-13T18:06:46Z"),
"lastHeartbeat" : ISODate("2012-03-13T18:08:07Z"),
"pingMs" : 0
},
{
"_id" : 2,
"name" : "localhost:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 79,
"optime" : {
"t" : 1331662006000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-13T18:06:46Z"),
"lastHeartbeat" : ISODate("2012-03-13T18:08:07Z"),
"pingMs" : 267583
}
],
"ok" : 1
}
PRIMARY>

Hopefully, this will clear up any ambiguities in the tutorial, and get
you up and running with a locally running replica set that you can
experiment with.

For more information on replica sets, please see the "Replica Set
Configuration" documentation: http://www.mongodb.org/display/DOCS/Replica+Set+Configuration

Please also see the documentation titled "Replica Set Commands":
http://www.mongodb.org/display/DOCS/Replica+Set+Commands

This contains information on the rs.add() and rs.remove() methods,
which allow you to add and remove members as per your original
question.

Please let us know if you run into any difficulties or have any
additional questions regarding replica sets. Good luck!

ad

unread,
Mar 15, 2012, 7:37:20 AM3/15/12
to mongod...@googlegroups.com
Hi Marc,

Thanks a lot for this explanation it made things a lot clearer. I tird your setps but am getting the following

[root@localhost ~]#  mongo localhost:27018
MongoDB shell version: 2.0.3
connecting to: localhost:27018/test
> config = {_id: 'foo', members: [
...                           {_id: 0, host: 'localhost:27018'},
...                           {_id: 1, host: 'localhost:27019'},
...                           {_id: 2, host: 'localhost:27020'}]
...            }
{
"_id" : "foo",
"members" : [
{
"_id" : 0,
"host" : "localhost:27018"
},
{
"_id" : 1,
"host" : "localhost:27019"
},
{
"_id" : 2,
"host" : "localhost:27020"
}
]
}
> rs.initiate(config);
{ "errmsg" : "couldn't initiate : bad new extent size", "ok" : 0 }
> rs.status()
{
"startupStatus" : 3,
"info" : "run rs.initiate(...) if not yet done for the set",
"errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)",
"ok" : 0
}
> rs.initate()
Thu Mar 15 16:56:49 TypeError: rs.initate is not a function (shell):1
> rs.initate();
Thu Mar 15 16:56:55 TypeError: rs.initate is not a function (shell):1
> rs.initate(config);
Thu Mar 15 16:57:01 TypeError: rs.initate is not a function (shell):1
> rs.initiate()
{
"info2" : "no configuration explicitly specified -- making one",
"me" : "localhost.localdomain:27018",
"errmsg" : "couldn't initiate : bad new extent size",
"ok" : 0
}

Can someone tell me what bad new extent size error means and what to do to remove it.

Thanks :)

Scott Hernandez

unread,
Mar 15, 2012, 8:55:16 AM3/15/12
to mongod...@googlegroups.com
Please post the logs to gist/pastebin/etc for your replica set members.

> --
> 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/-/raYpHuFbJGEJ.
>
> 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.

ad

unread,
Mar 15, 2012, 9:28:14 AM3/15/12
to mongod...@googlegroups.com
Hi scott,

I got the st working donno how. But i tried again from scrath and it wokrs.
But one strange issue is if i use port 27017. It throws an error any ideas?? why this is happening?
Also i didnt get the link you gave. is it gist or paste bin?


> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

> mongodb-user+unsubscribe@googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

> mongodb-user+unsubscribe@googlegroups.com.

Scott Hernandez

unread,
Mar 15, 2012, 9:31:16 AM3/15/12
to mongod...@googlegroups.com
You should post *your* logs to pastebin/pastie/gist/etc. Without an
error message to look at it is hard to guess what the exception is --
the likely, and simple, possible problem is that you already have a
server running on that port (which doesn't have --replSet set) and
that is underlying cause for all your issues, and errors.

>> > mongodb-user...@googlegroups.com.

>> > mongodb-user...@googlegroups.com.

>> > mongodb-user...@googlegroups.com.


>> > For more options, visit this group at
>> > http://groups.google.com/group/mongodb-user?hl=en.
>

> --
> 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/-/myoSYYlN-m0J.


>
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to

> mongodb-user...@googlegroups.com.

ad

unread,
Mar 15, 2012, 9:38:48 AM3/15/12
to mongod...@googlegroups.com

Scott here is a log of 27017 i have posted it on link below.
http://pastebin.com/CcC2Gsi2

>> > mongodb-user+unsubscribe@googlegroups.com.

>> > mongodb-user+unsubscribe@googlegroups.com.

>> > mongodb-user+unsubscribe@googlegroups.com.


>> > For more options, visit this group at
>> > http://groups.google.com/group/mongodb-user?hl=en.
>
> --
> 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/-/myoSYYlN-m0J.
>
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to

> mongodb-user+unsubscribe@googlegroups.com.

Marc

unread,
Mar 15, 2012, 4:59:59 PM3/15/12
to mongodb-user
What specifically is the error that you receive when you try to use
port 27017? The logs seem to have a number of missing lines, and none
of the lines that are included mention anything about port 27017 being
in use. Do you receive the error when you attempt to start a new
Mongod process on that port, or do you receive an error message when
you try and add host" : "localhost:27017" as a new member to your
replica set? If you receive the error when you try to start a new
mongo process, it is most likely that you already have a mongo process
running on that port as Scott said. 27017 is the default port for
mongod, so if you start mongod without the --port option, it will run
on port 27017.

ad

unread,
Mar 16, 2012, 1:50:17 AM3/16/12
to mongod...@googlegroups.com
It says port 27017 already in use, How can i get that port back, can it be reset or something.
I got some other guys to try this and they also faced an issue with 27017, but when i tried replication with 27018, 27019,27020 on my local machine it worked.
So is it a bug or something?

Thanks

Marc

unread,
Mar 16, 2012, 11:17:37 AM3/16/12
to mongodb-user
I am unable to reproduce this. I am able to create a three-member
replica set with ports 27017, 27018, and 27019.

PRIMARY> rs.status()
{
"set" : "mySet",
"date" : ISODate("2012-03-16T14:51:45Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1331909380000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-16T14:49:40Z"),
"self" : true
},
{
"_id" : 1,
"name" : "localhost:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 123,
"optime" : {
"t" : 1331909380000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-16T14:49:40Z"),
"lastHeartbeat" : ISODate("2012-03-16T14:51:45Z"),
"pingMs" : 48
},
{
"_id" : 2,
"name" : "localhost:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 123,
"optime" : {
"t" : 1331909380000,
"i" : 1
},
"optimeDate" : ISODate("2012-03-16T14:49:40Z"),
"lastHeartbeat" : ISODate("2012-03-16T14:51:45Z"),
"pingMs" : 0
}
],
"ok" : 1
}

I am using version 2.0.2. Which version are you using? I can retry
with your version if different.

However, If I have an additional mongod process running, with no port
number specified (remember, mongo's default port is 27017) and I try
to start a replica set member on that port, the following message is
displayed:

Fri Mar 16 10:54:50 [initandlisten] ERROR: listen(): bind() failed
errno:48 Address already in use for socket: 0.0.0.0:27017
Fri Mar 16 10:54:50 [websvr] ERROR: listen(): bind() failed errno:48
Address already in use for socket: 0.0.0.0:28017
Fri Mar 16 10:54:50 [initandlisten] ERROR: addr already in use
Fri Mar 16 10:54:50 [websvr] ERROR: addr already in use
Fri Mar 16 10:54:50 [initandlisten] now exiting

Is this what you are seeing?

To check which ports are in use by which program, you can run netstat -
p in your terminal.

You should see something like:
Proto Recv-Q Send-Q Local Address Foreign
Address State PID/Program name
... (truncated for brevity)
tcp 0 0 localhost.localdomain:27017 localhost.localdomain:
43430 ESTABLISHED 1960/./mongod

You can also open up your system monitor and look for any "extra"
mongod processes that may have been started and forgotten about.

I suppose it is possible that another application could be using port
27017. netstat -p will reveal this.

Hopefully this mystery can be explained, but for the time being it
sounds as though you are up and running on different port numbers.
Please let us know if you are able to determine which process was
using port 27017. Good luck!
Reply all
Reply to author
Forward
0 new messages