mongodb installation and configuration

MongoDB general installation

1. First, go to the official website ( http://www.mongodb.org/downloads  ) to download the appropriate installation package. The latest version is the 2.6
 installation package in zip and msi format. It is recommended to download the zip format. In fact, the msi version is also available. It's just decompressed, and the installation path is not allowed to be selected during installation. It is installed to the C:\Program Files\MongoDB 2.6 Standard directory by default, and choose 32-bit or 64-bit according to your own system.

My computer is a 64-bit win8 system, download the 64-bit zip package, and extract it to the D:\MongoDB directory after the download is complete

Create the database directory D:\MongoDB\data, then open the command line window, switch to the D:\MongoDB\bin directory and execute the following command:

Where --dbpath is the specified database storage directory, here we should pay attention to two "-"

mongod --dbpath D:\MongoDB\data

This is the command line window will print some startup information, and the last line displays the following information, indicating that the startup is successful

2014-04-23T10:38:48.391+0800 [initandlisten] waiting for connections on port 27017

This is to enter http://localhost:27017/ in the browser and you can see that the display information is

It looks like you are trying to access MongoDB over HTTP on the native driver port.
具体截图如下:

At this point, mongodb is installed, it is much simpler than expected.

MongoDB installed as a Windows service

Installing mongodb as a windows service is very simple, just add --install after the command line executed above

mongod --dbpath D:\MongoDB\data --install

According to the normal plot, the service should be installed successfully, but unfortunately, the following prompt appears

--install has to be used with --logpath

As prompted, we need to specify the log directory, so we create the log directory D:\MongoDB\logs and execute the command again

mongod --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log --logappend

However, the prompt still does not specify the log path. After a lot of tossing, I found that this is a bug in version 2.6 and will be fixed in the next version. Then we have two choices, one is to use the previous version 2.4.9, and the other is to use the first version. The 2.4.9 version is successfully installed and the service is installed, and then it is upgraded to 2.6 (swollen upgrade? Directly replace the file corresponding to the 2.4.9 version with the 2.6 version), then do we have any other options? Of course, the answer is yes, use sc Command to create a service, use net start to start the service

sc create MongoDB binPath= "D:\MongoDB\bin\mongod.exe --service --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log  --logappend"
net start MongoDB

MongoDB configuration file

很遗憾,官方下载的安装包里面没有默认的配置文件,若想使用配置文件只能自己建一个了,另外个人也推荐使用配置文件来管理MongoDB的配置,使用配置文件配置数据库文件、日志文件以及其它的一些配置都一目了然

解压安装包到D:\MongoDB

建立数据库目录 D:\MongoDB\data

建立日志目录 D:\MongoDB\logs

建立配置文件目录 D:\MongoDB\etc

建立配置文件 D:\MongoDB\etc\mongodb.conf

按 Ctrl+C 复制代码
dbpath=D:\MongoDB\data #数据库路径
logpath=D:\MongoDB\logs\mongodb.log #日志输出文件路径
logappend=true #错误日志采用追加模式,配置这个选项后mongodb的日志会追加到现有的日志文件,而不是从新创建一个新文件
journal=true #启用日志文件,默认启用
quiet=true #这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
port=27017 #端口号 默认为27017
按 Ctrl+C 复制代码

这里仅指定了几个常用项,更多详细配置请参考官方文档 http://docs.mongodb.org/manual/reference/configuration-options/

注:以上目录是博主自己建立的目录,官方并没有对配置文件路径做出规范,全凭个人喜好来决定

配置文件和相关目录建好后使用如下方式启动MongoDB

  • 普通启动
    mongod --config D:\MongoDB\etc\mongodb.conf
  • 安装为Windows服务
    注:2.6版 这种方式在win7、win8 64位版无法安装成功,其他系统未测试
    mongod --config D:\MongoDB\etc\mongodb.conf --install
  • 使用SC安装为Windows服务
    sc create MongoDB binPath= "D:\MongoDB\bin\mongod.exe --service --config=D:\MongoDB\etc\mongodb.conf"

     

这里需要注意下当指定了日志文件后,无论使用配置文件指定还是在命令行指定,日志就都会输出到指定的日志文件去了,在命令行界面将看不到任何日志输出

 

附注:

  2.6版无法安装windows服务BUG链接 https://jira.mongodb.org/browse/SERVER-13515

  MongoDB官网:http://www.mongodb.org/

windows安装MongoDB与错误1053解决办法

今天文章要介绍关于在windows安装MongoDB以及我在安装MongoDB时碰到安装错误1053代码的具体解决办法,各位朋友有兴趣可进入参考。
 

安装MongoDB

到http://www.mongodb.org/的下载页找到windows 32位的安装程序,实际是一个绿色的程序。本文以mongodb-win32-i386-1.6.0.zip 为例。

配置运行MongoDB

将下载下来的mongodb压缩包解压缩到目标目录,比如D:/mongodb ,先打开cmd命令行,输入:

 代码如下 复制代码

d:/mongodb/bin>mongod.exe –dbpath d:/mongodb/db

这里的d:/mongodb 目录下没有db文件夹需要自己建立一个,此时mongod 进程运行起来,再打开一个cmd窗口,输入:

 代码如下 复制代码

d:/mongodb/bin/mongo.exe

进入mongodb命令模式

 代码如下 复制代码

MongoDB Shell Version:1.6.0
connection to  (databaseName)
>show dbs
admin
local

可以预先看一下数据库状况,默认会有admin,local 两个数据库

>

 代码如下 复制代码

use testdb   ;打开数据库,没有的话立即建一个
> db.myc.save({a:10})  ;向 collection mpc 中保存一条信息,没有collection的话立即建一个

> db.myc.find()  ;检索所有记录
{ “_id” : ObjectId(“4c469967dd6f000000001637″), “a” : 10 }

> show collections  ;显示所有 collection 名字
myc
system.indexes  ;

系统使用

help 是帮助命令,随时可以运行以查看命令提示。

配置MongDB服务

为了避免每次打开cmd窗口启动MongoDB,可以注册为服务,cmd命令为:

 代码如下 复制代码

d:/mongodb/bin/mongod.exe -dbpath d:/mongodb/db  -logpath d:/mongodb/log  -install

此命令虽然可以注册上windows service 服务,但是我却遇到了无法启动的问题,提示:“错误1053 ,服务没有及时响应启动或控制请求”。郁闷之余想到了以VBS文件调用bat批处理来实现隐藏cmd命令后台运行。

首先建立bat文件:

 代码如下 复制代码
mongo-start.bat 内容d:/mongodb/bin/mongod.exe -dbpath=d:/mongodb/db -logpath=d:/mongodb/log
mongo-stop.bat 内容 taskkill /f /t /im mongod.exe

然后建立vbs文件:

 代码如下 复制代码

mongo-start.vbs:
Set ws = CreateObject(“Wscript.Shell”)
ws.run “cmd /c d:/mongodb/mongo-start.bat”,vbhide

mongo-stop.vbs:
Set ws = CreateObject(“Wscript.Shell”)
ws.run “cmd /c d:/mongodb/mongo-stop.bat”,vbhide

这样启动、停止MongoDB可以调用vbs文件,后台运行了。

安装MongoDB错误1053解决

在官网下载windows安装包mongodb-win32-i386-2.4.0.zip:http://www.mongodb.org/downloads

解压到D盘:D:/mongoDB,在mongoDB中创建2个文件夹:data、logs,因为mongoDB运行时需要指定数据存储目

录和logs目录,它不会自动创建。

然后CMD命令行安装mongoDB到系统服务:

 代码如下 复制代码

>D:/mongoDB/bin/mongod.exe --bind_ip 127.0.0.1 --logpath D:/mongodb/logs/mongodb.log --logappend --dbpath "D:/mongodb/data" --directoryperdb--serviceName MongoDB--install

启动:>net start MongoDB

 

mongoVUE中collections为空,即文件树无法展开问题的解决策略.

 

 

今天安装mongodb v3.2.8后,安装了它的一个可视化工具,MongoVUE,但是在操作数据库一切正常的情况下,在MongoVUE中无法查看到collections中的文件,但是在cmd中一切操作正常,也能用find()找到刚才插入的数据。

百度了一下,换了很多关键词,找了很久没有找到对策,最后终于发现了一条,并且成功解决了这个问题。

原因是mongodb3.2版本以后默认的开启的是wiredTiger存储引擎,而之前一直使用mmavp1存储,而且两种文件不兼容。

使用wiredTiger存储引擎产生的文件是这样的: 
这里写图片描述

若使用MongoVUE这个工具,需要将存储引擎改成mmavp1,将文件存储改变,这是目前我所知的方法,之后这个问题估计会得到解决

具体操作:

1、首先将存放数据的文件夹清空,例如我放在D:\MongoDB\bin\data,将data中原来wiredTiger存储的文件全部删除
  • 1
  • 1
2、在cmd中进入mongodb所在的文件夹,例如我存放在D:\MongoDB\bin
然后再输入mongod  --storageEngine mmapv1 --dbpath D:\MongoDB\bin\data,注意输入的是引号中的内容,注意其中的空格,以及最后的是数

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326887686&siteId=291194637