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"

  • 相关阅读:
    游戏开发之游戏策划的基本原则
    Lua游戏脚本语言入门
    游戏策划之游戏心理学理论深入浅出
    微博的10大特征包括哪些?
    普米族求助,十万火急!!! 请大家给力!!!
    剑指微博营销,速创品牌传奇
    将网络推广进行到底
    浅谈如何利用微博进行网站推广(转)
    “土风计划”,陈哲另一个伟大事业
    快速增加微博粉丝的十六大技巧
  • 原文地址:https://www.cnblogs.com/karl-F/p/6831644.html
Copyright © 2011-2022 走看看