mongodb3.4.15 Cluster Construction

Source: Internet
Author: User

Machine: Ubuntu 2 set

Ip:

    • 192.168.0.131 host1
    • 192.168.0.132 Host2

Installing MongoDB

sudo apt-key adv--keyserver HKP://keyserver.ubuntu.com:80--recv 0C49F3730359A14518585931BC711F9BA15703C6Echo "Deb [ARCH=AMD64] Http://repo.mongodb.org/apt/ubuntu trusty/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



File directory

Port

    • 27017 MONGOs Routing
    • 30000 Configserver Configuration Service
    • 27018 Shards

      DBPath

    • Null MONGOs

    • /app/mongo/data/config/data Configserver

    • /app/mongo/data/shard/data Shard

Place the startup Mongod configuration file in the/app/mongo/config directory

1.configServer

In 192.168.0.131

  
 mkdir -p/app/mongo/data/config/data  mkdir -p/app/mongo/data/config/log  /app/mongo/config/configserver.conf

   
DBPath=/app/MONGO/data/config/data port=  30000  bind_ip=0.0. 0.0 Configsvr = true Replset =conf

Using supervisor to start and stop

[Program:configdb]Command=Mongod-F/App/Mongo/Config/Configserver.confautostart=Trueautorestart=Truestderr_logfile=/App/Mongo/Data/Config/Log/Err.LogStdout_logfile=/App/Mongo/Data/Config/Log/Out.Log

Same operation in 192.168.0.132

Login to any Server Client initialize Config

 mongo --port 30000
= {_id: "conf", Members:[  {_id:0, Host: "192.168.0.131:30000"},  {_id:1, Host: " 192.168.0.132:30000 "}  ]};rs.initiate (config);

2. Routing MONGOs Configuration

In 192.168.0.132

- /app/MONGO/data/mongos/log

/app/MONGO/config/mongos.conf

Port = 27017
Bind_ip=0.0. 0.0 configdb=conf/192.168. 0.131:30000,192.168. 0.132:30000

Using supervisor to start and stop

[Program:mongos]Command=MONGOs-F/App/Mongo/Config/Mongos.confautostart=Trueautorestart=Truestdout_logfile= /App/Mongo/Data/MONGOs/Log/Out.LogStderr_logfile= /App/Mongo/Data/MONGOs/Log/Err.Logloglevel=Info

3. sharding

In 192.168.0.131

Mkdir-p/app/mongo/data/shard/datamkdir-p/app/mongo/data/shard/logsvim/app/mongo/config/mongod.confdbpath=/app/ mongo/data/shard/dataport=27018 bind_ip=0.0.0.0  Shardsvr=true  

Using supervisor to start and stop

# mongod.conf [Program:mongod]command=mongod-f/app/mongo/config/mongod. Confautorestart=trueredirect_stderr=true=/app/mongo/data/shard/ Logs/mongod. Log loglevel=info

  Supervisorctl Reload

In 192.168.0.132

mkdir -p/app/mongo/data/shard/datamkdir -p/app/mongo/data/shard/logs

Adding Shard nodes on 4.mongos
 Use admindb. RunCommand ({addshard: "192.168.0.131:27018"});d b. RunCommand ({addshard: " 192.168.0.132:27018 "});

View node Information

Db.runcommand ({listshards:1});

Add a shard primary key to the database (take Db.col as an example)

Sh.enablesharding ("DB") db. RunCommand ({"Shardcollection": "Db.col", "key": {"_id": 1}})

 
 

mongodb3.4.15 Cluster Construction

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.