# 关闭服务器端脚本,这将极大的限制功能
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true
# 关闭扫描表,任何查询将会是扫描失败
# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true
# 关闭数据文件预分配
# Disable data file preallocation.
#noprealloc = true
# 为新数据库指定.ns文件的大小,单位:MB
# Specify .ns file>
# nssize =
# Accout token for Mongo monitoring server.
#mms-token =
# mongo监控服务器的名称
# Server name for Mongo monitoring server.
#mms-name =
# mongo监控服务器的ping 间隔
# Ping interval for Mongo monitoring server.
#mms-interval =
# Replication Options 复制选项
# in replicated mongo databases, specify here whether this is a slave or master 在复制中,指定当前是从属关系
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com
二、MongoDB主从配置
一、mongodb主从服务器
1.172.16.1.170 mongodb主服务器
2.172.16.1.171 mongodb从服务器
二、主从服务器配置
1.172.16.1.170配置
[root@nagios mongo]# cat /etc/mongod.conf
logpath=/var/log/mongo/mongod.log
logappend=true
fork = true
dbpath=/var/lib/mongo
pidfilepath = /var/run/mongodb/mongod.pid
master = true
source = 172.16.1.171
port=27017
2.172.16.1.171配置
[root@171 mongo]# cat /etc/mongod.conf
port=27017
logpath=/var/log/mongo/mongod.log
logappend=true
fork = true
dbpath=/var/lib/mongo
pidfilepath = /var/run/mongodb/mongod.pid
slave = true
source = 172.16.1.170
3.启动主从服务器mongodb
service mongod start
主服务器mongodb日志
[root@nagios mongo]# tail -f /var/log/mongo/mongod.log
Tue Feb 26 13:44:36 [initandlisten] MongoDB starting : pid=14105 port=27017 dbpath=/var/lib/mongo master=1 64-bit host=nagios
Tue Feb 26 13:44:36 [initandlisten] db version v2.2.3, pdfile version 4.5
Tue Feb 26 13:44:36 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Tue Feb 26 13:44:36 [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
Tue Feb 26 13:44:36 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", master: "true", pidfilepath: "/var/run/mongodb/mongod.pid", port: 27017, source: "172.16.1.171" }
Tue Feb 26 13:44:36 [initandlisten] journal dir=/var/lib/mongo/journal
Tue Feb 26 13:44:36 [initandlisten] recover : no journal files present, no recovery needed
Tue Feb 26 13:44:37 [websvr] admin web console waiting for connections on port 28017
Tue Feb 26 13:44:37 [initandlisten] waiting for connections on port 27017
Tue Feb 26 13:44:48 [initandlisten] connection accepted from 172.16.1.171:45526 #1 (1 connection now open
从服务器mongodb日志
[root@171 mongo]# tail -f /var/log/mongo/mongod.log
Tue Feb 26 13:47:36 [initandlisten] MongoDB starting : pid=7283 port=27017 dbpath=/var/lib/mongo slave=1 64-bit host=171
Tue Feb 26 13:47:36 [initandlisten] db version v2.2.3, pdfile version 4.5
Tue Feb 26 13:47:36 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Tue Feb 26 13:47:36 [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
Tue Feb 26 13:47:36 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid", port: 27017, slave: "true", source: "172.16.1.170" }
Tue Feb 26 13:47:36 [initandlisten] journal dir=/var/lib/mongo/journal
Tue Feb 26 13:47:36 [initandlisten] recover : no journal files present, no recovery needed
Tue Feb 26 13:47:36 [initandlisten] waiting for connections on port 27017
Tue Feb 26 13:47:36 [websvr] admin web console waiting for connections on port 28017
Tue Feb 26 13:47:37 [replslave] repl: syncing from host:172.16.1.170
测试主从同步数据
在主服务器173.16.1.170新建数据库
[root@nagios mongo]# mongo
MongoDB shell version: 2.0.4
connecting to: test
> use zhangfang
switched to db zhangfang
> db.blog.save({title:"new zhangfang"})
从服务器172.16.1.171查看
[root@171 mongo]# mongo
MongoDB shell version: 2.2.3
connecting to: test
> show dbs;
elaindb0.203125GB
local0.203125GB
zhangfang0.203125GB
查看日志
[root@171 mongo]# tail -f /var/log/mongo/mongod.log
Tue Feb 26 13:55:39 [FileAllocator] allocating new datafile /var/lib/mongo/zhangfang.1, filling with zeroes...
Tue Feb 26 13:55:39 [conn1] command admin.$cmd command: { listDatabases: 1.0 } ntoreturn:1 keyUpdates:0 locks(micros) R:6 r:33 reslen:234 1424ms
Tue Feb 26 13:55:41 [replslave] build index zhangfang.blog { _id: 1 }
Tue Feb 26 13:55:42 [replslave] fastBuildIndex dupsToDrop:0
Tue Feb 26 13:55:42 [replslave] build index done. scanned 1 total records. 1.165 secs
Tue Feb 26 13:55:42 [replslave] resync: done with initial clone for db: zhangfang
Tue Feb 26 13:55:45 [FileAllocator] done allocating datafile /var/lib/mongo/zhangfang.1,>
Tue Feb 26 13:56:23 [conn1] end connection 127.0.0.1:54288 (0 connections now open)
Tue Feb 26 13:56:24 [initandlisten] connection accepted from 127.0.0.1:54290 #2 (1 connection now open)
Tue Feb 26 13:56:39 [conn2] end connection 127.0.0.1:54290 (0 connections now open)
Tue Feb 26 13:56:58 [replslave] repl: checkpoint applied 9 operations
Tue Feb 26 13:56:58 [replslave] repl: syncedTo: Feb 26 13:53:59 512c4df7:1
说明主从数据同步成功