Working on Installation, Configuration, Administration of MongoDB servers.
We have 3 Node Replicaset sharded cluster.
I used to sit with our developers in writing CRUD operations, Creating users, assigning privilages/roles,
Checking slow running queries, Creating Indexes on Dcoument Id.
Exporting and Importing Collections from prod to Dev enviornment.
Basic Architecture:-
mongodb is a document oriented database, store data in the form of BSNO format (Binary coded JSON) i.e Key value pair.
In Database we have Collection and in collections we can have mulitple documnets.
The main daemon or process in mongodb is mongoD, which is actually a database server, it handle connection requests and handle data.
The other process is mongo.. it provide access to the mongoD server.
MongoD Listene on default port 27017.. and default dbpath /data/db/.
Users are created in DB level in mongodb and previlages are also on DB level.
We can pass all the details like dbpath logpath port while starting mongoD but best is to use configuration file.
Bydefault mongoD start in foreground, to start it in background we need to use --fork .
Namespace is nothing but concatination of databasename and collection name.
Default storage engine is WiredTiger.
Replica sets are groups of different MongoDs that contain the same data.
The purpose of a replica set cluster is to ensure high availability and automatic failover.
In its most basic form, you can think of replica sets as having one node that manages all reads and writes-- a primary node.
And some secondary nodes that constantly copy the information from the primary node.
The latest version of our protocol is based in the industry accepted Raft Protocol, which ensures that in case of failure, the system is able to automatically select a secondary node as the new primary and keep up with the service without requiring any manual intervention or downtime.
Replica set cluster nodes can have different roles, different hardware configuration, and different operation system.
Process of distributing data across multiple servers for storage,
Shards reduces the number of operations.
Each shard servers as independent DB, together shards make a single logical DB.
Shards themselves are replica sets-- highly availability in units.
Where we have other components as well, like MongoSs, which are our shard cluster routing components.
MongoDB shards data per collection basis.
when you connect to perticular shard you will be able to view only fraction of data contained in cluster.
Data is not organized in any perticular order.
use admin
db.startServer()
db.shutdownServer()
db.currentOp()
db.killOp(pid)
mongotop
mongostat
db.getProfilingStatus()
db.getProfilingLevel (0-2)
db.setProfilingLevel(1) ---default conf 100msec
db.setProfilingLevel(1,5)...for 5misec
db.system.profile.find()
db.serverStatus()
db.serverCmdLineOpts() --to check db path
mongod --fork --logPath ---to start mongod in background
http:loclhost:28017 --we can open in browser if mongod started with --httpinterface and --rest
db = db.getSiblingDB('admin') to create admin user
db.auth("AdminUser", "password")
mongos> testdb=db.getSisterDB("testdb")
testdb
*) How to monitor mongodb performance?
db.getLogComponents() -verbosity (default 0, increase 1-5 for more debugging, -1 means inherited)
db.adminCommand({"getLog" : "global"})
db.setLogLevel( 0, "Index")
================================================ Replica Set Configuration =================================
1. Create three folders
D:\mongodb
one
two
three
2. mongod --dbpath "D:\mongodb\one" --port 45896 --replSet replicationtest (starting server)
3. mongo --port 45896
4. Open New Termianl
5. mongod --dbpath "D:\mongodb\two" --port 45897 --replSet replicationtest (starting server)
6. mongo --port 45897
7. Open New Termianl
8. mongod --dbpath "D:\mongodb\three" --port 45898 --replSet replicationtest (starting server)
9. mongo --port 45898
10. Create configuration file --(In prim DB session mongo --port 45896)
config = {
_id : "testreplica" , members :[
{
"_id" : 0 ,
"host" :"localhost:45896"
}
]
}
11. rs.initiate(config)
12. rs.status()
13. rs.add("localhost:45897")
14. rs.add("localhost:45898")
done
No comments:
Post a Comment