Windows Server 2008 R2 SP1安裝MongoDB

本文简单介绍在Windows Server 2008 R2 SP1安装MongoDB
1、 版本选择和下载安装源文件,由于是在64位操作系统且为2008 R2上安装的,故选择版本mongodb-win32-x86_64-2008plus-2.2.2.zip,读者根据自己的实际应用环境进行选择
http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.2.2.zip

2、解压到 d:\,再重命名为mongodb,路径为d:\mongodb
3、设置数据库所在目录
创建目录 d:\data\db
4、启动MongoDB服务,可以先通过—help进行幫助查看

  1. C:\>d:\mongodb\bin\mongod.exe --help
  2. Allowed options:
  3. General options:
  4. -h [ --help ] show this usage information
  5. --version show version information
  6. -f [ --config ] arg configuration file specifying additional options
  7. -v [ --verbose ] be more verbose (include multiple times for more
  8. verbosity e.g. -vvvvv)
  9. --quiet quieter output
  10. --port arg specify port number - 27017 by default
  11. --bind_ip arg comma separated list of ip addresses to listen on
  12. - all local ips by default
  13. --maxConns arg max number of simultaneous connections - 20000 by
  14. default
  15. --objcheck inspect client data for validity on receipt
  16. --logpath arg log file to send write to instead of stdout - has
  17. to be a file, not directory
  18. --logappend append to logpath instead of over-writing
  19. --pidfilepath arg full path to pidfile (if not set, no pidfile is
  20. created)
  21. --keyFile arg private key for cluster authentication
  22. --auth run with security
  23. --cpu periodically show cpu and iowait utilization
  24. --dbpath arg directory for datafiles - defaults to \data\db\
  25. --diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads
  26. --directoryperdb each database will be stored in a separate
  27. directory
  28. --ipv6 enable IPv6 support (disabled by default)
  29. --journal enable journaling
  30. --journalCommitInterval arg how often to group/batch commit (ms)
  31. --journalOptions arg journal diagnostic options
  32. --jsonp allow JSONP access via http (has security
  33. implications)
  34. --noauth run without security
  35. --nohttpinterface disable http interface
  36. --nojournal disable journaling (journaling is on by default
  37. for 64 bit)
  38. --noprealloc disable data file preallocation - will often hurt
  39. performance
  40. --noscripting disable scripting engine
  41. --notablescan do not allow table scans
  42. --nssize arg (=16) .ns file size (in MB) for new databases
  43. --profile arg 0=off 1=slow, 2=all
  44. --quota limits each database to a certain number of files
  45. (8 default)
  46. --quotaFiles arg number of files allowed per db, requires --quota
  47. --repair run repair on all dbs
  48. --repairpath arg root directory for repair files - defaults to
  49. dbpath
  50. --rest turn on simple rest api
  51. --slowms arg (=100) value of slow for profile and console log
  52. --smallfiles use a smaller default file size
  53. --syncdelay arg (=60) seconds between disk syncs (0=never, but not
  54. recommended)
  55. --sysinfo print some diagnostic system information
  56. --upgrade upgrade db if needed
  57. Windows Service Control Manager options:
  58. --install install Windows service
  59. --remove remove Windows service
  60. --reinstall reinstall Windows service (equivalent to --remove
  61. followed by --install)
  62. --serviceName arg Windows service name
  63. --serviceDisplayName arg Windows service display name
  64. --serviceDescription arg Windows service description
  65. --serviceUser arg account for service execution
  66. --servicePassword arg password used to authenticate serviceUser
  67. Replication options:
  68. --oplogSize arg size to use (in MB) for replication op log. default is
  69. 5% of disk space (i.e. large is good)
  70. Master/slave options:
  71. --master master mode
  72. --slave slave mode
  73. --source arg when slave: specify master as <server:port>
  74. --only arg when slave: specify a single database to replicate
  75. --slavedelay arg specify delay (in seconds) to be used when applying
  76. master ops to slave
  77. --autoresync automatically resync if slave data is stale
  78. Replica set options:
  79. --replSet arg arg is <setname>[/<optionalseedhostlist>]
  80. --replIndexPrefetch arg specify index prefetching if secondary)
  81. [none|_id_only|all]
  82. Sharding options:
  83. --configsvr declare this is a config db of a cluster; default port
  84. 27019; default dir /data/configdb
  85. --shardsvr declare this is a shard db of a cluster; default port
  86. 27018
  87. --noMoveParanoia turn off paranoid saving of data for moveChunk. this
  88. is on by default for now, but default will switch

以上是幫助详细内容

  1. C:\ >d:\mongodb\bin\mongod.exe --dbpath=d:\data\db
  2. Sun Dec 30 20:22:19 [initandlisten] MongoDB starting : pid=2512 port=27017 ddbpath=d:\data\db 64-bit host=WIN-6HB65GUTBNC
  3. Sun Dec 30 20:22:19 [initandlisten] db version v2.2.2, pdfile version 4.5
  4. Sun Dec 30 20:22:19 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
  5. Sun Dec 30 20:22:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2,
  6. service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
  7. Sun Dec 30 20:22:19 [initandlisten] options: { dbpath: "d:\data\db" }
  8. Sun Dec 30 20:22:19 [initandlisten] journal ddir=d:/data/db/journal
  9. Sun Dec 30 20:22:19 [initandlisten] recover : no journal files present, no recovery needed
  10. Sun Dec 30 20:22:19 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.1
  11. Sun Dec 30 20:22:29 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.2
  12. Sun Dec 30 20:22:39 [initandlisten] waiting for connections on port 27017
  13. Sun Dec 30 20:22:39 [websvr] admin web console waiting for connections on port 28017

通过输出内容可以查看到MongoDB的进程号、监听端口号、版本号、web访问端口等信息
5、可以通过浏览器查看当前各项状态统计信息,例如:http://127.0.0.1:28017/

6、停止 MongoDB服务, Ctrl-C

  1. C:\Users\Administrator>d:\mongodb\bin\mongod.exe --dbpath=d:\data\db
  2. Sun Dec 30 20:22:19 [initandlisten] MongoDB starting : pid=2512 port=27017 ddbpath=d:\data\db 64-bit host=WIN-6HB65GUTBNC
  3. Sun Dec 30 20:22:19 [initandlisten] db version v2.2.2, pdfile version 4.5
  4. Sun Dec 30 20:22:19 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
  5. Sun Dec 30 20:22:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2,
  6. service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
  7. Sun Dec 30 20:22:19 [initandlisten] options: { dbpath: "d:\data\db" }
  8. Sun Dec 30 20:22:19 [initandlisten] journal ddir=d:/data/db/journal
  9. Sun Dec 30 20:22:19 [initandlisten] recover : no journal files present, no recovery needed
  10. Sun Dec 30 20:22:19 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.1
  11. Sun Dec 30 20:22:29 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.2
  12. Sun Dec 30 20:22:39 [initandlisten] waiting for connections on port 27017
  13. Sun Dec 30 20:22:39 [websvr] admin web console waiting for connections on port 28017
  14. Sun Dec 30 20:32:19 Ctrl-C signal
  15. Sun Dec 30 20:32:19 [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
  16. Sun Dec 30 20:32:19 [consoleTerminate] now exiting
  17. Sun Dec 30 20:32:19 dbexit:
  18. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: going to close listening sockets...
  19. Sun Dec 30 20:32:19 [consoleTerminate] closing listening socket: 368
  20. Sun Dec 30 20:32:19 [consoleTerminate] closing listening socket: 376
  21. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: going to flush diaglog...
  22. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: going to close sockets...
  23. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: waiting for fs preallocator...
  24. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: lock for final commit...
  25. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: final commit...
  26. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: closing all files...
  27. Sun Dec 30 20:32:19 [consoleTerminate] closeAllFiles() finished
  28. Sun Dec 30 20:32:19 [consoleTerminate] journalCleanup...
  29. Sun Dec 30 20:32:19 [consoleTerminate] removeJournalFiles
  30. Sun Dec 30 20:32:19 [consoleTerminate] shutdown: removing fs lock...
  31. Sun Dec 30 20:32:19 dbexit: really exiting now

7、将MongoDB加入到Windows服务中,
创建文件D:\mongodb\logs\mongodb.log,再执行如下命令:d:\mongodb\bin\mongod.exe --dbpath=d:\data\db --logpath=d:\mongodb\logs\mongodb.log –install

  1. C:\ >d:\mongodb\bin\mongod.exe --dbpath=d:\data\db --logpath=d:\mongodb\logs\mongodb.log --install
  2. all output going to: d:\mongodb\logs\mongodb.log
  3. log file [d:\mongodb\logs\mongodb.log] exists; copied to temporary file [d:\mongodb\logs\mongodb.log.2012-12-30T12-30-11]

这时可以通过net start "Mongo DB"来启动服务:
C:\>net start "Mongo DB"

Mongo DB 服务已经启动成功。

通过net stop"Mongo DB"来关闭服务:
C:\>net stop "Mongo DB"
发生系统错误 109。

管道已结束。
关闭的时候会有个错误提示,估计是个bug,可以忽略,虽然不影响,但总是感觉不好,希望MongoDB团队尽快解决这个小bug。
8、访问MongoDB,双击D:\mongodb\bin\mongo.exe,或者在cmd命令提示符下输入
” D:\mongodb\bin\mongo.exe”回车即可访问。

  1. C:\>d:\mongodb\bin\mongo.exe --help
  2. MongoDB shell version: 2.2.2
  3. usage: d:\mongodb\bin\mongo.exe [options] [db address] [file names (ending in .js)]
  4. db address can be:
  5. foo foo database on local machine
  6. 192.169.0.5/foo foo database on 192.168.0.5 machine
  7. 192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
  8. options:
  9. --shell run the shell after executing files
  10. --nodb don't connect to mongod on startup - no 'db address'
  11. arg expected
  12. --norc will not run the ".mongorc.js" file on start up
  13. --quiet be less chatty
  14. --port arg port to connect to
  15. --host arg server to connect to
  16. --eval arg evaluate javascript
  17. -u [ --username ] arg username for authentication
  18. -p [ --password ] arg password for authentication
  19. -h [ --help ] show this usage information
  20. --version show version information
  21. --verbose increase verbosity
  22. --ipv6 enable IPv6 support (disabled by default)
  23. file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified

以下是通过服务的方式启动的时候的日志内容:

  1. Sun Dec 30 21:05:49 Trying to start Windows service 'MongoDB'
  2. Sun Dec 30 21:05:49 Service running
  3. Sun Dec 30 21:05:49 [initandlisten] MongoDB starting : pid=3884 port=27017 ddbpath=d:\data\db 64-bit host=WIN-6HB65GUTBNC
  4. Sun Dec 30 21:05:49 [initandlisten] db version v2.2.2, pdfile version 4.5
  5. Sun Dec 30 21:05:49 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
  6. Sun Dec 30 21:05:49 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
  7. Sun Dec 30 21:05:49 [initandlisten] options: { dbpath: "d:\data\db", logpath: "d:\mongodb\logs\mongodb.log", service: true }
  8. Sun Dec 30 21:05:50 [initandlisten] journal ddir=d:/data/db/journal
  9. Sun Dec 30 21:05:50 [initandlisten] recover : no journal files present, no recovery needed
  10. Sun Dec 30 21:05:50 [initandlisten] waiting for connections on port 27017
  11. Sun Dec 30 21:05:50 [websvr] admin web console waiting for connections on port 28017
  12. Sun Dec 30 21:10:06 [initandlisten] connection accepted from 127.0.0.1:16061 #5 (1 connection now open)
  13. Sun Dec 30 21:11:34 [initandlisten] connection accepted from 124.193.159.8:27974 #6 (2 connections now open)
  14. Sun Dec 30 21:12:52 [serviceShutdown] got SERVICE_CONTROL_STOP request from Windows Service Control Manager, will terminate after current cmd ends
  15. Sun Dec 30 21:12:52 [serviceShutdown] now exiting
  16. Sun Dec 30 21:12:52 dbexit:
  17. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: going to close listening sockets...
  18. Sun Dec 30 21:12:52 [serviceShutdown] closing listening socket: 412
  19. Sun Dec 30 21:12:52 [serviceShutdown] closing listening socket: 420
  20. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: going to flush diaglog...
  21. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: going to close sockets...
  22. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: waiting for fs preallocator...
  23. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: lock for final commit...
  24. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: final commit...
  25. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: closing all files...
  26. Sun Dec 30 21:12:52 [serviceShutdown] closeAllFiles() finished
  27. Sun Dec 30 21:12:52 [serviceShutdown] journalCleanup...
  28. Sun Dec 30 21:12:52 [conn6] end connection 124.193.159.8:27974 (1 connection now open)
  29. Sun Dec 30 21:12:52 [conn5] end connection 127.0.0.1:16061 (1 connection now open)
  30. Sun Dec 30 21:12:52 [serviceShutdown] removeJournalFiles
  31. Sun Dec 30 21:12:52 [serviceShutdown] shutdown: removing fs lock...
  32. Sun Dec 30 21:12:52 [initandlisten] now exiting
  33. Sun Dec 30 21:12:52 dbexit: ; exiting immediately

本文出自 “开源一员” 博客,请务必保留此出处http://521cto.blog.51cto.com/950229/1104732

更多相关文章
一周排行