The solution to the error reported when the MongoDB cluster starts with security authentication adduser

Mongodb cluster starts with security authentication, adduser reports an error After use admin. When adding a user db.addUser(“admin”,”123456″) Since other nodes do not have admin users yet, and the -keyFile parameter is still used, authorization authentication is required. Cause the first time can not, create a user. The phenomenon is as follows switched to db admin { “user” : “admin”, “readOnly” : false, “pwd” : “dfb2b4f665d248c6887cfba7b1f0c9fc”, “_id” : ObjectId(“50b41bb41e7bf4084c43a793”) } Tue Nov 27 09:47:32uncaught exception: couldn’t add user: SyncClusterConnection::insert prepare failed: 10.200.7.106:10021:{ errmsg: “need to login”, ok: 0.0 } 10.200.7.221:10021:{ errmsg: “need to login”, ok: 0.0 } 10.200.7.226:10021:{ errmsg: “need to login”, ok: 0.0 } Solution. Do not add the -keyFile parameter when starting for the first time. After startup, first create the admin user. Then stop all nodes. Add -keyFile parameter. Restart the cluster. You can. ./bin/mongod -shardsvr -replSet shard1 -port 10020 -dbpath data/shard1a-keyFile /data/support/mongodb-2.2.1/mongokey -oplogSize 100 -logpath logs/shard1a.log -logappend -fork -rest –nojournal

How to recover from MongoDB cluster node failure

A properly configured Mongodb sharded cluster has no single point of failure. This article describes several different potential node failure scenarios that exist in a sharded cluster, and how Mongodb handles these node failures. 1. Mongos node downtime A Mongos process should run on each application server, and this server should exclusively own the Mongos process and communicate with the shard cluster through it. Mongos processes are not persistent, instead, they collect all necessary configuration information from the Config Server at startup. This shows that the failure of any application server node has no impact on the sharded cluster as a whole, and all other application servers will continue to work normally. In this case, recovery is a fairly simple matter, we just need to start a new application server and a new Mongos process. 2. One of the Mongod nodes in the shard is down Each shard consists of n servers, which are configured as a replica set (replica set). If any node in the replica set goes down, reads and writes are still allowed on the shard. More importantly, the data on the down server will not be lost, because there is an option in the replication mechanism,…

Deploying a highly available MongoDB server cluster (2)

Deploying a highly available MongoDB server cluster (2)

In the previous article “Deploying a Highly Available MongoDB Server Cluster (1)” (http://www.server110.com/mongodb/201403/8341.html), several problems were mentioned that have not been resolved. Can the connection be switched automatically when the master node is down? Manual switching is currently required. How to solve the excessive reading and writing pressure on the master node? The data on each slave node is a full copy of the database. Will the slave node be under too much pressure? Can automatic expansion be achieved when the data pressure is too high for the machine to support? After reading this article, you can solve these problems. The emergence of NoSQL is to solve large data volume, high scalability, high performance, flexible data model, and high availability. However, the architecture of master-slave mode alone is far from reaching the above points, so MongoDB designed the function of replica set and fragmentation. This article mainly introduces replica sets: MongoDB officially does not recommend using the master-slave mode. The alternative is to use the replica set mode, click to view , as shown in the figure: So what is a replica set? Playing World of Warcraft always talks about playing dungeons. In fact, these two concepts have almost the…

Deploying a highly available MongoDB server cluster (1)

Deploying a highly available MongoDB server cluster (1)

In the era of big data, traditional relational databases must solve the problems of high concurrent reading and writing, efficient storage of massive data, high scalability and high availability in order to provide higher services. But it is because of these problems that Nosql was born. NOSQL has these advantages: Large data volume, you can store a large amount of data through cheap servers, and easily get rid of the traditional mysql single-table storage level limit. High scalability, Nosql removes the relational features of relational databases, it is easy to expand horizontally, and gets rid of the criticism of vertical expansion in the past. High performance, Nosql obtains data through a simple key-value method, which is very fast. In addition, NoSQL’s Cache is record-level, which is a fine-grained Cache, so NoSQL has much higher performance at this level. Flexible data model, NoSQL does not need to create fields for the data to be stored in advance, and can store custom data formats at any time. In a relational database, adding and deleting fields is a very troublesome thing. If it is a table with a very large amount of data, adding fields is simply a nightmare. High availability, NoSQL can…

Configuration and use of MongoDB database cluster

1. Data backup The most popular insurance method is to use the master-slave mode, and then obtain a write lock on the slave machine first, so that others can no longer write, and then back up all data files before unlocking, so that it will not affect the use of the master in the system Generally, slave machines that need to be backed up can be synchronized with delay MongoDB In addition to the most common Master/Slave mode in the replication mechanism, the more powerful one is the Replica that supports automatic failover Sets mode 2. Configure master and slave modes If we want to enable the Master/Slave mode and enable the Auth function You need to add a user and password named repl to the local database on both the Master and Slave: use local db.addUser(‘repl’,’password’) The oplogSize option needs to be added to the master to specify the log size The –oplogSize command line parameter (used together with –master) configures the disk space (in M units) used to store the update information available to the slave node. If this parameter is not specified, the default size is 5 of the currently available disk space % (minimum value is…

MongoDB database query guide

1. Multiple query conditions The way of adding multiple key/value pairs to the query document can realize the combination of multiple query conditions. For example, to query all users whose username is “joe” and whose age is 27, you can do it like this: >db.users.find({“username”: “joe”, “age”: 27}) 2. Specify the key to return the result For example, if only the “username” and “email” keys of the Users collection are of interest, use the following query: >db.users.find({}, {“username”: 1, “email”: 1}) At the same time, you can also remove a certain key/value pair from the query result. For example, if you do not want the “fatal_weakness” key in the result, the command is as follows: >db.users.find({}, {“fatal_weakness”: 0}) Can also be used to prevent “_id” from being returned. 3. Query conditions “$lt” is less than, “$lte” is less than or equal to, “$gt” is greater than, “$gte” is greater than or equal to, “$ne” is not equal to, for example: >db.users.find({“age” : {“$gte” : 18, “$lte” : 30}}) $in is similar to IN in Mysql, the usage is as follows: >db.raffle.find({“ticket_no” : {“$in” : [725, 542, 390]}}) $or is similar to OR in Mysql, the usage is as follows: >db.raffle.find({“$or”…

MongoDB database conditional query

The following example illustrates how to execute a SQL-like query, and demonstrates how to use it in MongoDB Implemented in . This It is queried in the MongoDB shell, Of course, you can also use other application drivers or languages ​​to implement: SELECT * FROM things WHERE name=”mongo” > db.things.find({name:”mongo”}).forEach(printjson); { “_id” : ObjectId(“4c2209f9f3924d31102bd84a”), “name” : “mongo” } SELECT * FROM things WHERE x=4 > db.things.find({x:4}).forEach(printjson); { “_id” : ObjectId(“4c220a42f3924d31102bd856”), “x” : 4, “j” : 1 } { “_id” : ObjectId(“4c220a42f3924d31102bd857”), “x” : 4, “j” : 2 } { “_id” : ObjectId(“4c220a42f3924d31102bd858”), “x” : 4, “j” : 3 } { “_id” : ObjectId(“4c220a42f3924d31102bd859”), “x” : 4, “j” : 4 } { “_id” : ObjectId(“4c220a42f3924d31102bd85a”), “x” : 4, “j” : 5 } The query condition is { a:A, b:B, … } Similar to “where a==A and b==B and …”. The above shows all elements, Of course we can also return specific elements, Similar to returning the value of a field in a table, Just specify the name of the element in find({x:4}) SELECT j FROM things WHERE x=4 > db.things.find({x:4}, {j:true}).forEach(printjson); { “_id” : ObjectId(“4c220a42f3924d31102bd856”), “j” : 1 } { “_id” : ObjectId(“4c220a42f3924d31102bd857”), “j” : 2 } { “_id” : ObjectId(“4c220a42f3924d31102bd858”),…

MongoDB database query advanced usage guide

Document-oriented NoSQL The main problem to be solved by the database is not high-performance concurrent read and write, but good query performance while ensuring massive data storage. MongoDB It can almost realize most of the functions of single-table query similar to relational database, and also supports indexing of data. 1.1 Conditional query <, , >= This operator does not need to be explained, the most commonly used and the simplest db.collection.find({ “field” : { $gt: value } } ); // greater than: field > value db.collection.find({ “field” : { $lt: value } } ); // less than: field <value db.collection.find({ “field” : { $gte: value } } ); // greater than or equal to: field >= value db.collection.find({ “field” : { $lte: value } } ); // less than or equal to: field <= value If you want to meet multiple conditions at the same time, you can do db.collection.find({ “field” : { $gt: value1, $lt: value2 } } ); // value1 <field <value 1.2 $all matches all This operator is similar to in in SQL syntax, but the difference is that in only needs to satisfy a certain value in ( ), while $all must satisfy [ ] for…

How to use MongoDB basic query

exact match A single key-value pair: {“age”:28}, returns all documents where the “age” value is 28. Multiple key-value pairs: {“username”:”tom”, “age”:28}, combining multiple query conditions is equivalent to: condition 1 AND condition 2 AND … AND condition N. The query document returns: all documents whose username is tom and whose age is 28. Condition Match Range “$ne” “Not equal” operator, corresponding to: != If the user name is not tom, the query document is: {“username”: {“$ne”:”tom”}} OR query $in It is used to query multiple values ​​corresponding to a key, and perform an OR query on a single key. For example: the event winning numbers are 1, 4, 8, the query document to find all these winning data is: {“ticket_no”:{“$in”:[1, 4, 8]}} $nin In contrast, $nin returns data that does not match the value in the array. For example, the query document to find out the data that has not won a prize is: { “ticket_no”: {“$nin”: [1, 4, 8]} }. $or It is more general to query arbitrary values ​​for multiple keys. It takes an array of all possible conditions as an argument, and can contain other conditionals as well. Such as: { “$or”: [ { “ticket_no”:{ “$in”:[1, 4,…

How to use MongoDB database query

1) . greater than, less than, greater than or equal to, less than or equal to $size matches the number of elements in the array. If there is an object: {a:[“foo”]}, it has only one element: The official website says that it cannot be used to match elements within a range. If you want to find something like $size<5, they suggest creating a field to save the number of elements. You cannot use $size to find a range of sizes (for example: arrays with more than 1 element). If you need to query for a range, create an extra size field that you increment when you add elements. $type based on bson type to match the type of an element, such as matching according to the type ID, but I did not find a bson type and id comparison table. The following query is to query the red records in colors. If the colors element is a data, the database will traverse the elements of this array to query. If the object has an element that is an array, then $elemMatch can match the elements in the inner array: $elemMatch matches { “a” : 1, “b” : 3 }, and…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索