Mongo启动说明

启动MongoDB

         昨天根据官方的例子来做的,没有指定任何自己的参数,完全采用Mongo默认的路径和参数来进行安装的,如果没有root的情况下,是不能把数据库的默认路径建立在根目录的/data/db下的,因此,我想自己定义一个目录来存放数据文件,如何进行呢?

    mongod还有很多的启动选择项,运行mongod --help就可以查看所有的选择项

[mongodb@localhost bin]$ ./mongod --help
Sat Oct 15 14:17:11 
Sat Oct 15 14:17:11 ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Sat Oct 15 14:17:11 **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Sat Oct 15 14:17:11 **       with --journal, the limit is lower
Sat Oct 15 14:17:11 
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
  --bind_ip arg              comma separated list of ip addresses to listen on   - all local ips by default

  --dbpath arg              directory for datafiles

  --maxConns arg          max number of simultaneous connections

 --logpath arg               log file to send write to instead of stdout - has to be a file, not directory

    其中,启动选择项可以直接写在在mongod后面,也可以指定配置文件,用文件来加载各种启动项,如,如指定mongodb的文件存放路径来说,./mongod --dbpath=/home/mongodb/data/db     MongoDB 服务端的默认连接端口是 27017  同时也可以指定端口启动,启动端口使用 --port参数选项

主要参数说如下:

dbpath = /home/mongodb/data
    指定数据库的存储目录,如果不设置则以mongodb的根目录为目录,当MongoDB启动之后,在数据库的存储目录下会创建一个mongod.lock文件,它是用来记录当前的mongod的进程号,同时也用于区分各个mongod的进程实例,所以不同的mongod进程实例是不能用相同的dbpath。
logpath = /home/mongodb/mongodb.log
    指定日志输出的路径,如果没有设置logappend = true,系统会清除原来的日志记录,把已有的文件进行覆盖。
logappend = true
    日志以追加的方式进行记录
bind_ip = 192.168.86.111
    指定对外服务的绑定ip,这里指定内网的ip方式,如果外网无特殊的处理方式是无法进行连接。
port = 27017
    指定服务器的监听端口号,默认是27017,如果单个机器要运行多个mongod进程,则需要给每个进程指定不同的端口号。
fork = true
    指定以守护进程的方式来启动MongoDB,如果不指定,在启动mongod命令是加“&”也是可以的。
auth = true
    启动mongodb客户端登录的认证机制。
master = true
    指定该机器为主从模式下的主机器。


     一般来说,使用参数配置文件启动,以便记忆和查看,注意:没有默认的启动参数文件,-f 选项可以指定配置文件的位置,

首先新建配置文件:

[mongodb@localhost bin]$ vi /home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf
# This is an example config file for MongoDB.
dbpath = /data/db/mongodb
logpath =
/data/db
/mongodb/mongod.log
bind_ip = 127.0.0.1
noauth = true
verbose = false
fork = true
nohttpinterface = true
~
</mongodb-linux-i686-2.0.0/mongodb.conf" [新] 8L, 273C 已写入 

 手动启动使用配置文件:
[mongodb@localhost bin]$ /home/mongodb/mongodb-linux-i686-2.0.0/bin/mongod -f /home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf 
all output going to: /data/db/mongod.log

如果将mongoDB服务加入随机启动

vi /etc/rc.local

使用vi编辑器打开配置文件,并在其中加入下面一行代码

/home/mongodb/mongodb-linux-i686-2.0.0/bin/mongod -f /home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf -

-logappend


启动日志信息查看:

[root@localhost ~]# tail -100f /data/db/mongod.log

Thu Oct 20 09:59:18 
Thu Oct 20 09:59:18 [initandlisten] MongoDB starting : pid=5612 port=27017 dbpath=/data/db 32-bit host=localhost --这里是配置的路径和主机,端口
Thu Oct 20 09:59:18 [initandlisten] 
Thu Oct 20 09:59:18 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data--使用内存大小
Thu Oct 20 09:59:18 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 20 09:59:18 [initandlisten] **       with --journal, the limit is lower
Thu Oct 20 09:59:18 [initandlisten] 
Thu Oct 20 09:59:18 [initandlisten] db version v2.0.0, pdfile version 4.5  --版本号
Thu Oct 20 09:59:18 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Thu Oct 20 09:59:18 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Thu Oct 20 09:59:18 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/home/mongodb/mongodb-linux-i686-2.0.0/mongodb.conf", dbpath: "/data/db", logpath: "/data/db/mongod.log", noauth: "true" } --启动参数
Thu Oct 20 09:59:18 [initandlisten] waiting for connections on port 27017 --监听端口
Thu Oct 20 09:59:18 [websvr] admin web console waiting for connections on port 28017 --web控制台端口

这些信息是很有用的,对于管理和维护是很重要的。


停止MongoDB
千万要强调的是千万不要使用kill -9去关闭mongod!这样数据库会不理一切直接杀死该进程,会使得数据文件损坏。
稳妥的方法是使用kill -2 pid去关闭mongod,也就是当mongod进程接受到关闭指令后会等待当前运行操作或文件分配等操作完毕后,关闭所有打开的连接,并将缓存的数据刷新到磁盘后才正式关闭。
最稳妥的方式是使用shutdown命令来结束
>  use admin
switched to db admin
>  db.shutdownServer();


附:WINDOWS的安装和配置参考

http://tech.it168.com/a2011/0417/1179/000001179081_1.shtml

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值