当前位置:   article > 正文

记mongodb7.0安装时的常用操作 windows_window 安装mongodb 7.0 安装使用

window 安装mongodb 7.0 安装使用

1、官网下载安装

Download MongoDB Community Server | MongoDBDownload MongoDB Community Server non-relational database to take your next big project to a higher level!icon-default.png?t=N7T8https://www.mongodb.com/try/download/community

2、官网下载shell工具,否则装好后无法创建admin账号和修改密码进行不了验证操作

MongoDB Shell Download | MongoDBThe MongoDB Shell is a modern command-line experience, full with features to make it easier to work with your database. Free download. Try now!icon-default.png?t=N7T8https://www.mongodb.com/try/download/shell

进入后都先选择环境,然后直接下载

3、安装好会默认启动,验证是否启动可以在浏览器访问下面的网址

http://localhost:27017/

启动成功:

4、启动安装的shell工具

先切换到admin库

use admin

然后先创建admin用户和密码

db.createUser({ user: 'admin', pwd: '123456', roles: [{ role: 'userAdminAnyDatabase', db: 'admin'}]});

然后编辑配置文件:

启用鉴权:

        security:

                authorization: enabled

然后重启服务:

        插入一个cmd命令添加服务的示例

               1、 管理员权限打开cmd窗口

               2、注册服务命令:sc create 服务名 binpath= 程序所在路径 type= own start= auto                 displayname= 服务显示名称

               3、将MongoDb插入后可以用下面的方式启动

               启动: net start mongodb

               停止:2 net stop mongodb

               做成bat可快速执行

        不想麻烦还可以用命令行直接关闭

                db.shutdownServer()

                或者

                bin / mongod--port = 27017--dbpath =/ soft / mongodb / mongodb / data--shutdown

5、再次进入shell工具直接输入admin然后回车

先鉴权:

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

可以的话说明鉴权成功,用其他工具链接也需要输入账号密码了

6、相关授权命令

MongoDB角色有:

    数据库用户角色:read、readWrite;
    数据库管理角色:dbAdmin、dbOwner、userAdmin;
    集群管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager;
    备份恢复角色:backup、restore;
    所有数据库角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase
    超级用户角色:root;

MongoDb权限有:

        read: 允许用户读取指定数据库
        readWrite: 允许用户读写指定数据库
        dbAdmin:允许用户在指定数据库中执行管理函数,如索引创建、删除,查看统计或访问

        system.profile
        userAdmin:允许用户向system.users集合写入,可以找指定数据库里创建、删除和管理用户
        clusterAdmin:只在admin数据库中可用,具有所有分片和复制集相关函数的管理权限。
        readAnyDatabase:只在admin数据库中可用,具有所有数据库的读权限
        readWriteAnyDatabase:只在admin数据库中可用,具有所有数据库的读写权限
        userAdminAnyDatabase:只在admin数据库中可用,具有所有数据库的userAdmin权限
        dbAdminAnyDatabase:只在admin数据库中可用,具有所有数据库的dbAdmin权限。
        root:只在admin数据库中可用。超级账号,超级权限。

创建普通用户:

                db.createUser(
                {
                  user: "user",
                  pwd: "password",
                  roles: [{ role: "readWrite",db:”user”}],
                } )

创建管理员:

         db.createUser(
        {
            user: "DbUser",
            pwd: "DbPwd“,roles:["readWriteAnyDatabase", "dbAdminAnyDatabase"]
        })

修改对应用户的权限:

db.updateUser( "user", { customData: { info: "测试修改权限" }, roles: [ { role: "clusterAdmin", db: "admin" }] } )

收回权限:

db.revokeRolesFromUser( "user", [ { role: "read", db: "admin" } ] )

修改密码:

db.changeUserPassword("user", "12345678")

对某个用户的某个数据库的某个操作进行限制:

db.createRole({role: "test",privileges: [{ resource: { db: "testdb", collection: "test1" }, actions: ["find", "update"] },{ resource: { db: "testdb", collection: "test2" }, actions: ["find"] },],roles: []})

查询数据库下的用户:

        db.system.users.find()

删除用户:

        db.dropUser(“user”)

mongod.conf配置文件

  1. # mongod.conf
  2. # for documentation of all options, see:
  3. # http://docs.mongodb.org/manual/reference/configuration-options/
  4. # Where and how to store data.
  5. storage:
  6. dbPath: D:\mongodb\data
  7. journal:
  8. #日志操作间隔
  9. commitIntervalMs: 500
  10. #保留的日志的最小时长
  11. oplogMinRetentionHours: 6
  12. wiredTiger:
  13. engineConfig:
  14. #所有数据的内部缓存的最大大小
  15. cacheSizeGB: 2
  16. #压缩方式,比zlib快但大
  17. journalCompressor: snappy
  18. # where to write logging data.
  19. systemLog:
  20. destination: file
  21. logAppend: true
  22. path: D:\mongodb\log\mongod.log
  23. traceAllExceptions: true
  24. # network interfaces
  25. net:
  26. port: 27017
  27. bindIp: 127.0.0.1
  28. wireObjectCheck: true
  29. #processManagement:
  30. security:
  31. authorization: enabled
  32. #慢速操作时间阈值
  33. operationProfiling:
  34. slowOpThresholdMs: 300
  35. #操作日志大小
  36. replication:
  37. oplogSizeMB: 10
  38. #sharding:
  39. ## Enterprise-Only Options:
  40. #auditLog:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/734487
推荐阅读
相关标签
  

闽ICP备14008679号