In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Three ways to build http://blog.csdn.net/luonanqin/article/details/8497860 Mongodb Cluster
NoSQL = Not Only SQL mongodb storage is document storage, not Key-Value storage.
Construction of three cluster modes of Mongodb: Replica Set / Sharding / Master-Slaver
Replica Set replica set clustering principle: (the simplest way to cluster)
Primary node, standby node, arbitration node. The active and standby nodes store data, while the arbitration node does not store data.
The client connects the primary node and the standby node at the same time, but does not connect the arbitration node.
By default, the master node provides all addition, deletion, query and modification services, while the standby node does not provide any services. However, the standby node can be set up to provide query services, so that the pressure on the primary node can be reduced. When the client makes a data query, the request is automatically transferred to the standby node. This setting is called Read Preference Modes, and the Java client provides a simple way to configure it without having to manipulate the database directly.
Arbitration node is a special node, it does not store data, the main role is to determine which standby node is promoted to the primary node after the primary node dies, so the client does not need to connect to this node. Although there is only one standby node here, a quorum node is still needed to upgrade the standby node level.
Test: one is to insert data into the primary node, which can be checked from the standby node to the previously inserted data (querying the standby node may encounter a problem, you can check it on the Internet yourself). The second is to stop the primary node, the standby node can become the primary node to provide services. The third is to restore the primary node, the standby node can also restore its standby role, rather than continue to play the primary role. Both two and three can see the changes in the cluster in real time through the rs.status () command.
Sharding sharding cluster:
Similar to Replica Set, a quorum node is required, but Sharding also needs to configure nodes and routing nodes. In terms of the three ways to build a cluster, this is the most complex.
Master-Slaver active / standby mode
This method is no longer recommended by the authorities, and the construction method is relatively simple.
People who have used it should know that mongodb eats memory. The solution can only be controlled by ulimit, but if it is not properly controlled, mongodb will die.
Installation of mongodb
Execute the script install_mongodb_20160510.sh to install the mongodb service. Please see redme for details.
Installation of mongodb cluster
Common command
Startup of mongodb
/ opt/server/mongodb/bin/mongod-f / opt/server/mongodb/mongodb.conf
/ opt/server/mongodb/bin/mongod-f / opt/server/mongodb/mongodb.conf-- fork # standalone environment / is related to the configuration file, please refer to the configuration file for details
Stop of mongodb
Kill-15 pid
Pkill mongod
Mongodb login method
/ opt/server/mongodb/bin/mongo 192.168.1.200:27017
View statu
Rs.status ()
Delete a node:
Rs.remove ("mongodb13.kk.net:27019") # can delete nodes
Add a node:
Rs.addArb ("mongodb13.kk.net:27019") # can add nodes, but the nodes so added are arbitration
How do you add a node to a mongodb replica set to make it a backup node?
Operate on the primary node
Use admin
Cfg= {_ id: "wlb", members: [{_ id:0,host:'192.168.11.215:27017',priority:2}, {_ id:1,host:'192.168.11.187:27017',priority:1}, {_ id:2,host:'192.168.11.25:27017',arbiterOnly:true}]}
Rs.reconfig (cfg); # make the configuration effective
Rs.status ()
View all databases
Show dbs
MongoDB creates a database
Use znx
Db
Show dbs # will find that the created database is not in the list, and you need to insert data in order to display it
If the standby node wants to view the database, it needs to execute the following command, otherwise it reports a 13435 error.
Rs.slaveOk (true)
Insert data
Db.znx.insert ({"name": "dengyong"})
Show dbs # will display the znx database, and the standby node will also show
View all data tables
Show collections
View all table records
Db.znx.find ()
Delete the pushlog table
> db.Pushlog.drop () # specific operation. Enter db.Pushlog.d and press the table key to see what commands there are.
True
If the standby node views the data, execute the following command first, otherwise an error will be reported.
Rs.slaveOk (true)
MongoDB deletes the database
Use znx
Db.dropDatabase () # execute delete command
Show dbs # znx database has been deleted
Reference link: http://blog.csdn.net/chen88358323/article/details/50206651
Mongodb create user
Use admin
Db.createUser ({user: "wjs", pwd: "wjs", roles: [{role: "userAdminAnyDatabase", db: "admin"}]}) # create a user
Show users # you need to use the database first to view the user
Built-in roles:
1. Database user roles: read, readWrite
two。 Database management roles: dbAdmin, dbOwner, userAdmin
3. Cluster management roles: clusterAdmin, clusterManager, clusterMonitor, hostManager
4. Backup and restore roles: backup, restore
5. All database roles: readAnyDatabase, readWriteAnyDatabase, userAdminAnyDatabase, dbAdminAnyDatabase
6. Superuser role: root
/ / there are also several roles that provide access to the system superuser indirectly or directly (dbOwner, userAdmin, userAdminAnyDatabase)
7. Internal role: _ _ system
Specific roles:
Read: allows the user to read the specified database
ReadWrite: allows users to read and write to a specified database
DbAdmin: allows users to perform administrative functions in a specified database, such as index creation, deletion, viewing statistics, or accessing system.profile
UserAdmin: allows users to write to the system.users collection. You can create, delete and manage users in a specified database.
ClusterAdmin: available only in the admin database, giving users administrative rights to all shard and replication set related functions.
ReadAnyDatabase: available only in admin databases, giving users read access to all databases
ReadWriteAnyDatabase: available only in admin databases, giving users read and write permissions to all databases
UserAdminAnyDatabase: available only in admin databases, giving users userAdmin permissions for all databases
DbAdminAnyDatabase: available only in admin databases, giving users dbAdmin permissions for all databases.
Root: available only in the admin database. Super account, super privilege
Db.system.users.find () # View users
Show users
Create a database znx
Use znx
Create a normal user wxc
Db.createUser ({user: "wxc", pwd: "wxc", roles: [{role: "readWrite", db: "znx"}]})
Release the memory occupied by MongoDB
Restart the service to free memory, or use MongoDB's built-in closeAllDatabases command to do so:
Mongo > use admin
Mongo > db.runCommand ({closeAllDatabases:1})
Monitor the memory usage of MongoDB
Db.serverStatus () mem
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.