Based on CentOS 7, MongoDB 3.4.2 Pseudo-shard cluster use

Source: Internet
Author: User
Tags mkdir mongodb split centos acer
first, the pre-preparation environment:

The construction according to the 3+3+9 pattern of pseudo-distributed structure (3 MONGOs to provide services, 3 Configserver to save configuration information, 3 Mongod storage data, 3 Mongod as a copy of data, 3 Mongod as the quorum node); (1) To create a cluster folder for the configuration service Configserver information about the service:

Cases:

Mkdir/home/mongo/cluster/config1/data;
Mkdir/home/mongo/cluster/config1/log;
(2) to save the service information for the Shard storage Service Mongod the cluster folder:

Cases:

Mkdir/home/mongo/cluster/shard1/data;
Mkdir/home/mongo/cluster/shard1/log;
second, the cluster 1, respectively start each configserver service, respectively accounted for 21000,21001,21002 port:
Mongod--configsvr--dbpath/home/mongo/cluster/config1/data--port 21000--logpath/home/mongo/cluster/config1/log/ Config.log--relset CS--fork

Note: Version 3.2 does not require –relset cs parameter, 3.4 version must have, otherwise you cannot follow up the Mongose service.   If no configuration information is written to Configserver, the MONGOs service rejects the connection. 2, respectively login Configserver write related configuration:

[root@localhost ~] #mongo 192.168.1.122:21000
mongo>use admin
mongo>cfg = {
  _id: ' CS ',
  Configsvr:true,
  members:[
    {_id:0,host: ' 10.45.32.118:21000 '}
  ]
};
Mongo>rs.initiate (CFG);
============= I am split line ===================//
[root@localhost ~] #mongo 192.168.1.122:21001
mongo>use Admin
mongo>cfg = {
  _id: ' CS ',
  configsvr:true,
  members:[
    {_id:0,host: ' 10.45.32.118:21001 '}
  ]
 };
 Mongo>rs.initiate (CFG);

 ============= I am split line ===================//
[root@localhost ~] #mongo 192.168.1.122:21002
mongo>use Admin
mongo>cfg = {
_id: ' CS ',
configsvr:true,
members:[
{_id:0,host: ' 10.45.32.118:21 002 '}
 ]
};
Mongo>rs.initiate (CFG);
3. Start the Shard storage service separately, accounting for 22001-22009 ports:
Mongod--shardsvr--replset shard1--port 22001--dbpath/home/mongo/cluster/shard1/data--logpath/home/mongo/cluster/ Shard1/log/shard1.log--fork--nojournal--oplogsize 10
4, set the Shard information:

Log in Shards separately

(1) Login MONGO 192.168.1.122:22001 [root@localhost ~]# MONGO 192.168.1.122:22001 >use admin; >config = {_id: "Shard1", members:[{_id:0,host: "192.168.1.122:22001"}, {_id:1,host: "192.168.1.122:
22002 "}, {_id:2,host:" 192.168.1.122:22003 ", Arbiteronly:true}]};
>rs.initiate (config);
>exit//(2) Re-login MONGO 192.168.1.122:22004 [root@localhost ~]# MONGO 192.168.1.122:22004 >use admin; >config = {_id: "Shard1", members:[{_id:0,host: "192.168.1.122:22004"}, {_id:1,host: "192.168.1.122:
22005 "}, {_id:2,host:" 192.168.1.122:22006 ", Arbiteronly:true}]};

>rs.initiate (config);
(3) landing MONGO 192.168.1.122:22007; [root@localhost ~]# MONGO 192.168.1.122:22007 >use admin; >config = {_id: "Shard1", members:[{_id:0,host: "192.168.1.122:22007"}, {_id:1,host: "192.168.1.122:
22008 "}, {_id:2,host:" 192.168.1.122:22009 ", Arbiteronly:true}]}; >rs.initiate (config); 
4, respectively start MONGOs, respectively accounted for: 23000,23001,23002 Port:
[Root@localhost ~]#  mongos--configdb cs/192.168.1.122:21000,192.168.1.122:21001,192.168.1.122:21002--port 23000
[root@localhost ~]#  MONGOs--configdb cs/ 192.168.1.122:21000,192.168.1.122:21001,192.168.1.122:21002--port 23001
[root@localhost ~]#  MONGOs-- ConfigDB cs/192.168.1.122:21000,192.168.1.122:21001,192.168.1.122:21002--port 23002
5, connected to MONGOs, serial routing server and Shard server:
(1) landing MONGO 192.168.1.122:23000;
[root@localhost ~] #mongo 192.168.1.122:23000
>use admin;
>>db.runcommand ({addshard: "shard1/192.168.1.122:22001,92.168.1.122:22002,92.168.1.122:22003"});
>db.runcommand ({addshard: "shard2/192.168.1.122:22004,92.168.1.122:22005,92.168.1.122:22006"});
>db.runcommand ({addshard: "shard2/192.168.1.122:22007,92.168.1.122:22008,92.168.1.122:22009"});
#查看分片服务器的配置
>db.runcommand ({listshards:1});
(2) Specify the Shard and test;
>use Acer;
>db.createcollection (' test ');
>db.runcommand ({enablesharding: "Acer"});
#指定为哪个库的哪个集合创建分片, TAB key
>sh.shardcollection ("Acer.test", {"UID": 1}), #此命令指的是为acer库的test集合进行分片, TAB key is Uid,
# Insert test data:
>use acer
>for (var i = 1; I <= 100000; i++) Db.test.save ({"Uid": I, "Name": "Zhanjindong", "Age" : "Date": New Date ()});
#查看分片结果
>db.test.stats ();

Reprinted from: http://www.cnblogs.com/jarven/p/6370353.html

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.