Table of Contents
Serve
Use systemctl
Order
Output
Set MongoDB to start at system startup via enable
in conclusion
Home Database MongoDB How to restart a NoSQL database service like MongoDB?

How to restart a NoSQL database service like MongoDB?

Aug 28, 2023 am 08:01 AM

如何重启像 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
Copy after login

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
Copy after login

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
Copy after login

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.
Copy after login

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
Copy after login

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.
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the different types of indexes in MongoDB (single, compound, multi-key, text, geospatial)? What are the different types of indexes in MongoDB (single, compound, multi-key, text, geospatial)? Mar 17, 2025 pm 06:17 PM

The article discusses various MongoDB index types (single, compound, multi-key, text, geospatial) and their impact on query performance. It also covers considerations for choosing the right index based on data structure and query needs.

How do I create users and roles in MongoDB? How do I create users and roles in MongoDB? Mar 17, 2025 pm 06:27 PM

The article discusses creating users and roles in MongoDB, managing permissions, ensuring security, and automating these processes. It emphasizes best practices like least privilege and role-based access control.

How do I choose a shard key in MongoDB? How do I choose a shard key in MongoDB? Mar 17, 2025 pm 06:24 PM

The article discusses selecting a shard key in MongoDB, emphasizing its impact on performance and scalability. Key considerations include high cardinality, query patterns, and avoiding monotonic growth.

How do I use MongoDB Compass for GUI-based management and querying? How do I use MongoDB Compass for GUI-based management and querying? Mar 17, 2025 pm 06:30 PM

MongoDB Compass is a GUI tool for managing and querying MongoDB databases. It offers features for data exploration, complex query execution, and data visualization.

How do I configure auditing in MongoDB for security compliance? How do I configure auditing in MongoDB for security compliance? Mar 17, 2025 pm 06:29 PM

The article discusses configuring MongoDB auditing for security compliance, detailing steps to enable auditing, set up audit filters, and ensure logs meet regulatory standards. Main issue: proper configuration and analysis of audit logs for security

What are the different components of a sharded MongoDB cluster (mongos, config servers, shards)? What are the different components of a sharded MongoDB cluster (mongos, config servers, shards)? Mar 17, 2025 pm 06:23 PM

The article discusses components of a sharded MongoDB cluster: mongos, config servers, and shards. It focuses on how these components enable efficient data management and scalability.

How do I implement authentication and authorization in MongoDB? How do I implement authentication and authorization in MongoDB? Mar 17, 2025 pm 06:25 PM

The article guides on implementing and securing MongoDB with authentication and authorization, discussing best practices, role-based access control, and troubleshooting common issues.

How do I use map-reduce in MongoDB for batch data processing? How do I use map-reduce in MongoDB for batch data processing? Mar 17, 2025 pm 06:20 PM

The article explains how to use map-reduce in MongoDB for batch data processing, its performance benefits for large datasets, optimization strategies, and clarifies its suitability for batch rather than real-time operations.

See all articles