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%\bin\mongod.exe" --auth --config "%installpath%\mongod.cfg" --smallfiles -install

%installpath% 为安装的目录

--auth 代表其他身份验证

--config 指定配置文件

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

-install 表示安装未windos服务

4、设置登录身份命令

"%installpath%\bin\mongo.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=%~

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=%~

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%\bin\mongod.exe" --auth --config "%installpath%\mongod.cfg" --smallfiles -install rem start service
net start MongoDB "%installpath%\bin\mongo.exe" 127.0.0.1:/admin --quiet SetAuth.js net stop MongoDB net start MongoDB pause

使用方法

setup.bat  "D:\Tes\mongoDB"

通过批处理 安装 mongodb和设置身份验证的更多相关文章

  1. linux安装mongodb(设置非root用户和开机启动)

    官网地址:https://www.mongodb.com/ 在官网上选择不同的linux系统得到不同的下载地址,我们用的下载地址是:https://fastdl.mongodb.org/linux/m ...

  2. Nginx设置身份验证

    在某些情况下,需要对某些内容的访问进行限制,在Nginx中也提供了这样的限制措施,以下是几种常见的限制措施: 1.访问身份验证 在Nginx的插件模块中有一个模块ngx_http_auth_basic ...

  3. 使用nginx代理kibana并设置身份验证

    1.在es-sever上安装nginx #wget http://nginx.org/download/nginx-1.8.1.tar.gz #tar xvf nginx-1.8.1.tar.gz # ...

  4. 安装mongodb以及设置为windows服务 详细步骤

    我的win7 32的,注意版本要正确! 一.下载mongodb压缩包:mongodb-win32-i386-2.6.9.zip() 二.在D盘新建文件夹mongodb,将压缩我的解压文件放进去(有一个 ...

  5. centos7源码包安装Mongodb,并设置开机自启动

    1.下载源码包 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.12.tgz 2.解压 放到 /usr/local/ ...

  6. (后端)安装mongodb以及设置为windows服务 详细步骤(转)

    1.在data文件夹下新建一个log文件夹,用于存放日志文件,在log文件夹下新建文件mongodb.log 2.在 D:\mongodb文件夹下新建文件mongo.config,并用记事本打开mon ...

  7. Linux 安装MongoDB 并设置防火墙,使用远程客户端访问

    1. 下载 MongoDB 提供了 linux 各发行版本 64 位的安装包  下载地址:https://www.mongodb.com/download-center#community 2. 安装 ...

  8. docker 安装MongoDB以及设置用户

    MongoDB 是一个免费的开源跨平台面向文档的 NoSQL 数据库程序. 1.查看可用的 MongoDB 版本 访问 MongoDB 镜像库地址: https://hub.docker.com/_/ ...

  9. ASP.NET MVC 随想录——探索ASP.NET Identity 身份验证和基于角色的授权,中级篇

    在前一篇文章中,我介绍了ASP.NET Identity 基本API的运用并创建了若干用户账号.那么在本篇文章中,我将继续ASP.NET Identity 之旅,向您展示如何运用ASP.NET Ide ...

随机推荐

  1. ubuntu nsight上链接OpenGL

    写一个需要使用OpenGL的程序,右击该程序名,此处需要OpenGL库的程序为Julia-C 右击,选择属性,弹出属性对话框,在左边选择build下的设置,中间窗格中选择GCC C++ Linker下 ...

  2. ubuntu14.04下chrome浏览器的安装

    ubuntu 64位 1.下载chrome安装包: sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_ ...

  3. Parallel.For 你可能忽视的一个非常实用的重载方法

    说起Parallel.For大家都不会陌生,很简单,不就是一个提供并行功能的for循环吗? 或许大家平时使用到的差不多就是其中最简单的那个重载方法,而真实情况 下Parallel.For里面有14个重 ...

  4. 用C写一个web服务器(二) I/O多路复用之epoll

    .container { margin-right: auto; margin-left: auto; padding-left: 15px; padding-right: 15px } .conta ...

  5. redux核心思路和代码解析

    最近在公司内部培训的时候,发现很多小伙伴只是会用redux.react-redux.redux-thunk的api,对于其中的实现原理和数据真正的流向不是特别的清楚,知其然,也要知其所以然,其实red ...

  6. 模块中为什么要加__name__ == "__main__"

    写一个hello模块 #!/usr/sbin/env python #-*- coding:utf- -*- print "我是hello模块,我被执行了" 在另一个python程 ...

  7. 使用arcpy.mapping模块批量出图

      出图是项目里常见的任务,有的项目甚至会要上百张图片,所以批量出土工具很有必要.arcpy.mapping就是ArcGIS里的出图模块,能快速完成一个出图工具. arcpy.mapping模块里常用 ...

  8. C#委托冒泡

    委托的实现,就是编译器自行定义了一个类:有三个重要参数1.制定操作对象,2.指定委托方法3.委托链 看如下一个列子: class DelegatePratice { public static voi ...

  9. 关于generator异步编程的理解以及如何动手写一个co模块

    generator出现之前,想要实现对异步队列中任务的流程控制,大概有这么一下几种方式: 回调函数 事件监听 发布/订阅 promise对象 第一种方式想必大家是最常见的,其代码组织方式如下: fun ...

  10. Azure IoT 技术研究系列2-起步示例之设备注册到Azure IoT Hub

    上篇博文中,我们主要介绍了Azure IoT Hub的基本概念.架构.特性: Azure IoT 技术研究系列1-入门篇 本文中,我们继续深入研究,做一个起步示例程序:模拟设备注册到Azure IoT ...