MongoDB installation and master-slave replication

Source: Internet
Author: User

First, CentOS installation MongoDB

Opt directory, download MongoDB, unzip

#wget HTTPS://FASTDL.MONGODB.ORG/LINUX/MONGODB-LINUX-X86_64-3.0.6.TG


#tar-ZXVF mongodb-linux-x86_64-3.0.6.gz

Renaming mongodb-linux-x86_64-3.0.6 to MongoDB

#mv mongodb-linux-x86_64-3.0.6.gz MongoDB


Go to MongoDB New database folder, log folder, and Configuration folder

#cd mongodb#mkdir db#mkdir Log#mkdir conf

Under the MongoDB Directory command start:

Bin/mongod  --dbpath db--port 27000--logpath Log/mongod.log--fork True

(Personal habits Write these parameters to the configuration file) go to the Configuration folder, create a new profile mongod.conf, edit the content

Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程

New startup file startmongod.sh in MongoDB directory, writing content

Bin/mongod-f conf/mongod.conf

The MongoDB basic directory structure after configuration:

Start SH startmongod.sh

Second, MongoDB master-slave replication

Test environment: 192.168.199.199 master, 192.168.199.200 from, 192.168.199.201 from

In the installation configuration mongodb,mongod.conf the boot configuration contents are as follows

199

Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程master = #主数据库

200

Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程slave = #从数据库标识source = 192.168.1 99.199:27,000

201

Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程slave = #从数据库标识source = 192.168.1 99.199:27,000

! (Three machine firewalls must open 27000 ports: iptables-i input-p TCP--dport 27000-j ACCEPT)

199 Main Library startup and log information


200 Startup and log information

199 Inserting data

200 Test Query synchronization data

201 The main library was not synchronized before, and now 201 synchronizes data as a new server database 199 Master Library

201 Log Display Synchronization

199 Main Library synchronization log information

Read and Write permissions are not opened from the database at this time

Which is the realization of read and write separation

MongoDB installation and master-slave replication

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.