Mongodbn cluster replica set
Oct 10, 2016 am 11:39 AMI 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
})

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Learn about introductory code examples for Python programming

PHP variables in action: 10 real-life examples of use

From beginner to proficient: Code implementation of commonly used data structures in Go language

How to use PHP to write inventory management function code in the inventory management system

Java implements simple bubble sort code

Go language programming examples: code examples in web development

Huawei Cloud Edge Computing Interconnection Guide: Java code examples to quickly implement interfaces

Guidance and Examples: Learn to implement the selection sort algorithm in Java
