One, MongoDB master server
192.168.1.5 MongoDB Primary Server
192.168.1.108 MongoDB from server
Second, MongoDB master server installation
[Root@localhost ~]# yum install Php-pecl-mongo MongoDB mongodb-devel mongodb-server
Third, master-slave server configuration
1, Primary server 192.168.1.5 configuration
[Root@localhost ~]# cat/etc/mongodb.conf |awk ' {if ($!~/^$/&& $!~/^#/) {print $}} '
logpath=/var/log/mo Ngodb/mongodb.log
fork = True
logappend=true
dbpath=/var/lib/mongodb
pidfilepath=/var/run/ Mongodb/mongodb.pid
master = true
Source = 192.168.1.108
Create a database directory
[Root@localhost lib]# mkdir-p/var/lib/mongodb [root@localhost lib]# chown mongodb:mongodb-r/var/lib/mongodb/
2, 192.168.1.108 configuration from server
[Root@localhost ~]# cat/etc/mongodb.conf |awk ' {if ($!~/^$/&& $!~/^#/) {print $}} '
logpath=/var/log/mo Ngodb/mongodb.log
logappend=true
fork = true
port = 27017
dbpath=/var/lib/mongodb
pidfilepath= /var/run/mongodb/mongodb.pid
slave = true
Source = 192.168.1.5
Create a database directory
[Root@localhost lib]# mkdir-p/var/lib/mongodb [root@localhost lib]# chown mongodb:mongodb-r/var/lib/mongodb/
There is a only in the original configuration, which can be used for selective synchronization of data, Only=test, to synchronize only the test database
3, start the master-slave server MongoDB
[Root@localhost www]#/etc/init.d/mongod start
Four, test synchronization
Primary server 192.168.1.5
<?php
$m = new Mongo ();
$db = new MongoDB ($m, ' mydbname ');
$log = $db->createcollection ("Logger", true, 10*1024);
for ($i = 0; $i < 5 $i + +) {
$log->insert (Array ("Level" => WARN, "msg" => "Zhang Ying log Message # $i", "TS" => New Mongodate ());
}
$msgs = $log->find ();
foreach ($msgs as $msg) {
echo $msg [' msg ']. " <br> ";
}
$dbs = $m->listdbs ();
Print_r ($dbs);
? >
192.168.1.108 from server
<?php
$m = new Mongo ();
$db = new MongoDB ($m, ' mydbname ');
$log = $db->createcollection ("Logger", true, 10*1024);
$msgs = $log->find ();
foreach ($msgs as $msg) {
echo $msg [' msg ']. " <br> ";
}
$dbs = $m->listdbs ();
Print_r ($dbs);
? >
If the display is the same, it means that the synchronization is successful, and we can also see if the synchronization is successful in other ways.
View the path to the database below the file is not the same size is not the same.
[Root@localhost www]# ll/var/lib/mongodb/
If all the same, it means that the synchronization is successful.
We can also view the log log to see if the synchronization was successful.