Home > php教程 > php手册 > body text

Mongodbn cluster replica set

WBOY
Release: 2016-10-10 11:39:30
Original
1148 people have browsed it

I am a newbie and I just ordered it based on my own needs. This is also my first time working on a mognodb cluster. Dear gods, please don’t complain. The writing is a bit messy, let’s take a look at it first
1. Create and configure the mongodb.conf file:
vi /etc/mongodb.conf (enter the following content)

fork=true #Run as a daemon and create a server process
logpath=/alidata/webroot/logs/work.log #Log output file path
logappend=true #Log output method
dbpath=/data/db #Database path
replSet=firstdb #Set the name of the rich collection

Then go into the bin directory of mongodb and execute the following command:
Note: Kill the mongod process first and then use the following command
./mongod -f /etc/mongodb.conf (start) Note: etc/rc.lcoal must also be changed to this mongod -f /etc/mongodb.conf

When entering the bin directory and executing ./mongo and then show dbs, a problem will occur: liasdatabase

When this problem occurs, it is because of initialization:
First try the command to shut down mongodb:
./mongod --dbpath=/alidata/approot/mongodb/mongodb-linux-x86_64-3.2.7/data/db/ --shutdown

Add these configurations to the configuration file:

journal=true
oplogSize = 4096
Then execute in the bin directory of mongodb: ./mongod -f /etc/mongodb.conf
Check whether the startup is successful: If the startup is successful, enter the bin directory of mongodb
Execute command: ./mongo
Then: rs.initiate(
{
_id: "rs0",
version: 1,
members: [
{ _id: 0, host : "ip:27017", priority: 30},
{ _id: 1, host: "ip:27017", priority: 20 },
{ _id: 2, host: "ip:27017", priority: 10 }
]
}
)

Then use the command: rs.ststus() to check
{
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94
}
If it is displayed like this, it means that the other two have written data:
Stop the two slaves: clear the data or change the folder
mv db db.bak
mkdir db
chmod -R 777 db
Then start
Execute the above command again: rs.initiate(
{
_id: "rs0",
version: 1,
members: [
{ _id: 0, host : "ip:27017", priority: 30},
{ _id: 1, host: "ip:27017", priority: 20 },
{ _id: 2, host: "ip:27017", priority: 10 }
]
}
)
Then use the command: rs.status()
Then go to the slave node and check the logs
Then use the command: top to check the load
Then check the synchronization process on the slave node: you must enter the logs directory to execute the following command to view the process
Use the command: tail -f work.log
Then go to the main node and use the command: use test
Then use the command: find image_weibo.files.find()
If there is data, execute the command from the mongo node:
rs.slaveOk()
Both slave nodes must execute this command:
Then use the command use test
Then use the command db.image_weibo.files.find() to check whether there is data. If there is data, the synchronization is successful. OK!
Then insert data on the master node to test:
db.image_weibo.insert({title: 'MongoDB Tutorial',
description: 'MongoDB is a Nosql database',
by: 'xx11',
url: 'http://www.baidu.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
})

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!