Install mongoDB on CentOS7

Source: Internet
Author: User
Tags install mongodb

Install mongoDB on CentOS7

MongoDB is one of the most well-developed NOSQL databases. It is eye-catching in the storage of big data and space data!
Generally, mongoDB is deployed on a linux System in enterprise-level applications. For Tom, deploying a complete set of mongoDB on linux is definitely not easy, I also succeeded in a recent attempt to crawl and roll. I wrote this blog so that I can check it later.

The first thing I need is to deploy the required environment. I am using a VMware VM. As I am working in a relatively wealthy area, I have provided two workstation computers worth yuan (absolutely powerful ). I have installed four centos virtual machines on these two computers and configured the environment.


This is the list of vms I use:

1-4, 5-8 are the four virtual machines located on the two workstations. Each virtual machine has a mongod installed on it, and the ip address is allocated by itself. Among them, config is installed on 1, 2, and 5, respectively, config is the specific principle that mongos uses to manage mongod. I will not talk about it here. I noticed that 5 was released later. This article will not introduce it. Another function is to release tiles and wmts in nginx. The last 9 and 10 are the application servers installed on the third computer. Here, I only use the two workstations and I have installed two virtual machines on them. Due to computer configuration, the VM memory here is 2 GB. Why do we need two computers? The two computers can be one master and the other one is a replica set, which is equivalent to two parts. Currently, 10 is useless. A mongos is installed on it. If there are many computers but the configuration is not high, you need to prepare multiple computers.

The following is how to install mongod:

Step 1: Download mongodb
Here you need a mongodb Installation File mongodb-linux-x86_64-2.6.7 http://pan.baidu.com/s/1mg642huhere download of course can also go to the official network download,
Copy the installation package to 10 VMS respectively.

Part 2: unzip the installation package


Step 3: create a data directory and a log directory
Note: to create several mongod instances, you need to create several data db and log. log instances.
Move the extracted files to the "/usr/local/mongodb" folder.

Create the data DIRECTORY and logs directory in the mongodb folder
Command: mkdir-p./data/db;
Mkdir logs;

Step 4: start the service
Start mongodb later

Command:
Numactl-interleave = all/usr/local/mongodb/bin/mongod-dbpath =/usr/local/mongodb/data/db-logpath =/usr/local/mongodb/logs/ mongodb. log-fork-port 27017-replSet rep1

Step 5: Set startup
Command:
Echo "numactl-interleave = all/usr/local/mongodb/bin/mongod-dbpath =/usr/local/mongodb/data/db-logpath =/usr/local/mongodb/ logs/mongodb. log-fork-port 27017-replSet rep1 ">/etc/rc. local

Step 6: View logs and services

Command: tail-f/usr/local/mongodb/logs/mongodb. log;

Command: ps aux | grep mongodb;

The service is started!

View mongodb

Replica set + sharding

Step 1: configure the replica set
Configure the first replica set and use the first mongod in the first group to start mongo and initialize the replica set rep1.
Initialize the first rep1 (mongod: 192.9.104.108: 27017)
Command:
Config = {_ id: 'rep1', members :[
{_ Id: 0, host: '2017. 9.104.108: 100 '},
{_ Id: 1, host: '2017. 9.104.109: 100 '},
{_ Id: 2, host: '2017. 9.104.110: 100 '},
{_ Id: 3, host: '2017. 9.104.110: 100'}]
}
Rs. initiate (config)

Configure the second replica set and use the first mongod in the second group to start mongo and initialize the replica set rep2.
Initialize the second rep2 (mongod: 192.9.104.111: 27017)
Config = {_ id: 'rep2', members :[
{_ Id: 0, host: '2017. 9.104.111: 100 '},
{_ Id: 1, host: '2017. 9.104.112: 66661 '},
{_ Id: 2, host: '2017. 9.104.113: 100 '},
{_ Id: 3, host: '2017. 9.104.113: 100'}]
}
Rs. initiate (config)

Step 2: Configure multiple config servers

Step 3: Configure mongos
Numactl-interleave = all/usr/local/mongodb/bin/mongos-configdb 192.9.104.108: 28017,192.9 .104.109: 28017,192.9 .104.111: 28017-port 30000-chunkSize 5-logpath/usr/local/mongodb/logs/mongos. log-fork

Note: (only one config is connected)
Numactl-interleave = all/usr/local/mongodb/bin/mongos-configdb 192.9.104.108: 28017-port 34500-chunkSize 5-logpath/usr/local/mongodb/logs/mongos. log-fork

Start the mongos Service

Connect to mongos

Step 4: configure the shard cluster
Connect to the mongos process and switch to the admin database for configuration.
Configure shard cluster

Step 5: Activate database and set sharding
Create a database and set, and activate it as needed.
Example: test. test
Activate database and set shards

So far, mongodb (mongodb, mongos, config server) based on centos7 has been deployed. Although it is difficult, it is still a bit of a sense of accomplishment!

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.