MongoDB master-slave replication and backup set deployment

Source: Internet
Author: User

I. MongoDB configuration parameter Description:

[Email protected] tmp]# cat/etc/mongod.conf


#以守护进程的方式运行

Fork=true


#设置db的路径

dbpath=/usr/local/mongodb/data/db


#设置日志路径

Logpath=/usr/local/mongodb/data/log/mongod.log

#logappend: Write the log mode: set to True for append. The default is overwrite. If this setting is not specified, MongoDB will overwrite the existing log file at startup.

Logappend=true


#设置端口号

port=27017


#在服务的端口号加上1000的端口上启动一个web服务器

Rest=true


#打开权限控制体系

#auth =true

Two. Deploy MongoDB master-slave replication:

1. Create a configuration file for master and slave:

[Email protected] tmp]# cat/etc/mongod_master.conf

Logpath=/usr/local/mongodb/data/log/mongod_master.log

Logappend=true

Fork=true

Dbpath=/usr/local/mongodb/data/master

port=10000

Rest=true

Master=true

#auth =true

#slaveok =true

[Email protected] tmp]#

[Email protected] tmp]# cat/etc/mongod_slave.conf

Logpath=/usr/local/mongodb/data/log/mongod_slave.log

Logappend=true

Fork=true

Dbpath=/usr/local/mongodb/data/slave

port=10001

Rest=true

Slave=true

#auth =true

source=127.0.0.1:10000

2. Start the master-slave process;

[[email protected] tmp] #mkdir-pv/usr/local/mongodb/data/master

[[email protected] tmp] #mkdir-pv/usr/local/mongodb/data/slave

[Email protected] tmp]mongod-f/etc/mongod_master.conf

[Email protected] tmp]mongod-f/etc/mongod_slave.conf

3. Check the master and slave status:

[Email protected] tmp]# MONGO localhost:10000

> Db.ismaster ();

{

"IsMaster": true,

"Maxbsonobjectsize": 16777216,

"Maxmessagesizebytes": 48000000,

"Maxwritebatchsize": 1000,

"LocalTime": Isodate ("2016-02-28t11:46:54.199z"),

"Maxwireversion": 4,

"Minwireversion": 0,

"OK": 1

}

>

> Db.printreplicationinfo ();

Configured Oplog SIZE:990MB

Log length start to End:23821secs (6.62hrs)

Oplog First Event Time:sun 13:05:17 gmt+0800 (CST)

Oplog last event Time:sun 19:42:18 gmt+0800 (CST)

Now:sun Feb 19:42:20 gmt+0800 (CST)

> Db.printslavereplicationinfo ();

Local.sources is empty; Is this db a--slave?

> Db.getreplicationinfo ();

{

"Logsizemb": 990,

"USEDMB": 0.14,

"Timediff": 23871,

"Timediffhours": 6.63,

"TFirst": "Sun Feb 13:05:17 gmt+0800 (CST)",

"Tlast": "Sun Feb 19:43:08 gmt+0800 (CST)",

"Now": "Sun Feb 19:43:18 gmt+0800 (CST)"

}

[Email protected] tmp]# MONGO localhost:10001

> Db.printreplicationinfo ();

This is a slave, printing slave replication info.

source:127.0.0.1:10000

Syncedto:sun Feb 19:44:18 gmt+0800 (CST)

4 secs (0 hrs) behind the freshest member (no primary available at the moment)


Three. Deployment of the backup set:

1. Create a configuration file for each node:

[Email protected] tmp]# cat/etc/mongod_node1.conf

Logpath=/usr/local/mongodb/data/log/mongod_node1.log

Logappend=true

Fork=true

Dbpath=/usr/local/mongodb/data/node1

port=20001

Rest=true

#auth =true

#slaveok =true

Replset=myrepl

[Email protected] tmp]# cat/etc/mongod_node2.conf

Logpath=/usr/local/mongodb/data/log/mongod_node2.log

Logappend=true

Fork=true

Dbpath=/usr/local/mongodb/data/node2

port=20002

Rest=true

#auth =true

#slaveok =true

Replset=myrepl

[Email protected] tmp]# cat/etc/mongod_node3.conf

Logpath=/usr/local/mongodb/data/log/mongod_node3.log

Logappend=true

Fork=true

Dbpath=/usr/local/mongodb/data/node3

port=20003

Rest=true

#auth =true

#slaveok =true

Replset=myrepl

[Email protected] tmp]#

2. Configure and activate the node service;

[[email protected] tmp] #mkdir-pv/usr/local/mongodb/data/node1

[[email protected] tmp] #mkdir-pv/usr/local/mongodb/data/node2

[[email protected] tmp] #mkdir-pv/usr/local/mongodb/data/node3

[[email protected] tmp] #mongod-F/etc/mongod_node1.conf

[[email protected] tmp] #mongod-F/etc/mongod_node2.conf

[[email protected] tmp] #mongod-F/etc/mongod_node2.conf

Login Mongod:

#设置备份集变量:

> config = {_id: "Myrepl", Members:[{_id:0,host: "127.0.0.1:20001"},{_id:1,host: "127.0.0.1:20002"},{_id:2,host: " 127.0.0.1:20003 "}]};

#初始化副本集配置

> rs.initiate (config);


3. Check the status of node nodes;

#查看副本集的状态

> Rs.status ();

#删除节点:

Rs.remove ("127.0.0.1:20001");

Rs.status ();

#添加节点:

Rs.add ("127.0.0.1:20001");

Rs.status ();

Four. MONGO master-Slave and backup cluster deployment is completed;


This article is from the "Webseven" blog, make sure to keep this source http://webseven.blog.51cto.com/4388012/1745849

MongoDB master-slave replication and backup set deployment

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.