mongdb安装
Installa MongoDB on Window server 2008(64bit)
Installed on Windows server 2008(64bit), please use 64bitlegacy installation package.
useful links for mongoDB.
http://docs.mongodb.org/
一、按照操作系统下载http://www.mongodb.org/downloads。
二、在D盘新建MongoDB文件夹(此文件夹为自定义的数据库安装目录D:\\MongoDB)把刚才下载的压缩包解压并把bin文件夹拷贝到MongoDB文件夹。
三、在MongoDB文件夹内新建logs文件夹(用于存储日志文件D:\\MongoDB\\logs),并在此文件夹内新建空文件mongodb.log。
四、在MongoDB文件夹内新建db文件夹(用于存放数据库文件D:\\MongoDB\\db)。
五、启动MongoDB。
以系统管理员身份运行cmd,切换至D:\\MongoDB\\bin目录输入 mongod.exe --dbpath=d:\\mongodb\\db。如看到控制台最后一行类似
Tue Oct 09 11:50:55 [websvr] admin web console watiing for connections on port 28017说明启动成功(MongoDB占用系统28017端口)
。
---------------------------------------------------------------------------------------------------------------
例如
Microsoft Windows [版本 6.0.6002]
版权所有 (C) 2006 Microsoft Corporation。保留所有权利。
C:\\Users\\Administrator>cd D:\\MongoDB\\bin
C:\\Users\\Administrator>d:
D:\\MongoDB\\bin>mongod.exe --dbpath=d:\\mongodb\\db
2015-01-07T13:12:55.855+0800 [initandlisten] MongoDB starting : pid=912 port=27017 dbpath=d:\\mongodb\\db 64-bit host=ctvms-dev002
2015-01-07T13:12:55.855+0800 [initandlisten] targetMinOS: Windows Server 2003 SP2
2015-01-07T13:12:55.855+0800 [initandlisten] db version v2.6.6
2015-01-07T13:12:55.855+0800 [initandlisten] git version:
608e8bc319627693b04cc7da29ecc300a5f45a1f
2015-01-07T13:12:55.855+0800 sys.getwindowsversion(major=6,
[initandlisten] minor=1,
build info: windows
build=7601, platform=2,
service_pack='Service Pack 1') BOOST_LIB
2015-01-07T13:12:55.855+0800 [initandlisten] allocator: system
2015-01-07T13:12:55.855+0800 [initandlisten] options: { storage: { dbPath: \"d:\\mongodb\\db\" } }
2015-01-07T13:12:55.870+0800 dir=d:\\mongodb\\db\\journal
[initandlisten] journal
2015-01-07T13:12:55.870+0800 [initandlisten] recover : no journal files present, no recovery needed
2015-01-07T13:12:55.948+0800 [initandlisten] allocating new ns file d:\\mongodb\\db\\local.ns, filling with zeroes...
2015-01-07T13:12:56.276+0800 [FileAllocator] allocating new datafile d:\\mongodb\\db\\local.0, filling with zeroes...
2015-01-07T13:12:56.276+0800 d:\\mongodb\\db\\_tmp
[FileAllocator] creating directory
2015-01-07T13:12:56.292+0800 [FileAllocator] done allocating datafile d:\\mongodb\\db\\local.0, size: 64MB, took 0.012 secs
2015-01-07T13:12:56.308+0800 [initandlisten] build index on:
local.startup_log properties: { v: 1, key: { _id: 1 }, name: \"_id_\ns: \"local.startup_log\" }
2015-01-07T13:12:56.308+0800 [initandlisten] added index to empty collection
2015-01-07T13:12:56.308+0800 [initandlisten] command local.$cmd
command: create { create: \"startup_log\keyUpdates:0 numYield
2015-01-07T13:12:56.308+0800 [initandlisten] waiting for connections on port 27017
2015-01-07T13:13:55.948+0800 [clientcursormon] mem (MB) res:38 virt:312
2015-01-07T13:13:55.948+0800 [clientcursormon] mapped (incl journal view):160
2015-01-07T13:13:55.948+0800 [clientcursormon] connections:0
六、测试MongoDB。
以管理员身份新建一个cmd窗口,进入MongoDB的bin目录输入mongo,如出现connecting to:test说明测试通过。
继续测试:
(1).输入use test回车
(2).输入db.foo.save({hello:1, baie:2})回车
(3).输入db.foo.find()回车
如果出现类似
{ \"_id\" : ObjectId(\"5073a0a090f93be1455461d2\"), \"hello\" : 1, \"baie\" : 2 }之类信息,说明测试成功数据已经插入数据库,然后输入exit退出。
---------------------------------------------------------------------------------------------------------------
例如
Microsoft Windows [版本 6.0.6002]
版权所有 (C) 2006 Microsoft Corporation。保留所有权利。
C:\\Users\\Administrator>cd D:\\MongoDB\\bin
C:\\Users\\Administrator>d:
D:\\MongoDB\\bin>mongo
MongoDB shell version: 2.6.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type \"help\".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> user test
2015-01-07T13:35:49.948+0800 SyntaxError: Unexpected identifier
> use test
switched to db test
> db.foo.save({hello:1, baie:2})
WriteResult({ \"nInserted\" : 1 })
> db.foo.find()
{ \"_id\" : ObjectId(\"54acc5dc031c75a8cb484b82\"), \"hello\" : 1, \"baie\" : 2 }
> exit
bye
D:\\MongoDB\\bin>
七、注册MongoDB为系统服务(此步骤必须以系统管理员身份运行cmd,否则会报错)
八、以系统管理员身份运行cmd输入并切换至MongoDB的bin目录运行以下语句
九、mongod.exe --dbpath=d:\\mongodb\\db --logpath=d:\\mongodb\\logs\\mongodb.log --install --serviceName \"MongoDB\"
十、回车
十一、如果控制台出现类似
Tue Oct 09 12:05:15 Service can be started from the command line with 'net s
tart MongoDB'这样的语句,说明服务已经注册成功。
十二、在cmd中输入net start MongoDB即可启动MongoDB数据库服务,此时控制台输出Mongo DB 服务已经启动成功,说明系统启动成功。
十三、如果出现发生系统错误 1067 请把db目录下的mongod.lock文件删除后重新输入net start MongoDB启动服务即可。
---------------------------------------------------------------------------------------------------------------
例如
D:\\MongoDB\\bin>mongod.exe --dbpath=d:\\mongodb\\db --logpath=d:\\mongodb\\logs\\mongodb.log --install --serviceName \"MongoDB\"
2015-01-07T13:41:14.495+0800 log file \"d:\\mongodb\\logs\\mongodb.log\" exists; moved to \"d:\\mongodb\\logs\\mongodb.log.2015-01-07T05-41-14\".
D:\\MongoDB\\bin>net start MongoDB
MongoDB 服务正在启动 .
MongoDB 服务无法启动。
系统出错。
发生系统错误 1067。
进程意外终止。
正常结果如下:
因篇幅问题不能全部显示,请点此查看更多更全内容