How to force MongoDB Replica Set Primary member use ip as host value?

1,302 views
Skip to first unread message

janwen lou

unread,
Mar 11, 2015, 12:05:19 AM3/11/15
to mongod...@googlegroups.com
After i execute command:rs.initiate()
and then add other 2 Replica Set Member to sets(using ip address,not host),and execute:
rs.conf();
output as follow,the problem is that developers need to changes host config on their machines to connect Replica Set(With Spring Data MongoDB).
i want to know how can i force every Replicate Set member use ip address as host value,not server name.
When i initial replica set,how can i force the first member using ip address as host value? need update linux /etc/hosts?
thx

{
        "_id" : "rs1",
        "version" : 3,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "dev02:27017"
                },
                {
                        "_id" : 1,
                        "host" : "10.10.10.139:27018"
                },
                {
                        "_id" : 2,
                        "host" : "10.10.10.139:27019"
                }
        ]
}



janwen lou

unread,
Mar 11, 2015, 12:11:47 AM3/11/15
to mongod...@googlegroups.com
Just check /etc/interfaces as follow:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 10.10.10.139
netmask 255.255.255.0
gateway 10.10.10.1
dns-nameservers 223.5.5.5 223.6.6.6

Asya Kamsky

unread,
Mar 11, 2015, 12:37:50 AM3/11/15
to mongod...@googlegroups.com
It will use whatever is returned to
hostname -f

If you want something specific used, you have to pass conf object to rs.initiate() specifying exact config you want (i.e. IP addresses instead of hostnames).
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/025e8883-b1ac-4b96-ba28-0d900c21da01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

loujianwen

unread,
Mar 11, 2015, 1:52:34 AM3/11/15
to mongod...@googlegroups.com, Asya Kamsky
Got it,thanks
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/NnPNhmyh_WA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

janwen lou

unread,
Mar 11, 2015, 3:27:16 AM3/11/15
to mongod...@googlegroups.com
I follow the second procedure in this tutorial,http://docs.mongodb.org/manual/tutorial/change-hostnames-in-a-replica-set/
Got output from rs.conf()
{
        "_id" : "rs1",
        "version" : 3,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "10.10.10.139:27017"
                },
                {
                        "_id" : 1,
                        "host" : "10.10.10.139:27018"
                },
                {
                        "_id" : 2,
                        "host" : "10.10.10.139:27019"
                }
        ]
}


but get output from rs.status()
 {
                        "_id" : 1,
                        "name" : "10.10.10.139:27018",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 221,
                        "optime" : Timestamp(1426044718, 1),
                        "optimeDate" : ISODate("2015-03-11T03:31:58Z"),
                        "lastHeartbeat" : ISODate("2015-03-11T07:26:17Z"),
                        "lastHeartbeatRecv" : ISODate("2015-03-11T07:26:16Z"),
                        "pingMs" : 0,
                        "syncingTo" : "dev02:27017"
                },


the secondary members still syncingTo dev02:27017,
how to fix this?
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

Asya Kamsky

unread,
Mar 11, 2015, 5:22:21 PM3/11/15
to mongodb-user
As long as rs.conf() on that host shows the correct name, it will use
that - I think the field you're seeing is just a display thing...

Asya
>>> email to mongodb-user...@googlegroups.com.
>>> To post to this group, send email to mongod...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/mongodb-user.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/mongodb-user/025e8883-b1ac-4b96-ba28-0d900c21da01%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user"
> group.
>
> For other MongoDB technical support options, see:
> http://www.mongodb.org/about/support/.
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mongodb-user/96bea6b1-baad-4011-a43e-89d8e77546e7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages