Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Operation and maintenance in mongodb

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the example analysis of operation and maintenance in mongodb, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

We look at mongodb from an administrator's point of view. As an administrator, we are often exposed to four main aspects:

1. Installation and deployment

2. Status monitoring

3. Security certification

4. Backup and restore

Let's explain it bit by bit.

One: installation and deployment

My previous articles are carried by console programs, but this is not the best practice in a production environment. No one wants to find mongodb everywhere after the machine is rebooted. It provides a mode called "service boarding" in mongodb. I think it is easy to understand if you are familiar with wcf. All right, let's put it into practice. Here I'll turn on the mongodb in D drive.

There are two points to pay attention to here:

Logpath: when we use the service to host, we can figure it out with our eyes and definitely will not use console to carry log information.

Install: open the installation service hosting, very happy, reduce the manual operation of the administrator to a minimum, thanks to mongodb.

All right, the console program told me to look at the log log, so I took a look and found that mongodb had told us how to open mongodb, and then I just did it.

I would also like to remind you that many of these command parameters are very complex and easy to forget, but it doesn't matter, the database provides us with a help method, and we can talk about mongod and mongo.

Mongod:

Mongo:

Second: status monitoring

Monitoring allows us to know the health status and performance tuning of the database in real time, which provides us with three ways in mongodb.

1:http monitor

I also mentioned this in my previous article, so I won't repeat it here.

2:serverStatus ()

This function can get the server statistics of mongodb, including: global locks, indexes, user behavior and so on, which is very important to the administrator.

Here's a screenshot that looks familiar.

3:mongostat

No matter how awesome the previous statistics are, they are also static statistics, which do not allow me to watch real-time data changes. fortunately, mongodb provides the mongodstat monitor to be mentioned here, which will be refreshed every second, which is very useful in the actual production environment, or a screenshot, which is very interesting, does it feel like the army is pressing the border?

Three: security certification

As database software, we certainly don't want everyone to be able to access it. In order to ensure the security of data, mongodb can also use user authentication like other database software, so what should we do? In fact, it is very simple, mongodb provides the addUser method, and another note is that if you add it to the admin database, it will be considered a "super administrator."

The above admin user will be regarded as a super administrator, and the third parameter appended by the "jack" user indicates whether it is a "read-only user". All right, we have added everything we need to add, we did not use authentication mode when we first logged in, now we use-- reinstall to restart the service and log in-- auth authentication mode.

All right, let's go to the test collection and flip through the data, and we find that jack users always don't have write permissions, whether authorized or not.

IV: backup and recovery

I don't think I need to talk about the importance of this thing. If it doesn't happen, it will kill people. There are three common methods in mongodb.

1: direct copy

This is the simplest, but it should be noted that it is very risky to directly copy when the server is running. It is possible that when the copy comes out, the data has already been encountered.

Damage, the only guarantee is to temporarily shut down the server, and then restart the copy.

2:mongodump and mongorestore

This is a built-in tool provided to us by mongo and is easy to use to guarantee copy data without shutting down the server.

For ease of operation, we first delete the authorized user.

All right, let's get down to business. Here, I'll create a backup folder on disk D to store the test database.

Look, the data has been backed up, which is great. Now we use mongorestore to restore the past. Remember, it doesn't have to shut down the machine.

One thing to mention is the drop option, which means that I delete the data in the original database before I restore the test data, and you can also view it through help.

3: master-slave replication

In fact, the above two points can not guarantee the real-time performance of data acquisition, because we may still have data in memory when backing up, so we want to say whether we can violently brush the data onto the hard disk, of course. Mongodb provides us with a fsync+lock mechanism to meet our needs.

Fsync+lock first brushes buffer data into the hard disk, then writes to the database a lock, and writes to other instances are blocked until fsync+lock releases the lock.

There's no test here.

Lock: db.runCommand ({"fsync": 1, "lock": 1})

Release lock: db.$cmd.unlock.findOne ()

Thank you for reading this article carefully. I hope the article "sample Analysis of Operations and maintenance in mongodb" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report