In practice, we will explain how to build MongoDB and master-slave replication. Because there is only one server, you can only modify the port number to implement the master-slave MongoDB, instead of using multiple servers.
In practice, we will explain how to build MongoDB and master-slave replication. Because there is only one server, you can only modify the port number to implement the master-slave MongoDB, instead of using multiple servers.
One of the main features of MongoDB is replication, which has multiple replication modes. Among them, master-slave replication is a commonly used one.
How master-slave replication works: first, there must be two or more servers, one of which is the master node, responsible for processing client requests, and the other is slave nodes, responsible for ing data on the master node. The master node records all operations performed on it, regularly polls the master node for these operations, and then performs these operations. Because the slave node and the master node perform the same operations, the slave node can maintain data synchronization with the master node.
In practice, we will explain how to build MongoDB and master-slave replication. Because there is only one server, you can only modify the port number to implement MongoDB master-slave, instead of using multiple servers. In fact, the principle is the same ~, However, this is of little practical significance ~
A version of MongoDB (2.6.11) has been installed before. Since mongodb has been updated to 3.0.6, the slave database uses 3.0.6 for test purposes ~
Install
Mongodb
Download mongodb3.0.6 and decompress it. Put the binary file in the/usr/local/mongo3.0.6 directory.
Configuration
Master Database Configuration
# Mongod. conf
# Where to log
Logpath =/var/log/mongodb/mongod-27017.log
Logappend = true
# Fork and run in background
Fork = true
Port = 27017
# Dbpath =/var/lib/mongo
Dbpath =/data/mongodb/mongo-27017
# Location of pidfile
Pidfilepath =/var/run/mongodb/mongod-27017.pid
Bind_ip = 127.0.0.1, 192.168.56.61
# Noauth = true
# Ignore query hints
# Nohints = true
# Disable the HTTP interface (Defaults to localhost: 27017 ).
Nohttpinterface = false
Rest = true
Master = true
Slave Database Configuration
# Mongod. conf
# Where to log
Logpath =/var/log/mongodb/mongod-27018.log
Logappend = true
# Fork and run in background
Fork = true
Port = 27018
# Dbpath =/var/lib/mongo
Dbpath =/data/mongodb/mongo-27018
# Location of pidfile
Pidfilepath =/var/run/mongodb/mongod-27018.pid
# Listen to local interface only. Comment out to listen on all interfaces.
Bind_ip = 127.0.0.1, 192.168.56.61
# Noauth = true
# Ignore query hints
# Nohints = true
# Disable the HTTP interface (Defaults to localhost: 27018 ).
Nohttpinterface = false
Rest = true
Slave = true
Source = 127.0.0.1: 27017
Start
# Master database startup
/Usr/local/release 2.6.11/release d-f/etc/release d/mongod-27017.conf
# Starting from the database
/Usr/local/mongo3.0.6/mongod-f/etc/mongod/mongod-27018.conf
Authentication
The following method can be used to start the auth mode for different versions of mongodb:
1. Set all master-slave mongodb instances to the unauth mode.
2. Add an account to the master so that slave automatically synchronizes the account.
3. Enable auth mode for all Master/Slave mongodb instances
For more information about MongoDB, see the following links:
MongoDB 3.0 official version released and downloaded
CentOS compilation and installation of MongoDB
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: