|
[root@node1 ~]# tar xvf mongodb-linux-x86_64-2.4.5-rc0.tgz
mongodb-linux-x86_64-2.4.5-rc0/README
mongodb-linux-x86_64-2.4.5-rc0/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-2.4.5-rc0/GNU-AGPL-3.0
mongodb-linux-x86_64-2.4.5-rc0/bin/mongodump
mongodb-linux-x86_64-2.4.5-rc0/bin/mongorestore
mongodb-linux-x86_64-2.4.5-rc0/bin/mongoexport
mongodb-linux-x86_64-2.4.5-rc0/bin/mongoimport
mongodb-linux-x86_64-2.4.5-rc0/bin/mongostat
mongodb-linux-x86_64-2.4.5-rc0/bin/mongotop
mongodb-linux-x86_64-2.4.5-rc0/bin/mongooplog
mongodb-linux-x86_64-2.4.5-rc0/bin/mongofiles
mongodb-linux-x86_64-2.4.5-rc0/bin/bsondump
mongodb-linux-x86_64-2.4.5-rc0/bin/mongoperf
mongodb-linux-x86_64-2.4.5-rc0/bin/mongosniff
mongodb-linux-x86_64-2.4.5-rc0/bin/mongod
mongodb-linux-x86_64-2.4.5-rc0/bin/mongos
mongodb-linux-x86_64-2.4.5-rc0/bin/mongo
[root@node1 ~]#
[root@node1 ~]# mv mongodb-linux-x86_64-2.4.5-rc0 /usr/local/mongodb
[root@node1 ~]# cd /usr/local/mongodb/
[root@node1 mongodb]# ls
bin GNU-AGPL-3.0 README THIRD-PARTY-NOTICES
[root@node1 mongodb]#mkdir data
[root@node1 mongodb]# mkdir logs
[root@node1 mongodb]#/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data/ --logpath=/usr/local/mongodb/logs/mongodb.log
Sat Jul 27 15:35:23.920 [initandlisten] MongoDB starting : pid=28673 port=27017 dbpath=/usr/local/mongodb/data/ 64-bit host=node1
Sat Jul 27 15:35:23.955 [initandlisten] db version v2.4.5-rc0
Sat Jul 27 15:35:23.955 [initandlisten] git version: 13b33da1e49973dcb71fa5680f7f4bd8612f1010
Sat Jul 27 15:35:23.955 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Sat Jul 27 15:35:23.955 [initandlisten] allocator: tcmalloc
Sat Jul 27 15:35:23.955 [initandlisten] options: { dbpath: "/usr/local/mongodb/data/", logpath: "/usr/local/mongodb/logs/mongodb.log" }
Sat Jul 27 15:35:23.982 [initandlisten] journal dir=/usr/local/mongodb/data/journal
Sat Jul 27 15:35:23.982 [initandlisten] recover : no journal files present, no recovery needed
Sat Jul 27 15:35:24.152 [FileAllocator] allocating new datafile /usr/local/mongodb/data/local.ns, filling with zeroes...
Sat Jul 27 15:35:24.152 [FileAllocator] creating directory /usr/local/mongodb/data/_tmp
Sat Jul 27 15:35:26.358 [FileAllocator] done allocating datafile /usr/local/mongodb/data/local.ns,> Sat Jul 27 15:35:26.358 [FileAllocator] allocating new datafile /usr/local/mongodb/data/local.0, filling with zeroes...
Sat Jul 27 15:35:37.883 [FileAllocator] done allocating datafile /usr/local/mongodb/data/local.0,>
Sat Jul 27 15:35:37.922 [initandlisten] command local.$cmd command: { create: "startup_log",> Sat Jul 27 15:35:37.954 [initandlisten] waiting for connections on port 27017
Sat Jul 27 15:35:37.954 [websvr] admin web console waiting for connections on port 28017
为了便于以后启动,我们可以将命令行参数写成配置文件。
[root@node1 mongodb]# mkdir etc
[root@node1 mongodb]# vim mongodb.conf
dbpath=/usr/local/mongodb/data/
logpath=/usr/local/mongodb/logs/mongodb.log
[root@node1 mongodb]# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf
停止数据库:
[root@node1 logs]# /usr/local/mongodb/bin/mongo
MongoDB shell version: 2.4.5-rc0
connecting to: test
> use admin
switched to db admin
> db.shutdownServer()
Sat Jul 27 17:20:45.674 DBClientCursor::init call() failed
server should be down...
Sat Jul 27 17:20:45.675 trying reconnect to 127.0.0.1:27017
Sat Jul 27 17:20:45.694 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
[root@node1 ~]#/usr/local/mongodb/bin/mongod -h
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 # 静默模式, 安静输出
--port arg #指定服务运行端口号,默认端口27017
--bind_ip arg # 绑定服务IP,若绑定127.0.0.1,则只能本机访问,不指定默认本地所有IP
--maxConns arg # 最大同时连接数 默认2000
--logpath arg # 指定MongoDB日志文件,注意是指定文件不是目录
--logappend # 使用追加的方式写日志
--pidfilepath arg # PID File 的完整路径,如果没有设置,则没有PID文件
--keyFile arg # 集群的私钥的完整路径,只对于Replica Set 架构有效
--setParameter arg Set a configurable parameter # 设置参数
--nounixsocket # 禁用Unix套接字监听
--unixSocketPrefix arg # UNIX域套接字替代目录,(默认为 /tmp)
--fork # 以守护进程的方式运行MongoDB,创建服务器进程
--syslog log to system's syslog facility instead of file or stdout # 系统日志
--auth # 启用验证
--cpu # 定期显示CPU的CPU利用率和iowait
--dbpath arg # 指定数据库路径
--diaglog arg # diaglog选项 0=off 1=W 2=R 3=both 7=W+some reads
--directoryperdb # 设置每个数据库将被保存在一个单独的目录
--ipv6 enable IPv6 support (disabled by default) # 开启ipv6
--journal # 启用日志选项,MongoDB的数据操作将会写入到journal文件夹的文件里。
# Mongodb在1.8版本之后开始支持journal,就是我们常说的redo log,用于故障恢复和持久化。
在2.0之后的版本,journal都是默认打开的,以确保数据安全。
--journalCommitInterval arg how often to group/batch commit (ms)
--journalOptions arg journal diagnostic options
--jsonp # 允许JSONP形式通过HTTP访问(有安全影响)
--noauth # 不启用验证
--nohttpinterface # 关闭http接口,默认关闭27018端口访问
--nojournal disable journaling (journaling is on by default
for 64 bit)
--noprealloc # 禁用数据文件预分配(往往影响性能)
--noscripting # 禁用脚本引擎
--notablescan # 不允许表扫描
--nssize arg (=16) # 设置信数据库.ns文件大小(MB)
--profile arg # 档案参数 0=off 1=slow, 2=all
--quota # 限制每个数据库的文件数,设置默认为8
--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 # 开启简单的rest API
--shutdown kill a running server (for init scripts)
--slowms arg (=100) value of slow for profile and console log
--smallfiles # 使用较小的默认文件
--syncdelay arg (=60) # 数据写入磁盘的时间秒数(0=never,不推荐)
--sysinfo # 打印一些诊断系统信息
--upgrade # 如果需要升级数据库
Replication options:
--oplogSize arg # 设置oplog的大小(MB)
Master/slave options (old; use replica sets instead):
--master # 主库模式
--slave # 从库模式
--source arg #如果是从库模式,指定主库ip及端口号
--only arg # 指定单一的数据库复制
--slavedelay arg # 设置从库同步主库的延迟时间
--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 # 声明这是一个集群的config服务,默认端口27019,默认目录/data/configdb
--shardsvr # 声明这是一个集群的分片,默认端口27018
########### mongodb 配置文件解释 ###########
verbose = true
vvvv = true
# port = 27017
bind_ip = # 绑定mongoDB服务的IP, 默认绑定所有网卡
maxConns # 最大连接数
objcheck
noobjcheck
logpath
logappend
syslog
pidfilepath
keyFile
nounixsocket
unixSocketPrefix
fork
auth
cpu
dbpath
diaglog
directoryperdb
journal
journalCommitInterval
ipv6
jsonp
noauth
nohttpinterface
nojournal
noprealloc
noscripting
notablescan
nssize
profile
quota
quotaFiles
rest
repair
repairpath
slowms
smallfiles
syncdelay
sysinfo
upgrade
traceExceptions
quiet
setParameter
# For mongod the following options are available using setParameter:
* enableLocalhostAuthBypass
* enableTestCommands
* journalCommitInterval
* logLevel
* logUserIds
* notablescan
* quiet
* replApplyBatchSize
* replIndexPrefetch
* supportCompatibilityFormPrivilegeDocuments
* syncdelay
* textSearchEnabled
* traceExceptions
# For mongos the following options are available using setParameter:
* enableLocalhostAuthBypass
* enableTestCommands
* logLevel
* logUserIds
* notablescan
* quiet
* supportCompatibilityFormPrivilegeDocuments
* syncdelay
* textSearchEnabled
#Replication Options
replSet
oplogSize
fastsync
replIndexPrefetch
# Master/Slave Replication
master
slave
source
only
slaveDelay
autoresync
# Sharded Cluster Options
configsvr
shardsvr
configdb
test
chunkSize
localThreshold
noAutoSplit
# SSL Options
sslOnNormalPorts
sslPEMKeyFile
sslPEMKeyPassword
sslCAFile
sslCRLFile
sslWeakCertificateValidation
sslFIPSMode
停止MongoDB
让MongoDB稳妥地停下来和启动它同样重要。 有很多途径可以有效的做到这一点。
最基本的方法是向MongoDB服务器发送一个SIGINT或SIGTERM信号。如果服务器是作为前台进程运行在终端的,就直接按Ctrl-C。 否则,就用kill这种命令发出信号。 如果mongod的PID是10014, 就可以 kill -2 10014(SIGINT) 或者 kill 10014 (SIGTERM)。
当mongod收到SIGINT或者SIGTERM时,会稳妥退出。 也就是说会等到当前运行的操作或者文件预分配完成(需要一些时间),关闭所有打开的连接,将缓存的数据刷新到磁盘,最后停止。
注意, 千万不要向运行中的MongoDB发送 SIGKILL(kill -9)。这样会导致数据库直接关闭, 上面讲到的步骤都是被忽略的,这样会使数据文件损毁。要是真的发生不幸,一定要在启动备份之前修复数据库。
另一种稳妥的方式就是使用shutdown命令, {"shutdown":1}。这是管理命令,要在admin数据库下使用。 shell提供了辅助函数,来简化这一过程:
>use admin
switched to db admin
>db.shutdownServer();
server should be down...
|
|
|