推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
laike9m
V2EX  ›  MongoDB

使用副本集时,不同服务器应该连哪个 mongodb?

  •  
  •   laike9m · Apr 28, 2015 · 5934 views
    This topic created in 4109 days ago, the information mentioned may be changed or developed.

    副本集有三台机器(M1, M2, M3),然后服务器放在另外几台机器(S1, S2, ..Sn)。用的 driver 是 pymongo。因为对实时性要求不高,所以 ReadPreference 打算设置成 NEAREST,也就是会把请求平均分布到各台 mongo 所在机器。然后现在的问题是,MongoReplicaSetClient 的第一个参数 hosts_or_uri 不知道该怎么设置。可能的选择有三种:

    1. 在各台后端服务S1-Sn,都设置 hosts_or_uri = M1;
    2. 平均分配, 1/3 hosts_or_uri = M1, 1/3 hosts_or_uri = M3, 1/3 hosts_or_uri = M3;
    3. 设置 hosts_or_uri = M1, M2, M3

    哪一种比较好呢?谢谢。

    5 replies    2015-04-29 11:08:54 +08:00
    whatisnew
        1
    whatisnew  
       Apr 28, 2015
    关于 mongodb 我一直没学会,如何删除前30行数据。

    选择数据 asc 排序,删除前 asc 30行。试过 remove findandmodify 全都没成功,半小时后放弃。。。
    EPr2hh6LADQWqRVH
        2
    EPr2hh6LADQWqRVH  
       Apr 28, 2015
    读可以用slave,写可不行,但repl set的语境下对于任意时间点到底谁是Master这个问题是不确定的,所以任意一台需要访问mongodb的应用服务器都需要了解所有可能是Master的mongod实例地址。
    具体URI格式参考官方文档 http://docs.mongodb.org/manual/reference/connection-string/
    laike9m
        3
    laike9m  
    OP
       Apr 28, 2015
    @avastms 嗯,我知道写不行,写的话会练到master的。如果只考虑度,一般来说初始化client的时候应该把所有地址都写上么?
    laike9m
        4
    laike9m  
    OP
       Apr 29, 2015
    mongodb 官方的人给了个回复:

    You're only required to pass the hostname/port of one of the replica set members. MongoReplicaSetClient will discover the rest automatically. The being said, it is best practice to include more than one member in the seed list (hosts_or_uri). If you only include one member in the seed list and that member just happens to be unavailable when you (re)start your application, PyMongo won't be able to connect. If you include two or more members in the seed list, as long as one of the members in the seed list is available PyMongo will be able to connect.
    laike9m
        5
    laike9m  
    OP
       Apr 29, 2015
    所以最好是把所有 Mongodb 所在机器都写上。性能上应该没区别。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3091 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:25 · PVG 21:25 · LAX 06:25 · JFK 09:25
    ♥ Do have faith in what you're doing.