zoukankan      html  css  js  c++  java
  • mongodb副本集

    创建docker:

    创建docker5000:docker run -d -p 5000:5000 -p 27017:27017 -e MONGO_ONE_NODE=True -e MONGO_ADMIN_PASSWORD=admin mm2:latest
    创建docker5001:docker run -d -p 5000:5001 -p 27018:27017 -e MONGO_ONE_NODE=True -e MONGO_ADMIN_PASSWORD=admin mm2:latest

    启动mongo服务:

    /usr/bin/mongod --bind_ip_all  --logpath  /var/log/mongodb/mongod.log --replSet rs0 --fork

    创建副本集:

    /usr/bin/mongo admin --eval "rs.initiate({"_id":"rs0","members":[{"_id":0,"host":"172.17.0.1:27017"},{"_id":1,"host":"172.17.0.1:27018"}]});"

    创建角色:

    /usr/bin/mongo admin --eval "
    db.createUser({
        user: 'admin',
        pwd: 'admin',
        roles: [{role: 'userAdminAnyDatabase', db: 'admin'}],
        mechanisms:['SCRAM-SHA-1']
    });"

    创建读写权限用户:

    use admin
    db.auth("admin","password");
    use ballmatch
    db.createUser({
        user: "football",
        pwd: "password",
        roles: [{role: "readWrite",db: "ballmatch"}]
    })

    修改用户密码:

    db.updateUser( "admin",{pwd:"password"});

    密码认证:

    db.auth("admin","password");

    删除用户:

    删除用户(需要root权限,会将所有数据库中的football用户删除)
    db.system.users.remove({user:"football"});
    删除用户(权限要求没有那么高,只删除本数据中的football用户)
    db.dropUser("football");

    关闭mongo:

    /usr/bin/mongod --shutdown --dbpath=/var/lib/mongodb --logpath=/var/log/mongodb/mongod.log --port=27017 --logappend --fork

    use admin; db.shutdownServer();

    主节点:

    db.isMaster()

    查看副本集:

    rs.status()
    rs.config()

     设置权重:

    conf = rs.config()     #获取副本集的配置,默认权重都是1
    conf.members[0].priority = 10   # 设置权重

    为SECONDARY添加查询权限:

    rs.slaveOk()

    mongo副本集设置主库权重,即使主库宕机了再重启也还是主库:

    cfg = rs.conf()  
    cfg.members[0].priority = 10 
    cfg.members[1].priority = 1
    rs.reconfig(cfg)
    rs.reconfig(cfg,{"force":true})

     结束!

  • 相关阅读:
    [HTTP2] HTTP1 probs and HTTP2 saves
    [HTTPS] MAN IN THE MIDDLE (MITM)
    [HTTP] HTTP Verb
    [Node.js] Creating JWTs (JSON Web Tokens) in Node
    [RxJS] Drag and Drop example
    [Webpack 2] Ensure all source files are included in test coverage reports with Webpack
    [Webpack 2] Add Code Coverage to tests in a Webpack project
    android简单的答题游戏
    Java Web----EL(表达式语言)详解
    使用ant构建报错,编码GBK的不可映射字符解决方法
  • 原文地址:https://www.cnblogs.com/aaronthon/p/14163551.html
Copyright © 2011-2022 走看看