Home  >  Article  >  Database  >  How to restart a NoSQL database service like MongoDB?

How to restart a NoSQL database service like MongoDB?

WBOY
WBOYforward
2023-08-28 08:01:171174browse

如何重启像 MongoDB 这样的 NoSQL 数据库服务?

If we are going to use a NoSQL database for our application, then we need something fast and easy to use.

We understand that "NoSQL" does not necessarily mean "no maintenance." We considered using a managed hosting service like MongoDB's Atlas or Amazon's DynamoDB, but we chose to host it ourselves, either on our premises or in our own cloud instance. We evaluated several NoSQL options, including Redis and Cassandra, and chose MongoDB.

We can install it by installing from a Linux distribution, using Mongo's repository, or using a snap. But if something goes wrong, we may need to restart it.

We will look at the different ways to restart a MongoDB database.

Serve

We may be able to find a reference to the old script service. They provide a standard command that will work regardless of whether our Linux installation uses systemd, upstart, or another type of startup service. It doesn't matter whether you use the service; you just don't need it anymore.

Let’s start the local instance of MongoDB again -

$ service mongod restart

This program became popular during the Great Initialization Wars, when different groups argued over different methods of booting and controlling parts of a Unix or Linux system.

Red Hat Linux provides a centralized script called "system-config-kickstart" that is responsible for running these scripts on startup and stopping them when they are no longer needed.

Canonical attempts to replace these scripts with a system called Upstart.

Service scripts have evolved to handle competing start, stop, and status tools - now, service scripts also include systemctl. Red Hat adopted SystemD in version 7.0. Canonical adopts SystemD

in Ubuntu 20.04

Recently, systemd has become our default way to start services in the Linux environment. And the service is no longer needed.

Use systemctl

We will use the systemctl tool to manage MongoDB and any dependencies.

When we initially installed MongoDB, all of its binary and configuration file locations were set up, but are not currently running.

To see if we can use the status command to check if our service has started, we You can run the following command -

$ systemctl status mongod
mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor
preset: enabled)
   Active: inactive (dead)
   Docs: https://docs.mongodb.org/manual

Systemd provides us with several commands for starting, stopping and restarting Serve.

Let’s reboot using the following command -

Order

$ sudo service mongod restart
$ sudo service mongod status

Output

mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor
   preset: enabled)
   Active: active (running) since Tue 2022-10-11 07:45:50 HST; 7s ago
   Docs: https://docs.mongodb.org/manual
   Main PID: 124287 (mongod)
   Memory: 135.4M
   CGroup: /system.slice/mongod.service
   └─154987 /usr/bin/mongod --config /etc/mongod.conf
   Oct 11 07:45:50 shoes systemd[1]: Started MongoDB Database Server.

We can check the status to get the date and time the most recent log entry occurred, and Note their hostnames.

To restart our MongoDB server again, we just need to run -

$ systemctl mongod restart

Set MongoDB to start at system startup via enable

However, even if we start MongoDB using systemd, this does not necessarily mean that it will always run when our system starts.

We can use the systemctl "enable" command to ensure that MongoDB starts with our system.

$ sudo systemctl enable mongod
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.

Now that we understand how systemd manages service files, let's take a quick look at the links under etc/systemd to get a list of these service files.

Now that we have the Dockerfile set up for our application, let's run it! We want to ensure that MongoDB starts when the container starts. To do this, we need to tell Docker to start MongoDB after all its dependencies are met.

in conclusion

Here, we use the systemd service management tool to check the status of the MongoDB server and then restart it if necessary.

There are other ways to do this, but we don't need to know about them unless we are using an older system.

Finally, if we want the MongoDB server to start automatically when restarting the computer, please remember to "enable" it.

The above is the detailed content of How to restart a NoSQL database service like MongoDB?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete