MongoDB installation configuration and replica set operations

Source: Internet
Author: User

First, Mongdb3.0 installation


Download the latest stable version of MongoDB software on official website

Https://www.mongodb.org/downloads


Decompression software

[Email protected] service]# tar zxvf mongodb-linux-x86_64-rhel62-3.0.3.tgz mongodb-linux-x86_64-rhel62-3.0.3/ readmemongodb-linux-x86_64-rhel62-3.0.3/third-party-noticesmongodb-linux-x86_64-rhel62-3.0.3/ gnu-agpl-3.0mongodb-linux-x86_64-rhel62-3.0.3/bin/mongodumpmongodb-linux-x86_64-rhel62-3.0.3/bin/ mongorestoremongodb-linux-x86_64-rhel62-3.0.3/bin/mongoexportmongodb-linux-x86_64-rhel62-3.0.3/bin/ mongoimportmongodb-linux-x86_64-rhel62-3.0.3/bin/mongostatmongodb-linux-x86_64-rhel62-3.0.3/bin/ mongotopmongodb-linux-x86_64-rhel62-3.0.3/bin/bsondumpmongodb-linux-x86_64-rhel62-3.0.3/bin/ mongofilesmongodb-linux-x86_64-rhel62-3.0.3/bin/mongooplogmongodb-linux-x86_64-rhel62-3.0.3/bin/ mongoperfmongodb-linux-x86_64-rhel62-3.0.3/bin/mongodmongodb-linux-x86_64-rhel62-3.0.3/bin/ Mongosmongodb-linux-x86_64-rhel62-3.0.3/bin/mongo

Create MONGDB data storage path and log storage path

[[email protected] service]# mkdir-p/date/{mongodbdata,mongodb_logs}

Establish Mongod account, authorization Data directory

[Email protected] date]# useradd mongod[[email protected] date]# chown-r mongod.mongod/date/mongodbdata/

To create a mongod.conf configuration file, you need only the following options

[[email protected] Date] #cat/etc/mongod.conf dbpath =/data/mongodata #mongodb数据存放路径logpath =/ Data/mongodb_logs/mongodb.log #mongodb日志存放路径httpinterface = True #mongodb管理端口默认 +10 00:280fork = True #后台启动

Second, start MongoDB initialization data

(1) The first to specify the path and log directly on the command line

/usr/local/service/mongodb-linux-x86_64-rhel62-3.0.3/bin/mongod--dbpath=/date/mongodbdate/--logpath=/date/ Mongodb_logs/mongodb.log--forkabout to fork child process, waiting until server is a ready for connections.forked process:  5238child process started successfully, the parent exiting Port has been up: [[email protected] mongodb_logs]# lsof-i: 27017COMMAND PID USER FD TYPE DEVICE size/off NODE namemongod 5238 root 6u IPv4 41939 0t0 TCP *:27017 (LISTEN) initialization due to synchronization of data, built Local data files. will start relatively slowly.


(2) Second way to start: Start by loading configuration file (recommended)

[Email protected] mongodbdate]#/usr/local/service/mongodb-linux-x86_64-rhel62-3.0.3/bin/mongod-f/etc/ Mongod.conf about to fork child process, waiting until server was ready for connections.forked Process:5382child process s Tarted successfully, parent exiting

Accessing the terminal to view the database

[[email protected] mongodb_logs]# /usr/local/service/mongodb-linux-x86_64-rhel62-3.0.3/bin/ mongomongodb shell version: 3.0.3connecting to: testwelcome to the  Mongodb shell. for interactive help, type  "Help". for more comprehensive documentation, seehttp://docs.mongodb.org/questions? try  the support grouphttp://groups.google.com/group/mongodb-userserver has startup  warnings: 2015-06-30t17:37:53.882+0800 i control  [initandlisten] **  warning: you are running this process as the root user,  which is not recommended.2015-06-30t17:37:53.882+0800 i control  [ initandlisten] 2015-06-30t17:37:53.905+0800 i control  [initandlisten]  2015-06-30t17:37:53.905+0800 i control  [initandlisten] **  warning: /sys/kernel/mm/transparent_hugepage/enabled is  ' always '. 2015-06-30t17:37:53.905+0800  i control  [initandlisten] **        we  suggest setting it to  ' Never ' 2015-06-30t17:37:53.905+0800 i control   [initandlisten] 2015-06-30t17:37:53.905+0800 i control  [initandlisten] **  WARNING: /sys/kernel/mm/transparent_hugepage/defrag is  ' always '. 2015-06-30t17:37:53.906+ 0800 i control  [initandlisten] **        we  suggest setting it to  ' Never ' 2015-06-30t17:37:53.906+0800 i control   [initandlisten] > show dbs;local  0.078gb

The following will appear when starting an error:

[Email protected] mongodbdate]#/usr/local/service/mongodb-linux-x86_64-rhel62-3.0.3/bin/mongod-f/etc/ Mongod.conf about to fork child process, waiting until server was ready for connections.forked process:5298

Check Cause:

First: Since there is no normal exit MongoDB service, need to delete the Mongod.lock file, again start to return to normal.

Second: There is a problem with the configuration file, you need to check the configuration file for special characters, which causes unresolved


Third, MongoDB replica set configuration

Configure a MongoDB replica set be sure to do the following:

1, each node can access the MONGODB socket port normally, iptables to release

2, SELinux must be shut down, so as not to prohibit port replication

3, each server node to do a good job of parsing/etc/hosts

4, because the replica set is connected through the heartbeat heart jumper, it is important to synchronize the time of each node

Small bet: I have not noticed these before, was pit for a long time. Ha ha!!!


MongoDB replication process and concepts

(1) The master node saves data modification operations to Oplog,oplog: fixed-size files stored in the local database

(2) Initial sync (inital sync)

Node does not have any data

Node lost replica replication history

: Cloning all databases

: Apply all changes to the dataset: Copy Oplog and apply to local

: Build index for all collection

(3) Chase after rollback (Post-rollback catch-up)

(4) Segmentation block Migration (shareding chunk migrations)

Local: All elements and Oplog of the replica set are stored, and the Oplog is a collection named oplog.rs;

The size of the oplog.rs depends on the OS and file system, but can be customized to its size oplogsize


Environmental testing


This article is from the "struggling veterans" blog, make sure to keep this source http://jiaxu201.blog.51cto.com/4569604/1669504

MongoDB installation configuration and replica set operations

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.