Original MongoDB Integrated Instance One

Source: Internet
Author: User
Tags unix domain socket

CentOS-6.5 single-Machine implementation MongoDB Shards

Environment:1) CentOS 6.5 system 2) IP: Native 3) mongodb:mongodb-linux-x86_64-2.6.1

implementation: two replica sets shard (Shard-a and Shard-b), each replica set shard configured three instances (master, slave, and quorum), three config server instances, and one mongos route. Finally, the data written by MONGOs is evenly distributed across two shard.

1. Install CentOS 6.5 and configure the IP address, then configure the/etc/hosts file to add a native IP address and domain name (custom, such as IP Master) mappings.

2. Download and install MongoDB:

1) Create Active Directory: #mkdir/data

1) Download mongodb-linux-x86_64-2.6.1.tgz to/data directory

3) Unzip and enter the bin directory of the extracted directory:

#tar –zxvf/data/mongodb-linux-x86_64-2.6.1.tgz

#cd/data/mongodb-linux-x86_64-2.6.1/bin

3. Prepare The directory to deploy the sharding environment:

#mkdir/data/rs-a-1

#mkdir/data/rs-a-2

#mkdir/data/rs-a-3

#mkdir/data/rs-b-1

#mkdir/data/rs-b-2

#mkdir/data/rs-b-3

#mkdir/data/config-1

#mkdir/data/config-2

#mkdir/data/config-3

4. start the replica set

1) Start the first replica set

#mongod--shardsvr--replset shard-a--dbpath/data/rs-a-1--logpath/data/rs-a-1.log--port 30000--nojournal--fork & ;

#mongod--shardsvr--replset shard-a--dbpath/data/rs-a-2--logpath/data/rs-a-2.log--port 30001--nojournal--fork & ;

#mongod--shardsvr--replset shard-a--dbpath/data/rs-a-3--logpath/data/rs-a-3.log--port 30002--nojournal--fork &am P

2) Start a second replica set

#mongod--shardsvr--replset shard-b--dbpath/data/rs-b-1--logpath/data/rs-b-1.log--port 30100--nojournal--fork & ;

#mongod--shardsvr--replset shard-b--dbpath/data/rs-b-2--logpath/data/rs-b-2.log--port 30101--nojournal--fork & ;

#mongod--shardsvr--replset shard-b--dbpath/data/rs-b-3--logpath/data/rs-b-3.log--port 30102--nojournal--fork & ;

5. Configure the replica set

1) on the first replica set:

#mongo--port 30000

>rs.initiate ()

>rs.add ("master:30001")

>rs.add ("master:30002", {arbiteronly:true})

2) on the second replica set:

#mongo –port 30100

> Rs.initiate ()

>rs.add ("master:30101")

>rs.add ("master:30102", {arbiteronly:true})

3) Finally, run the >rs.status () command on each replica set to verify that the two replica sets are working correctly. If all goes well, you are ready to start the configuration server.

6. Start the configuration server

1) Start three configuration server instances

#mongod--configsvr--dbpath/data/config-1--logpath/data/config-1.log--port 27019--nojournal--fork &

#mongod--configsvr--dbpath/data/config-2--logpath/data/config-2.log--port 27020--nojournal--fork &

#mongod--configsvr--dbpath/data/config-3--logpath/data/config-3.log--port 27021--nojournal--fork &

2) Use the shell to connect or view the log files, make sure each configuration server is up and running, and verify that each process is listening on the port. If the configuration server is running, you can start MONGOs.

7. start mongos Routing

1) MONGOs--configdb master:27019,master:27020,master:27021--logpath/data/mongos.log--fork--port 40000

2) Use Shell login to verify that it is working correctly. (MONGOs can specify the size of the chunksize at startup, this value is the Shard when the specified data size arrives)

8. Configure the cluster

1) Specify two replica sets that were created before, with the address of the non-quorum node in each replica set:

#mongos –port 40000

>sh.addshard ("shard-a/master:30000,master:30001")

>sh.addshard ("shard-b/master:30100,master:30101")

If the command executes successfully, the command's response contains the name of the Shard that was just added.

2) Use the Getsiblingdb () method to switch the database to see the effect:

>db.getsiblingdb ("config"). Shards.find ()

9. Open a shard on a database, with gizwits as an example:

1) Command: >sh.enablesharding ("Gizwits")

2) Check the data in config to see the changes:

>db.getsiblingdb ("config"). Databases.find ()

3) to shard the test set, you need to define a sharding key, which uses the composite shard key {username:1,_id:1}.

>sh.shardcollection ("Gizwits.test", {username:1,_id:1})

>sh.getsiblingdb ("config"). Collections.findone ()//Verify the configuration of the Shard collection

4) Run the Getindexes () method on the Shard instance to verify.

#mongo –port 30000

>use gizwits

>db.test.getindexes ()

Complete the Shard of the collection, and the Shard cluster is ready.

Ten: in the MONGOs inserting data into a route test a shard cluster

#mongo –port 40000

>for (i=1;i<=50000;i++) {Db.test.insert ({_id:i,username: "user" +i,age:10+i})}

Log on to the Shard replica set to view the effect.

Note 1: If there is an error that cannot be viewed while viewing data from the machine, execute the command on the Slave: Db.getmongo (). setslave0k (). You can check it again. Mongodb3.0 above version of Use Db.getmongo (). setslave0k () or Rs.slaveok () after exiting the login again, this error will still occur, and the file needs to be edited: #vi ~/.mongorc.js add Rs.slaveok ( );

NOTE 2: After configuring the sharding note that maxsize is worth specifying, if it is found that data can be fragmented later may not be the data storage beyond the size of the maxsize, after adjustment can be. The MaxSize value (in m) represents a disk size that can be used by a shard, and the excess data is not fragmented but is stored on primary sharding. Use the statement to specify or change its size:

The first type:

>db.runcommand ({addshard: "Shardip:port", maxsize:20480})

The second type:

>use Config

>db.shards.update ({_id: "[Shardname]"},{$set: {maxsize:20480}})

Attached: [Original]MONGODB integrated case two links:http://www.cnblogs.com/wsjhk/p/4469317.html

Mongodb Start Command Mongod parameter Description

The main parameters of Mongod are:

Basic Configuration

--------------------------------------------------------------------------------

--quiet

# quiet Output

--port Arg

# Specify the service port number, default ports 27017

--BIND_IP Arg

# Bind service IP, if bind 127.0.0.1, can only native access, do not specify default local all IP

--logpath Arg

# Specify the MongoDB log file, note that the specified file is not a directory

--logappend

# Write a log using append

--pidfilepath Arg

# The full path of the PID file, if not set, there are no PID files

--keyfile Arg

# The full path of the cluster's private key, valid only for the replica Set schema

--unixsocketprefix Arg

# UNIX domain Socket Alternative directory, (default =/tmp)

--fork

# run MongoDB as a daemon and create a server process

--auth

# Enable Validation

--cpu

# Periodic display of CPU utilization and iowait

--dbpath Arg

# Specify Database path

--diaglog Arg

# Diaglog Options 0=off 1=w 2=r 3=both 7=w+some reads

--directoryperdb

# Set each database to be saved in a separate directory

--journal

# Enable logging option, MONGODB data operation will be written to the file in the Journal folder

--journaloptions Arg

# Enable Log Diagnostics options

--ipv6

# Enable IPV6 option

--jsonp

# Allow JSONP form to be accessed via HTTP (with security implications)

--maxconns Arg

# Maximum number of simultaneous connections default 2000

--noauth

# Do not enable validation

--nohttpinterface

# Close the HTTP interface and turn off 27018 port access by default

--noprealloc

# Disable data file pre-allocation (often impacting performance)

--noscripting

# Disable scripting engine

--notablescan

# No table scan allowed

--nounixsocket

# Disable UNIX socket snooping

--nssize Arg (=16)

# Set the message database. ns File Size (MB)

--objcheck

# in the receipt of customer data, check the validity of

--profile Arg

# file Parameters 0=off 1=slow, 2=all

--quota

# limit the number of files per database, set default to 8

--quotafiles Arg

# Number of files Allower per db, requires--quota

--rest

# Open a simple rest API

--repair

# fix all databases run repair on all DBS

--repairpath Arg

# Fix the directory of the files generated by the library, default to directory name DBPath

--slowms Arg (=100)

# Value of slow for profile and console log

--smallfiles

# Use a smaller default file

--syncdelay Arg (=60)

# Number of seconds data written to disk (0=never, not recommended)

--sysinfo

# Print some diagnostic system Information

--upgrade

# If you need to upgrade your database

* Replicaton Parameters

--------------------------------------------------------------------------------

--fastsync

# from a dbpath enabled from the Library Replication service, the DBPath database is a snapshot of the main library and can be used to quickly enable synchronization

--autoresync

# If synchronizing data from the library to the main library is much worse, automatic resynchronization

--oplogsize Arg

# Set the size of the Oplog (MB)

* Master/slave parameters

--------------------------------------------------------------------------------

--master

# Main Library Mode

--slave

# from Library mode

--source Arg

# from the Library port number

--only Arg

# Specify a single database copy

--slavedelay Arg

# Set the delay time for synchronizing the main library from the library

* Replica set (replica set) option:

--------------------------------------------------------------------------------

--replset Arg

# set Replica set name

* sharding (Shard) option

--------------------------------------------------------------------------------

--configsvr

# Declare this is a clustered config service, default port 27019, default directory/data/configdb

--shardsvr

# Declare this is a clustered shard, default port 27018

--nomoveparanoia

# Turn off paranoid for movechunk data save

Original MongoDB Integrated Instance One

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.