转: 将MongoDB加入到Windows服务

本文详细介绍了如何在Windows环境下安装MongoDB并将其加入系统服务。包括设置数据库路径、日志文件、绑定IP等参数,以及安装后的启动和停止命令。

安装:

mongod.exe --bind_ip 127.0.0.1  --logpath D:\02_mogodb\logs\log.txt --logappend --dbpath D:\02_mogodb\data --directoryperdb –-install

执行后安装到Windows服务,注意需要在data目录下建议db目录

 

1、Windows下的安装

官方的地址是:http://www.mongodb.org/pages/viewpage.action?pageId=20742425

2、加入到Windows服务,可以通过命令行的方式启动,官方也有说明,只是每次找的时候比较麻烦,所以记录下来,并简单的说明

安装以后,进入到mongo的bin目录下。例如:

 

  1. F:/mongo/bin>  
 

 

执行 mongod.exe --help 命令可以查看帮助信息:

 

  1. F:/mongo/bin>mongod.exe --help  
  2. ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data  
  3. **       see http://blog.mongodb.org/post/137788967/32-bit-limitations  
  4. **       with --dur, the limit is lower  
  5. Allowed options:  
  6. General options:  
  7.   -h [ --help ]         show this usage information  
  8.   --version             show version information  
  9.   -f [ --config ] arg   configuration file specifying additional options  
  10.   -v [ --verbose ]      be more verbose (include multiple times for more  
  11.                         verbosity e.g. -vvvvv)  
  12.   --quiet               quieter output  
  13.   --port arg            specify port number  
  14.   --bind_ip arg         comma separated list of ip addresses to listen on - all  
  15.                         local ips by default  
  16.   --logpath arg         log file to send write to instead of stdout - has to be  
  17.                         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 (only for  
  22.                         replica sets)  
  23.   --auth                run with security  
  24.   --cpu                 periodically show cpu and iowait utilization  
  25.   --dbpath arg          directory for datafiles  
  26.   --diaglog arg         0=off 1=W 2=R 3=both 7=W+some reads  
  27.   --directoryperdb      each database will be stored in a separate directory  
  28.   --journal             enable journaling  
  29.   --journalOptions arg  journal diagnostic options  
  30.   --ipv6                enable IPv6 support (disabled by default)  
  31.   --jsonp               allow JSONP access via http (has security implications)  
  32.   --maxConns arg        max number of simultaneous connections  
  33.   --noauth              run without security  
  34.   --nohttpinterface     disable http interface  
  35.   --noprealloc          disable data file preallocation - will often hurt  
  36.                         performance  
  37.   --noscripting         disable scripting engine  
  38.   --notablescan         do not allow table scans  
  39.   --nssize arg (=16)    .ns file size (in MB) for new databases  
  40.   --objcheck            inspect client data for validity on receipt  
  41.   --profile arg         0=off 1=slow, 2=all  
  42.   --quota               limits each database to a certain number of files (8  
  43.                         default)  
  44.   --quotaFiles arg      number of files allower per db, requires --quota  
  45.   --rest                turn on simple rest api  
  46.   --repair              run repair on all dbs  
  47.   --repairpath arg      root directory for repair files - defaults to dbpath  
  48.   --slowms arg (=100)   value of slow for profile and console log  
  49.   --smallfiles          use a smaller default file size  
  50.   --syncdelay arg (=60) seconds between disk syncs (0=never, but not  
  51.                         recommended)  
  52.   --sysinfo             print some diagnostic system information  
  53.   --upgrade             upgrade db if needed  
  54. Windows Service Control Manager options:  
  55.   --install                install mongodb service  
  56.   --remove                 remove mongodb service  
  57.   --reinstall              reinstall mongodb service (equivilant of mongod  
  58.                            --remove followed by mongod --install)  
  59.   --serviceName arg        windows service name  
  60.   --serviceDisplayName arg windows service display name  
  61.   --serviceDescription arg windows service description  
  62.   --serviceUser arg        user name service executes as  
  63.   --servicePassword arg    password used to authenticate serviceUser  
  64. Replication options:  
  65.   --fastsync            indicate that this instance is starting from a dbpath  
  66.                         snapshot of the repl peer  
  67.   --autoresync          automatically resync if slave data is stale  
  68.   --oplogSize arg       size limit (in MB) for op log  
  69. Master/slave options:  
  70.   --master              master mode  
  71.   --slave               slave mode  
  72.   --source arg          when slave: specify master as <server:port>  
  73.   --only arg            when slave: specify a single database to replicate  
  74.   --slavedelay arg      specify delay (in seconds) to be used when applying  
  75.                         master ops to slave  
  76. Replica set options:  
  77.   --replSet arg         arg is <setname>[/<optionalseedhostlist>]  
  78. Sharding options:  
  79.   --configsvr           declare this is a config db of a cluster; default port  
  80.                         27019; default dir /data/configdb  
  81.   --shardsvr            declare this is a shard db of a cluster; default port  
  82.                         27018  
  83.   --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this  
  84.                         is on by default for now, but default will switch  
 

 

下面来将MongoDB加入到Windows服务:

 

  1. F:/mongo/bin>mongod.exe --dbpath=F:/mongo/data --logpath=F:/mongo/logs/logs.txt  
  2. --logappend --bind_ip 127.0.0.1 --directoryperdb --install  
 

 

说说各个参数吧:

--dbpath这个指定数据库的存放路径

--logpath指定日志文件

--logappend追加的方式

--bind_ip绑定IP地址

--directoryperdb每个数据库单独存放在一个文件夹内

--install安装到Windows服务

 

成功之后可以看到类似下面的信息:

 

  1. all output going to: F:/mongo/logs/logs.txt  
  2. Creating service MongoDB.  
  3. Service creation successful.  
  4. Service can be started from the command line via 'net start "MongoDB"'.  
 

 

以后可以通过cmd的命令行的方式来启动和停止,不会出现那个“不能关闭”的黑框框了。

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值