Install 3.2 for centos/6
& amazon linux
[monbodb]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
Disable THP
#!/bin/bash
### BEGIN INIT INFO
# Provides: disable-transparent-hugepages
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before: mongod mongodb-mms-automation-agent
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description: Disable Linux transparent huge pages, to improve
# database performance.
### END INIT INFO
case $1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
return 0
fi
echo 'never' > ${thp_path}/enabled
echo 'never' > ${thp_path}/defrag
re='^[0-1]+$'
if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
then
# RHEL 7
echo 0 > ${thp_path}/khugepaged/defrag
else
# RHEL 6
echo 'no' > ${thp_path}/khugepaged/defrag
fi
unset re
unset thp_path
;;
esac
Non systemd!
ulimit
- cent6/amazon
mongod soft nproc 64000
Deploy cluster ver 3.2
Build config server
replication:
replSetName: replconfig
sharding:
clusterRole: configsvr
Start mongod server.
And build Config Server Replica Set (maybe from ver 3.2)
$ mongod
rs.initiate(
{
_id : "replconfig",
members: [
{ _id : 0, host : "mongoc1:27017" },
{ _id : 1, host : "mongoc2:27017" },
{ _id : 2, host : "mongoc3:27017" }
]
}
)
Build ReplicaSet
Shard-0 (sh00)
replication:
replSetName: sh00
sharding:
clusterRole: shardsvr
$ mongod
rs.initiate(
{
_id : "sh00",
members: [
{ _id : 0, host : "mongod1:27017" },
{ _id : 1, host : "mongod2:27017" },
{ _id : 2, host : "mongod3:27017" }
]
}
)
Shard-1 (sh01)
port 27117
replication:
replSetName: sh01
sharding:
clusterRole: shardsvr
$ mongod
rs.initiate(
{
_id : "sh01",
members: [
{ _id : 0, host : "mongod1:27117" },
{ _id : 1, host : "mongod2:27117" },
{ _id : 2, host : "mongod3:27117" }
]
}
)
Add Shards
sh.addShard( "sh00/mongod1:27017")
sh.addShard( "sh01/mongod1:27117")
[replName]/primaryNode:port
We must set primaryNode!
And more...
sh.enableSharding("")
If the collection already contains data, you must create an index on the shard key using the db.collection.createIndex() method before using shardCollection().
If the collection is empty, MongoDB creates the index as part of sh.shardCollection().
The following operation shards the target collection:
sh.shardCollection("<database>.<collection>", { <key> : <direction> } )
start on mac
Install via brew
mongod --config /usr/local/etc/mongod.conf
mongoimport
Support 2 type json
http://zaiste.net/2012/08/importing_json_into_mongodb/
{ name: "Widget 1", desc: "This is Widget 1" }
{ name: "Widget 2", desc: "This is Widget 2" }
or
[
{ name: "Widget 1", desc: "This is Widget 1" },
{ name: "Widget 2", desc: "This is Widget 2" }
]
with --jsonArray
option.