副本集配置文件

dbpath=/hwdata/mongodb/data
logpath=/hwdata/mongodb/logs/master.log
pidfilepath=/hwdata/mongodb/logs/master.pid
directoryperdb=true
logappend=true
port=27017
oplogSize=60000
fork=true
noprealloc=true
replSet=ucdb
keyFile=/hwdata/mongodb/keyfile/keyfile.dat

 

查看当前连接数:

db.serverStatus().connections

 

增加副本级

cfg = {_id: "ucdb", members: [

{_id: 0, host: "172.16.33.27:27017",priority:14},
{_id: 1, host:"172.16.33.34:27017",priority:18},
{_id: 2, host: "172.16.33.26:27017",arbiterOnly:true},]};

rs.initiate(cfg)  #初始化

 

 

添加新主机到副本集

rs.add({_id: 2, host: "172.16.33.37:27017",arbiterOnly:true})
rs.add({_id: 3, host: "172.16.33.35:27017",priority:1})

 

 

修改副本优先级
cfg = rs.conf();
cfg.members[0].priority = 10;
cfg.members[1].priority = 9;
cfg.members[2].priority = 8;
rs.reconfig(cfg)
rs.config();    #查看副本集优先级权重

 

 

移除副本集的单个主机

rs.remove('172.16.33.34:27017')

 

 

移除副本集的单个主机主机后,进入移除这个mongo 输入处变成OTHER

用移除的副本集主机,重新在建立一个副本集群:

  1执行:

  cfg = {_id: "ucdb", members: [
  {_id: 0, host: "172.16.33.27:27017",priority:14},
  {_id: 1, host:"172.16.33.34:27017",priority:18},
  {_id: 2, host: "172.16.33.26:27017",arbiterOnly:true},]};

 

  2执行

  rs.reconfig(cfg,{ force: true})

 

  3如果从库不同步,做如下操作完成后,立刻再一次同步

  rs.remove('172.16.33.27:27017')

  rm -rf data/*

  rs.add('172.16.33.27:27017')

用移除副本集的主机在重新做新的副本集会有这样的错误提示:

rs.initiate(cfg)
{
"info" : "try querying local.system.replset to see current configuration",
"ok" : 0,
"errmsg" : "already initialized",
"code" : 23
}
rs.reconfig(cfg)
{
"ok" : 0,
"errmsg" : "replSetReconfig should only be run on PRIMARY, but my state is REMOVED; use the "force" argument to override",
"code" : 10107
}
rs.reconfig(ctf, force: true)
2017-02-23T13:43:40.827+0800 E QUERY SyntaxError: Unexpected token :
rs.reconfig({ctf, force: true})
2017-02-23T13:43:48.536+0800 E QUERY SyntaxError: Unexpected token ,
rs.reconfig(cfg, { force: true})
{ "ok" : 1 }


 

创建用户:

db.createUser( 

    user:"a123",  
    pwd:"a123", 
    roles:[{role:"userAdminAnyDatabase",db:"admin"}] 
 });


db.createUser( {
 user: "123",
 pwd: "123",
 roles: [ { role: "root", db: "admin" } ]
 });

 

posted on 2018-06-08 17:02  Python哥  阅读(726)  评论(0编辑  收藏  举报