V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
laike9m
V2EX  ›  MongoDB

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

  •  
  •   laike9m · 2015-04-28 20:30:20 +08:00 · 5000 次点击
    这是一个创建于 3256 天前的主题,其中的信息可能已经有所发展或是发生改变。

    副本集有三台机器(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 条回复    2015-04-29 11:08:54 +08:00
    whatisnew
        1
    whatisnew  
       2015-04-28 22:50:18 +08:00
    关于 mongodb 我一直没学会,如何删除前30行数据。

    选择数据 asc 排序,删除前 asc 30行。试过 remove findandmodify 全都没成功,半小时后放弃。。。
    EPr2hh6LADQWqRVH
        2
    EPr2hh6LADQWqRVH  
       2015-04-28 23:04:35 +08:00
    读可以用slave,写可不行,但repl set的语境下对于任意时间点到底谁是Master这个问题是不确定的,所以任意一台需要访问mongodb的应用服务器都需要了解所有可能是Master的mongod实例地址。
    具体URI格式参考官方文档 http://docs.mongodb.org/manual/reference/connection-string/
    laike9m
        3
    laike9m  
    OP
       2015-04-28 23:46:06 +08:00
    @avastms 嗯,我知道写不行,写的话会练到master的。如果只考虑度,一般来说初始化client的时候应该把所有地址都写上么?
    laike9m
        4
    laike9m  
    OP
       2015-04-29 11:08:16 +08:00
    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
       2015-04-29 11:08:54 +08:00
    所以最好是把所有 Mongodb 所在机器都写上。性能上应该没区别。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3829 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 10:33 · PVG 18:33 · LAX 03:33 · JFK 06:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.