zoukankan      html  css  js  c++  java
  • 通过批处理 安装 mongodb和设置身份验证

    1、首先需要 mongodb.msi安装包

    2、mongodb的配置文件mongod.cfg 内容如下:

    systemLog:
    destination: file
    path: "D:/mongodb/logs/mongodb.log"
    storage:
    dbPath: "D:/mongodb/db"
    net:
    http:
    enabled: true
    RESTInterfaceEnabled: true

    3、将mongodb以windows服务运行执行的命令为:

    "%installpath%inmongod.exe" --auth --config "%installpath%mongod.cfg" --smallfiles -install

    %installpath% 为安装的目录

    --auth 代表其他身份验证

    --config 指定配置文件

    --smaillfiles 限制日志大小,否则硬盘空间不足时,无法启动服务

    -install 表示安装未windos服务

    4、设置登录身份命令

    "%installpath%inmongo.exe" 127.0.0.1:27017/admin --quiet SetAuth.js

    SetAuth.js 文件内容如下:

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

    设置完上述登录账号后,需要重启服务才能生效

    5、因为配置文件的路径需要根据安装的路径动态生成,下面是生成conf文件的脚本

    set installpath=%~1
    
    set installpath2=%installpath:=/%
    
    rem Create installation directory
    mkdir "%installpath%"
    
    del "%installpath%mongod.cfg"
    echo systemLog:>>"%installpath%mongod.cfg"
    echo destination: file>>"%installpath%mongod.cfg"
    echo path: "%installpath2%/logs/mongodb.log">>"%installpath%mongod.cfg"
    echo storage:>>%installpath%mongod.cfg
    echo dbPath: "%installpath2%/db">>"%installpath%mongod.cfg"
    echo net:>>"%installpath%mongod.cfg"
    echo http:>>"%installpath%mongod.cfg"
    echo enabled: true>>"%installpath%mongod.cfg"
    echo RESTInterfaceEnabled: true>>"%installpath%mongod.cfg"

    将所有综合起来写成一个安装批处理setup.bat,如下:

    set installpath=%~1
    
    set installpath2=%installpath:=/%
    
    rem Create installation directory
    mkdir "%installpath%"
    
    
    del "%installpath%mongod.cfg"
    echo systemLog:>>"%installpath%mongod.cfg"
    echo destination: file>>"%installpath%mongod.cfg"
    echo path: "%installpath2%/logs/mongodb.log">>"%installpath%mongod.cfg"
    echo storage:>>%installpath%mongod.cfg
    echo dbPath: "%installpath2%/db">>"%installpath%mongod.cfg"
    echo net:>>"%installpath%mongod.cfg"
    echo http:>>"%installpath%mongod.cfg"
    echo enabled: true>>"%installpath%mongod.cfg"
    echo RESTInterfaceEnabled: true>>"%installpath%mongod.cfg"
    
    
    rem install mongodb
    
    msiexec /x mongodb.msi /qn
    mongodb.msi /qn INSTALLLOCATION="%installpath%" ADDLOCAL="all"
    
    mkdir "%installpath%"db
    
    mkdir "%installpath%"logs
    
    rem create service
    
    
    "%installpath%inmongod.exe" --auth --config "%installpath%mongod.cfg" --smallfiles -install
    
    rem start service
    net start MongoDB
    
    
    "%installpath%inmongo.exe" 127.0.0.1:27017/admin --quiet SetAuth.js
    
    
    net stop MongoDB
    
    
    net start MongoDB
    
    
    pause

    使用方法

       setup.bat  "D:TesmongoDB"

  • 相关阅读:
    vuex action 与mutations 的区别
    vue element-UI 升级报错Cannot find module "element-ui/lib/theme-default/index.css"
    mac 端口占用问题
    关于npm 淘宝镜像 以及package.json里包的更新
    plugin-barcodescanner 报错
    ios集成极光推送:Undefined symbols for architecture arm64: "_dns_parse_resource_record", referenced from:?
    Undefined symbols for architecture i386: "_deflate", referenced from:
    ionic3 打包Xcode 9 Swift Language Version (SWIFT_VERSION) Ask 报错
    ionic3 调用摄像头 当键盘弹出时候 出现摄像头 背景
    ionic3 更新打开apk android 8.0报错
  • 原文地址:https://www.cnblogs.com/karl-F/p/6831644.html
Copyright © 2011-2022 走看看