不做第二个别人,永远做第一个自己。
分类: NOSQL
2014-04-10 11:22:01
主服务器:master 10.1.1.3
从服务器:slave 10.1.1.4
因为我是在VPS上安装的mongodb所以使用axel 来加速yum下载速度!
添加安装mongodb yum源:
# vim /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=
gpgcheck=0
enabled=1
在主、从上都执行以下命令:
# yum -y install mongo-10gen mongo-10gen-server
安装完成后!
配置主服务器:10.1.1.3 master
[root@master]# cat /etc/mongod.conf
logpath = /var/log/mongo/mongod.log
logappend = true
fork = true
port = 27017
dbpath = /var/lib/mongo
pidfilepath = /var/run/mongodb/mongod.pid
master = true
source = 10.1.1.4 #从服务器ip
配置从服务器:10.1.1.4 slave1
[root@master]# cat /etc/mongod.conf
logpath = /var/log/mongo/mongod.log
logappend = true
fork = true
port = 27017
dbpath = /var/lib/mongo
pidfilepath = /var/run/mongodb/mongod.pid
slave = true
source = 10.1.1.3 #主服务器ip
启动主数据库
# service mongod start
# chkconfig mongod on
启动从数据库
# service mongod start
# chkconfig mongod on
查看一下主服务器,日志数据库是否同步成功!
[root@master ~]# tail -f /var/log/mongo/mongod.log
Mon Dec 16 15:01:11.572 [initandlisten] creating replication oplog of size: 990MB…
Mon Dec 16 15:01:11.574 [FileAllocator] allocating new datafile /var/lib/mongo/local.1, filling with zeroes…
Mon Dec 16 15:01:11.574 [FileAllocator] creating directory /var/lib/mongo/_tmp
Mon Dec 16 15:01:11.603 [FileAllocator] done allocating datafile /var/lib/mongo/local.1, size: 1024MB, took 0.025 secs
Mon Dec 16 15:01:11.604 [initandlisten] ******
Mon Dec 16 15:01:11.605 [websvr] admin web console waiting for connections on port 28017
Mon Dec 16 15:01:11.605 [initandlisten] waiting for connections on port 27017
Mon Dec 16 15:01:21.326 [initandlisten] connection accepted from 10.1.1.4:49948 #1 (1 connection now open)
Mon Dec 16 15:01:22.343 [slaveTracking] build index local.slaves { _id: 1 }
Mon Dec 16 15:01:22.344 [slaveTracking] build index done. scanned 0 total records. 0.001 secs
查看一下从服务器,日志数据库是否同步成功!
[root@slave1 ~]# tail /var/log/mongo/mongod.log
Mon Dec 16 15:01:20.069 [FileAllocator] done allocating datafile /var/lib/mongo/local.ns, size: 16MB, took 0.008 secs
Mon Dec 16 15:01:20.070 [FileAllocator] allocating new datafile /var/lib/mongo/local.0, filling with zeroes…
Mon Dec 16 15:01:20.072 [FileAllocator] done allocating datafile /var/lib/mongo/local.0, size: 64MB, took 0.001 secs
Mon Dec 16 15:01:20.076 [initandlisten] waiting for connections on port 27017
Mon Dec 16 15:01:20.076 [websvr] admin web console waiting for connections on port 28017
Mon Dec 16 15:01:21.079 [replslave] build index local.sources { _id: 1 }
Mon Dec 16 15:01:21.081 [replslave] build index done. scanned 0 total records. 0.001 secs
Mon Dec 16 15:01:21.081 [replslave] repl: syncing from host:10.1.1.3
Mon Dec 16 15:01:21.097 [replslave] build index local.me { _id: 1 }
Mon Dec 16 15:01:21.099 [replslave] build index done. scanned 0 total records. 0.001 secs
登陆数据库创建一个数据库看是否能同步成功!
[root@master ~]# mongo
MongoDB shell version: 2.4.8
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
Questions? Try the support group
> show dbs;
local 1.078125GB
> use kernal #这个命令就是create DB
switched to db kernal
> db.blog.save({title:”kernal”})
> show dbs;
kernal 0.203125GB
local 1.078125GB
> exit
bye
到从服务器上查看是否有数据同步过来!
[root@slave1 ~]# mongo
MongoDB shell version: 2.4.8
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
Questions? Try the support group
> show dbs;
kernal 0.203125GB
local 0.078125GB
> exit
bye
到此MongoDB Cluster 安装完成!后续补上分片、聚合!