Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb master-slave replication configuration

Shulou Source: shulou.com Published: 2022-06-01 10:44:37 11月14日 Update

Master-slave replication is the most commonly used replication method in mongodb, which is very flexible. Can be used for backup, fault recovery, read expansion and so on. The most basic way to set up is to establish a master node and one or more slave nodes, each slave node should know the address of the master node. We realize the master and subordinate in two ways.

Here we use one master and one slave to copy mongodb.

Configuration file method:

1. Mainframe

Mongodb-master 10.48.255.244 master

Mongodb-slave 10.48.255.243 slave

two。 Apply the above installation process to the two hosts mongodb, and change the configuration file slightly

On mongodb-master, the profile is added

Master=trueoplogSize=2048 # is similar to mysql's log scrolling, in m

On mongodb-slave, the profile is added:

Slave=truesource=10.48.100.1:27017 # specifies master mongodb serverslavedelay=10 # delay replication in seconds autoresync=true # when it is found that the data from the slave server is not up-to-date, request synchronization data from the master server

Start mongodb on both hosts: mongod-f / etc/mongodb/mongod.conf

Command method:

1) Experimental environment

Master: 192.168.0.14

From: 192.168.0.64

2) time synchronization

Time synchronization between two machines

[root@zabbix_server src] # ntpdate time.windows.com

3) start the service

Master:192.168.0.14

Start command

/ usr/local/mongodb/bin/mongod-master-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/logs-logappend-port=27017-fork

Slave:192.168.0.64

Start command

/ usr/local/mongodb/bin/mongod-- slave-- source 192.168.0.14 source 27017-- dbpath=/usr/local/mongodb/data-- logpath=/usr/local/mongodb/logs-- logappend-- port=27017-- fork

View the master-slave service status command from the slave host:

Db.printReplicationInfo ()

Master-slave: http://blog.chinaunix.net/uid-24250828-id-3770298.html

Http://linuxme.blog.51cto.com/1850814/965184

Http://kupig.blog.51cto.com/8929318/1697635

Tags: Mode master-slave configuration host command file node service synchronization unit data time server two address backup multiple that is commonly used failure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information vpn Xiaomi Huawei