MongoDB Configuration and PHP connectivity test

Source: Internet
Author: User
Tags findone mkdir
MongoDB Configuration and PHP connectivity test(2010-05-10 10:41:36) reprint
Tags: mongodb php topics Category: Technical Articles
The auto-sharding function of MongoDB refers to the mongodb of a horizontally expanding database cluster system through MONGOs, and the database is stored on each node of sharding. A MongoDB cluster includes some shards (including some mongod processes), MONGOs routing processes, one or more config servers
Shards each shard includes one or more services and a mongod process that stores data (Mongod is the core process of MONGODB data), each of the typical Shard opens multiple services to increase the availability of the service. These services/mongod processes form a replica set in Shard
Chunks Chunk is a range of data from a particular set (Collection,minkey,maxkey) that depicts a chunk between Minkey and Maxkey ranges. For example, the maxsize size of chunks is 100M, and if a file reaches or exceeds this range, it will be split into 2 new chunks. When a shard data is overloaded, chunks is migrated to other shards. Similarly, chunks can also migrate to other shards
The Config Servers config server stores the metadata information for the cluster, including each server, and the basic information for each shard and the Chunk Information config server primarily stores the chunk information. The full chunk information is replicated for each config server.
Configuration: (Simulate 2 shard service and one Config service) shard1:192.168.11.37:27017 shard2:192.168.11.39:27017 config:192.168.11.40:27019 mongos:192.168.11.41:27017 MONGOs 27017 Ports Used by default at startup
Start the service 192.168.11.37 mkdir/data/db cd/mnt/disk1/mongodb-linux-x86_64-1.4.2/bin./mongod--shardsvr--dbpath/data/db >/tmp/mongodb.log &
192.168.11.39 mkdir/data/db cd/mnt/disk1/mongodb-linux-x86_64-1.4.2/bin./mongod--shardsvr--dbpath/data/db >/ Tmp/mongodb.log &
192.168.11.40 cd/mnt/disk1/mongodb-linux-x86_64-1.4.2/bin./mongod--configsvr--dbpath/data/db >/tmp/ Mongoconfigdb.log &
192.168.11.41 cd/mnt/disk1/mongodb-linux-x86_64-1.4.2/bin./mongos--configdb 192.168.11.40:27019 >/tmp/ Mongoconfigdb.log &
Check Service status Ps-ef|grep MONGO Netstat-an-t open 28017 is the corresponding HTTP interface
Manage MongoDB 192.168.11.41 cd/mnt/disk1/mongodb-linux-x86_64-1.4.2/bin./mongo default connection to MONGOs > show DBS Join Shard node > U SE admin > Db.runcommand ({addshard: "192.168.11.37:27018", allowlocal:true}) > Db.runcommand ({addshard: "1   92.168.11.39:27018 ", allowlocal:true}) > Db.runcommand ({listshards:1}); View Shard node list new auto Slice library user001: > config = connect ("192.168.11.40:27019") > config = config.getsisterdb ("config") > User001=db.getsisterdb ("user001"); > Db.runcommand ({enablesharding: "user001"}) > Db.printshardingstatus (); Create a new table in user001, insert data > Use user001 > Db.createcollection ("user_001") > Show Collections > Db.user_001.insert ({ Uid:1,username: "Falcon.c", Sex: "Male", age:25}); > Db.user_001.find (); See which Shard 192.168.11.37/39 the user001 library is assigned to cd/data/db Ls-l You can see that user001 is assigned to the 192.168.11.39 Shard, but through MONGOs routing, we don't feel the Shard on which data is stored.
Sharding admin Command 192.168.11.41 > db. $cmd. FindOne ({isdbgrid:1}); > db. $cmd. FindOne ({ismaster:1}); > Printshardingstatus (Db.getsisterdb ("config")) > Use admin > Db.runcommand ({netstat:1})
PHP Test VI mondb.php <?php $m = new Mongo ("192.168.11.41");                     Connect to Mongs $db = $m->user001;           Select a database (user001) $collection = $db->user_001; Select a collection (user_001) $result = $collection->find (); foreach ($result as $val) {print_r ($val);}
echo "<br><br>";
foreach ($result as $val) {echo User id:. $val [UID]. "        <br> "; echo "User name:". $val ["username"]. "        <br> "; echo "User gender:". $val ["Sex"]. "        <br> "; echo "User age:". $val [??]. <br> "; }//Disconnect $m->close ();?>
http://192.168.11.37/mondb.php Display Results: Array ([_id] => mongoid Object () [UID] => 1 [username] => falcon.c [sex] => male [age] => 25)
User Id:1 user name: falcon.c user sex: Male user age: 25
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.