zoukankan      html  css  js  c++  java
  • MongoDB的"副本“数据库服务器

    1.假设1数据库服务器为活跃服务器(主服务器),2和3为备份服务器,当1出现故障的时候,那么会在2和3中推选出一个(根据权重的等规则)作为活跃服务器,而当1又恢复正常了之后呢,它将以备份服务器的身份出现;

    2.设值数据库服务器(配置文件中要设置成闭环):

     比如设置1,2,3三个数据库的副本集群:

      数据库1:dbpath= D:/AA/AA/1

                   port= 1111 #端口号

                   bind_ip= 127.0.0.1 #服务器的IP地址

                   replSet= child/127.0.0.1:2222 #备份的服务器同伴

      位于1.conf配置文件中;

      

      数据库2:dbpath= D:/AA/AA/2

                   port= 2222 #端口号

                   bind_ip= 127.0.0.1 #服务器的IP地址

                   replSet= child/127.0.0.1:3333 #备份的服务器同伴

      位于2.conf配置文件中;

      数据库3:dbpath= D:/AA/AA/3

                   port= 333 #端口号

                   bind_ip= 127.0.0.1 #服务器的IP地址

                   replSet= child/127.0.0.1:1111 #备份的服务器同伴

      位于3.conf配置文件中;

      ***然后在1,2,3对应的服务器启动的批处理文件中对应好  如1数据库启动服务器   mongod  --config 1.conf 其他的同理即可***;

      ***在shell中 如1数据库服务器直接输入:mongo 127.0.0.1:1111  其他同理即可;***

    3.想要以上配置的副本集群起作用必须执行一下命令:

       3.1 use 数据库名  输入:db.runCommand({"replSetInitiate" :

                          {

                                                                   "_id" : "child",

                               "menbers" : [{"_id" : 1, "host" : "127.0.0.1:1111"},{"_id" : 1, "host" : "127.0.0.1:2222"},{"_id" : 1, "host" : "127.0.0.1:3333"}]

                                                                 }

                          });

    4.使用 rs.status() 来查看副本集群数据库服务器的状态;

       

  • 相关阅读:
    JNI_Z_02_函数参数_JNIEnv*_jclass_jobject
    JNI_Z_01_获取Clazz
    文章网址
    nginx安装,反向代理配置
    排序的hashmap(guava)
    Unirest-拼装http请求发送rest接口
    mac远程连接windows
    java class遍历属性
    mongodb mongotemplate聚合
    java tar.gz文件生成
  • 原文地址:https://www.cnblogs.com/zzq-include/p/4291206.html
Copyright © 2011-2022 走看看