MongoDB Shard Detail Description (Itsom)

Source: Internet
Author: User
Tags database sharding

MongoDB is scalable and can be run in a distributed platform cluster environment, that is, sharding.

Different parts of the data can be assigned to different servers using indexes. For example, the customer in the index record is placed on a group of servers, and the vendor is placed on another set of servers. However, to be completely randomly distributed, you use an indexed hash value. You can also assign data to multiple servers with a range of values.

Shard Cluster
MongoDB infrastructure. You can communicate with routers, which can poll the configuration (config) server to determine the Shard (Shard) server that writes and reads data, which is where the data is stored. The configuration server can also act as a replica set, where data is replicated to obtain additional copies.

There should be at least 3 configuration servers in a production environment. Here, we show how the development environment establishes a shard configuration where at least 1 routers, one configuration server, and one shard server are used.

Installing software and setting up virtual machines
We need three virtual machines. As shown below, in/etc/hosts, we have set up three virtual machines. You can set any desired IP address, but for the purposes of this tutorial, we use the same name as below to set the host name.

We use:

mongomaster-this is the router.
Mongoshard-This is the database server we use for sharding, which is running in a clustered environment.
mongoconfig-This is the configuration server and database copy.
192.168.20.150 Mongomaster
192.168.20.149 Mongoshard
192.168.20.170 Mongoconfig
Installing the Software
We use MONGO 3.4.10 on Ubuntu 16.04. As I said, because MONGO changed the software, the server is no longer just configuring the server. Instead, the configuration server can be used as a replica. The other replicas can only be replicas.

The MONGO software is installed on all three servers.
sudo apt-key adv--keyserver hkp://keyserver.ubuntu.com:80--recv 0c49f3730359a14518585931bc711f9ba15703c6
echo "Deb [arch=amd64,arm64] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Multiverse" | sudo tee/etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install-y mongodb-org
Create a configuration server replication set
RS is the name we give to this replica set. The –-CONFIGSVR switch indicates that this replica set can be used as a replica server and as a configuration server.
SSH Mongoconfig
sudo mongod--configsvr--dbpath/data/configdb--replset RS
Now, run MONGO through any server. We connect to port 27019 because in standard output (stdout), when you start Mongod, this is where the Mongod display is listening:

This node is mongoconfig:27019 in the configuration.

The

is initialized.
Mongo--host mongoconfig--port 27019
rs.initiate ()
then observe the status, confirming that it is the configuration server:
Rs.status ()
{
"set": "RS",
Date: Isodate ("2017-10-28t06:38:52.355z"),
"MyState": 1,
"term": Numberlong (1),
"Configsvr": true,
...
Start Mongod
on the Shard server ssh mongoshard
sudo mongod--shardsvr--replset
Now use the MONGO Client connection and initialize it:
Mongo-- Host Monogshard--port 2718
rs.initiate ()
{
"Info2": "No Configuration specified. Using a default configuration for the set ",
" Me ":" mongoshard:27018 ",
" OK ": 1
}
start on the router mongos
SSH Mongom Aster
MONGOs--configdb rs/mongoconfig:27019
Note This message in standard output, which gives us the port number for the next step:

Wait for a 27017 port connection
Adding shards to the cluster
MONGO--host Mongomaster--port 27017
Sh.addshard ("rs/mongoshard:27018")
{"shardadded": "RS", "OK": 1}
Enable Database sharding
You can use any database name. Remember the database name so that it does not exist when it is created. We use tobacco because this is the name we used in our last tutorial, the database name when using Nodejs and MongoDB.
Sh.enablesharding ("Tobacco")
{"OK": 1}
Check Status
See if the database exists and shards.
Sh.status ()
---sharding Status---
Sharding version: {
"_id": 1,
"Mincompatibleversion": 5,
"CurrentVersion": 6,
"Clusterid": ObjectId ("59f425f12fdbabb0db68b690")
}
Shards:
{"_id": "RS", "Host": "rs/mongoshard:27018", "state": 1}
Active Mongoses:
"3.4.10": 1
Autosplit:
Currently Enabled:yes
Balancer
Currently Enabled:yes
Currently Running:no
NaN
Failed balancer rounds in last 5 attempts:0
Migration Results for the Last Hours:
No Recent Migrations
Databases
{"_id": "Tobacco", "primary": "RS", "Partitioned": true}

MongoDB Shard Detail Description (Itsom)

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.