Mongo启动说明

来源:互联网 发布:涉水险有必要买吗 知乎 编辑:程序博客网 时间:2024/06/05 12:42

启动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();


原文地址:http://blog.csdn.net/java3344520/article/details/6875893

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 mac玩刺客信条卡怎么办 阴部长了个疙瘩怎么办 两个人觉得累了怎么办 朋友把我拉黑了怎么办 下雨了怎么办我好想你 雨停怎么办我好想你 下雨天怎么办我好想你 天谕账号忘记了怎么办 天谕账号被冻结怎么办 促黄体生成素低怎么办 地暖家里太干燥怎么办 剑灵摧毁了东西怎么办 想打嗝打不出来怎么办 孩子满100天要怎么办 宝宝吃奶粉过敏了怎么办 1岁宝宝不喝奶粉怎么办 母乳不够宝宝不喝奶粉怎么办 宝宝吃奶粉上火了怎么办 我小孩不喝奶粉怎么办 2岁宝宝不喝奶粉怎么办 婴儿吃奶粉上火了怎么办 100天的宝宝咳嗽怎么办 40天的小孩咳嗽怎么办 40天的婴儿咳嗽怎么办 50天的婴儿咳嗽怎么办 宝宝20天感冒了怎么办 1个月宝宝咳嗽怎么办 40天的宝宝干咳怎么办 百天的宝宝咳嗽怎么办 50天的孩子咳嗽怎么办 百天宝宝咳嗽有痰怎么办 1岁半宝宝拉肚子怎么办 百天的宝宝拉肚子怎么办 激战2帧数三十多怎么办 太受欢迎了怎么办txt微 太受欢迎了怎么办网盘 太受欢迎了怎么办微盘 我太受欢迎了该怎么办h 我太受欢迎了该怎么办1 卡培他滨副作用怎么办 究极风暴4卡怎么办