Detailed MongoDB master configuration _mongodb

Source: Internet
Author: User
Tags foreach install php log log mkdir mongodb

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.