设为首页 收藏本站
查看: 758|回复: 0

[经验分享] Windows Server 2008 R2 SP1安装MongoDB

[复制链接]

尚未签到

发表于 2018-10-27 14:25:42 | 显示全部楼层 |阅读模式
  本文简单介绍在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进行帮助查看
  

  


  • C:\>d:\mongodb\bin\mongod.exe --help
  • Allowed options:

  • General options:
  •   -h [ --help ]               show this usage information
  •   --version                   show version information
  •   -f [ --config ] arg         configuration file specifying additional options
  •   -v [ --verbose ]            be more verbose (include multiple times for more
  •                               verbosity e.g. -vvvvv)
  •   --quiet                     quieter output
  •   --port arg                  specify port number - 27017 by default
  •   --bind_ip arg               comma separated list of ip addresses to listen on
  •                               - all local ips by default
  •   --maxConns arg              max number of simultaneous connections - 20000 by
  •                               default
  •   --objcheck                  inspect client data for validity on receipt
  •   --logpath arg               log file to send write to instead of stdout - has
  •                               to be a file, not directory
  •   --logappend                 append to logpath instead of over-writing
  •   --pidfilepath arg           full path to pidfile (if not set, no pidfile is
  •                               created)
  •   --keyFile arg               private key for cluster authentication
  •   --auth                      run with security
  •   --cpu                       periodically show cpu and iowait utilization
  •   --dbpath arg                directory for datafiles - defaults to \data\db\
  •   --diaglog arg               0=off 1=W 2=R 3=both 7=W+some reads
  •   --directoryperdb            each database will be stored in a separate
  •                               directory
  •   --ipv6                      enable IPv6 support (disabled by default)
  •   --journal                   enable journaling
  •   --journalCommitInterval arg how often to group/batch commit (ms)
  •   --journalOptions arg        journal diagnostic options
  •   --jsonp                     allow JSONP access via http (has security
  •                               implications)
  •   --noauth                    run without security
  •   --nohttpinterface           disable http interface
  •   --nojournal                 disable journaling (journaling is on by default
  •                               for 64 bit)
  •   --noprealloc                disable data file preallocation - will often hurt
  •                               performance
  •   --noscripting               disable scripting engine
  •   --notablescan               do not allow table scans
  •   --nssize arg (=16)          .ns file size (in MB) for new databases
  •   --profile arg               0=off 1=slow, 2=all
  •   --quota                     limits each database to a certain number of files
  •                               (8 default)
  •   --quotaFiles arg            number of files allowed per db, requires --quota
  •   --repair                    run repair on all dbs
  •   --repairpath arg            root directory for repair files - defaults to
  •                               dbpath
  •   --rest                      turn on simple rest api
  •   --slowms arg (=100)         value of slow for profile and console log
  •   --smallfiles                use a smaller default file size
  •   --syncdelay arg (=60)       seconds between disk syncs (0=never, but not
  •                               recommended)
  •   --sysinfo                   print some diagnostic system information
  •   --upgrade                   upgrade db if needed

  • Windows Service Control Manager options:
  •   --install                install Windows service
  •   --remove                 remove Windows service
  •   --reinstall              reinstall Windows service (equivalent to --remove
  •                            followed by --install)
  •   --serviceName arg        Windows service name
  •   --serviceDisplayName arg Windows service display name
  •   --serviceDescription arg Windows service description
  •   --serviceUser arg        account for service execution
  •   --servicePassword arg    password used to authenticate serviceUser

  • Replication options:
  •   --oplogSize arg       size to use (in MB) for replication op log. default is
  •                         5% of disk space (i.e. large is good)

  • Master/slave options:
  •   --master              master mode
  •   --slave               slave mode
  •   --source arg          when slave: specify master as
  •   --only arg            when slave: specify a single database to replicate
  •   --slavedelay arg      specify delay (in seconds) to be used when applying
  •                         master ops to slave
  •   --autoresync          automatically resync if slave data is stale

  • Replica set options:
  •   --replSet arg           arg is [/]
  •   --replIndexPrefetch arg specify index prefetching if secondary)
  •                           [none|_id_only|all]

  • Sharding options:
  •   --configsvr           declare this is a config db of a cluster; default port
  •                         27019; default dir /data/configdb
  •   --shardsvr            declare this is a shard db of a cluster; default port
  •                         27018
  •   --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this
  •                         is on by default for now, but default will switch
  

  以上是帮助详细内容
  

  


  • C:\ >d:\mongodb\bin\mongod.exe --dbpath=d:\data\db
  • Sun Dec 30 20:22:19 [initandlisten] MongoDB starting : pid=2512 port=27017 ddbpath=d:\data\db 64-bit host=WIN-6HB65GUTBNC

  • Sun Dec 30 20:22:19 [initandlisten] db version v2.2.2, pdfile version 4.5
  • Sun Dec 30 20:22:19 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
  • Sun Dec 30 20:22:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2,
  • service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
  • Sun Dec 30 20:22:19 [initandlisten] options: { dbpath: "d:\data\db" }
  • Sun Dec 30 20:22:19 [initandlisten] journal ddir=d:/data/db/journal
  • Sun Dec 30 20:22:19 [initandlisten] recover : no journal files present, no recovery needed
  • Sun Dec 30 20:22:19 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.1
  • Sun Dec 30 20:22:29 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.2
  • Sun Dec 30 20:22:39 [initandlisten] waiting for connections on port 27017
  • 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
  


  • C:\Users\Administrator>d:\mongodb\bin\mongod.exe --dbpath=d:\data\db
  • Sun Dec 30 20:22:19 [initandlisten] MongoDB starting : pid=2512 port=27017 ddbpath=d:\data\db 64-bit host=WIN-6HB65GUTBNC

  • Sun Dec 30 20:22:19 [initandlisten] db version v2.2.2, pdfile version 4.5
  • Sun Dec 30 20:22:19 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
  • Sun Dec 30 20:22:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2,
  • service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
  • Sun Dec 30 20:22:19 [initandlisten] options: { dbpath: "d:\data\db" }
  • Sun Dec 30 20:22:19 [initandlisten] journal ddir=d:/data/db/journal
  • Sun Dec 30 20:22:19 [initandlisten] recover : no journal files present, no recovery needed
  • Sun Dec 30 20:22:19 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.1
  • Sun Dec 30 20:22:29 [initandlisten] preallocating a journal file d:/data/db/journal/prealloc.2
  • Sun Dec 30 20:22:39 [initandlisten] waiting for connections on port 27017
  • Sun Dec 30 20:22:39 [websvr] admin web console waiting for connections on port 28017
  • Sun Dec 30 20:32:19 Ctrl-C signal
  • Sun Dec 30 20:32:19 [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
  • Sun Dec 30 20:32:19 [consoleTerminate] now exiting
  • Sun Dec 30 20:32:19 dbexit:
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: going to close listening sockets...
  • Sun Dec 30 20:32:19 [consoleTerminate] closing listening socket: 368
  • Sun Dec 30 20:32:19 [consoleTerminate] closing listening socket: 376
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: going to flush diaglog...
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: going to close sockets...
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: waiting for fs preallocator...
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: lock for final commit...
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: final commit...
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: closing all files...
  • Sun Dec 30 20:32:19 [consoleTerminate] closeAllFiles() finished
  • Sun Dec 30 20:32:19 [consoleTerminate] journalCleanup...
  • Sun Dec 30 20:32:19 [consoleTerminate] removeJournalFiles
  • Sun Dec 30 20:32:19 [consoleTerminate] shutdown: removing fs lock...
  • 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
  


  • C:\ >d:\mongodb\bin\mongod.exe --dbpath=d:\data\db --logpath=d:\mongodb\logs\mongodb.log --install
  • all output going to: d:\mongodb\logs\mongodb.log
  • 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”回车即可访问。
  


  • C:\>d:\mongodb\bin\mongo.exe --help
  • MongoDB shell version: 2.2.2
  • usage: d:\mongodb\bin\mongo.exe [options] [db address] [file names (ending in .js)]
  • db address can be:
  •   foo                   foo database on local machine
  •   192.169.0.5/foo       foo database on 192.168.0.5 machine
  •   192.169.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999
  • options:
  •   --shell               run the shell after executing files
  •   --nodb                don't connect to mongod on startup - no 'db address'
  •                         arg expected
  •   --norc                will not run the ".mongorc.js" file on start up
  •   --quiet               be less chatty
  •   --port arg            port to connect to
  •   --host arg            server to connect to
  •   --eval arg            evaluate javascript
  •   -u [ --username ] arg username for authentication
  •   -p [ --password ] arg password for authentication
  •   -h [ --help ]         show this usage information
  •   --version             show version information
  •   --verbose             increase verbosity
  •   --ipv6                enable IPv6 support (disabled by default)

  • file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
  

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

  


  • Sun Dec 30 21:05:49 Trying to start Windows service 'MongoDB'
  • Sun Dec 30 21:05:49 Service running
  • Sun Dec 30 21:05:49 [initandlisten] MongoDB starting : pid=3884 port=27017 ddbpath=d:\data\db 64-bit host=WIN-6HB65GUTBNC
  • Sun Dec 30 21:05:49 [initandlisten] db version v2.2.2, pdfile version 4.5
  • Sun Dec 30 21:05:49 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
  • 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
  • Sun Dec 30 21:05:49 [initandlisten] options: { dbpath: "d:\data\db", logpath: "d:\mongodb\logs\mongodb.log", service: true }
  • Sun Dec 30 21:05:50 [initandlisten] journal ddir=d:/data/db/journal
  • Sun Dec 30 21:05:50 [initandlisten] recover : no journal files present, no recovery needed
  • Sun Dec 30 21:05:50 [initandlisten] waiting for connections on port 27017
  • Sun Dec 30 21:05:50 [websvr] admin web console waiting for connections on port 28017
  • Sun Dec 30 21:10:06 [initandlisten] connection accepted from 127.0.0.1:16061 #5 (1 connection now open)
  • Sun Dec 30 21:11:34 [initandlisten] connection accepted from 124.193.159.8:27974 #6 (2 connections now open)
  • Sun Dec 30 21:12:52 [serviceShutdown] got SERVICE_CONTROL_STOP request from Windows Service Control Manager, will terminate after current cmd ends
  • Sun Dec 30 21:12:52 [serviceShutdown] now exiting
  • Sun Dec 30 21:12:52 dbexit:
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: going to close listening sockets...
  • Sun Dec 30 21:12:52 [serviceShutdown] closing listening socket: 412
  • Sun Dec 30 21:12:52 [serviceShutdown] closing listening socket: 420
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: going to flush diaglog...
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: going to close sockets...
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: waiting for fs preallocator...
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: lock for final commit...
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: final commit...
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: closing all files...
  • Sun Dec 30 21:12:52 [serviceShutdown] closeAllFiles() finished
  • Sun Dec 30 21:12:52 [serviceShutdown] journalCleanup...
  • Sun Dec 30 21:12:52 [conn6] end connection 124.193.159.8:27974 (1 connection now open)
  • Sun Dec 30 21:12:52 [conn5] end connection 127.0.0.1:16061 (1 connection now open)
  • Sun Dec 30 21:12:52 [serviceShutdown] removeJournalFiles
  • Sun Dec 30 21:12:52 [serviceShutdown] shutdown: removing fs lock...
  • Sun Dec 30 21:12:52 [initandlisten] now exiting
  • Sun Dec 30 21:12:52 dbexit: ; exiting immediately
  




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-627185-1-1.html 上篇帖子: 安装MongoDB遇到的问题 下篇帖子: MongoDB 连接测试
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表