JIYIK CN >

Current Location:Home > Learning > DATABASE > MongoDB >

Mongodb database learning centos system mongodb installation chapter

Author:JIYIK Last Updated:2025/04/30 Views:

This article introduces the process of installing mongodb on Centos. The installation of software will definitely involve 32-bit and 64-bit. Since my system is 32-bit, I will use the 32-bit mongodb software here.

You can choose the corresponding software according to the situation of your machine

1. Install using source package

First download the source package of mongodb. For easy management, I created a new mongodb folder under the / directory and used the following command

$ mkdir –p /mongodb

Jiyi Blog - Mongodb database learning centos system mongodb1

Then type the following command in the Linux terminal

$ cd /mongodb

$ curl -O https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.2.0.tgz

The directory where the downloaded software is stored is /mongodb. After downloading, unzip the software and use the following command

$ tar -zxvf mongodb-linux-i686-3.2.0.tgz

Unzip to the current directory, and then use the following command to adjust the directory structure

$ mv mongodb-linux-i686-3.2.0/* ./

The directory structure is as follows

Jiyi Blog - Mongodb database learning centos system mongodb2

Then delete the empty folder mongodb-linux-i686-3.2.0.

At this point, it can be said that mongodb has been installed.

Next you need to start the mongodb service.

Create a new /data/db folder to store data

$ mkdir –p /data/db

Then start the mongodb service (Note: before starting the service, you must ensure that /data/db has read and write permissions for the current user)

There is a mongod command under /mongodb/bin. This command can be used to start the service. The command is as follows

$ /mongodb/bin/mongod --dbpath /data/db

The following interface description appears

Jiyi Blog - Mongodb database learning centos system mongodb3

This indicates that the service has been successfully started, the listening port is 27017, and it is waiting for the client to connect.

The /mongodb/bin/mongod command above is a bit long. We can use # export PATH=/mongodb/bin:$PATH   to add the mongodb bin directory to the environment variable. The /mongodb/bin/mongod command above can be simplified to mongod.

The above is how to install mongodb using the source package.

2. Install using binary package

(Note: This method is written with reference to the official MongoDB tutorial. Since the official website does not provide 32-bit MongoDB, the 64-bit version is used for demonstration here.)

First, you need to create a yum source, create a new /etc/yum.repos.d/mongodb-org-3.2.repo file, and add the following content to the file

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1

After saving, you can use this yum source to install mongodb. Now start installing mongodb and its associated tools.

$ yum install –y mongodb-org

In addition, we can specify the corresponding version to install, and we can also specify the tools and versions of the tools associated with mongodb, as shown below

$ yum install -y mongodb-org-3.2.0 mongodb-org-server-3.2.0 mongodb-org-shell-3.2.0 mongodb-org-mongos-3.2.0 mongodb-org-tools-3.2.0

At this point, the mongodb installation is complete. Now start the mongodb service

Before starting the service, you must ensure that SELinux allows mongodb to be started. You can use the following command to achieve this effect.

$ setenforce 0

Finally, you can start, stop or restart the mongodb service through the following commands

$ service mongod start Start the service

$ service mongod stop Shut down the service

$ service mongod restart Restart the service

Note: By default, mongodb stores data files in /var/lib/mongo, log files in /var/log/mongodb, and the user is mongod. These can be set in /etc/mongod.conf.

Previous:Storing images in MongoDB

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Storing images in MongoDB

Publish Date:2025/04/30 Views:193 Category:MongoDB

You can use a database to store pictures and other small images in a database table. Such picture files can be processed more efficiently on a file server. However, when image data is stored in a binary field, it can only be accessed by app

List all collections in MongoDB Shell

Publish Date:2025/04/29 Views:156 Category:MongoDB

When using MongoDB , there are several ways to list the collections in the database. This article will discuss four different ways to get a list of collections in a MongoDB database. These methods are as follows: show collections List all c

Querying for non-null values in MongoDB

Publish Date:2025/04/29 Views:139 Category:MongoDB

This MongoDB article will explain how to query for non-null values ​​in MongoDB. To query for non-null values, you can use $ne the operator and $eq the operator and then specify the desired value to query. This article shows the readers

Shutting down with code:100 error in MongoDB

Publish Date:2025/04/29 Views:54 Category:MongoDB

This MongoDB tutorial will teach you to fix the error on different operating systems shutting down with code:100 . It will also talk about the root cause of why this issue occurs. shutting down with code:100 Errors in MongoDB As we all know

SELECT COUNT GROUP BY in MongoDB

Publish Date:2025/04/29 Views:75 Category:MongoDB

In this article, we will discuss the functions in MongoDB. Also, we will point out the aggregation functions in detail. We will explain in detail the different ways to count and sort multiple and single fields of Group in MongoDB. Operation

Differences between MongoDB and Mongoose

Publish Date:2025/04/29 Views:80 Category:MongoDB

This MongoDB article will discuss the differences between MongoDB and Mongoose. Unfortunately, most beginners tend to confuse these two concepts when they start developing applications and use MongoDB as their backend. MongoDB has its own s

Install MongoDB using Homebrew

Publish Date:2025/04/29 Views:161 Category:MongoDB

MongoDB is a well-known unstructured database management system that can handle large amounts of data. It is a document-oriented database system and belongs to the NoSQL family (non-SQL). Data and records are stored as documents that look a

Create a MongoDB dump of the database

Publish Date:2025/04/29 Views:63 Category:MongoDB

In this MongoDB article, you’ll get a walkthrough of Mongodump and Mongorestore , how to use them, and some simple examples of backing up and restoring your collections using both tools. mongodump Commands in MongoDB Mongodump is a tool t

Get the size of the database in MongoDB

Publish Date:2025/04/29 Views:88 Category:MongoDB

When working in MongoDB, do you know the size of your database? Today, we will learn how to get the size of a database in MongoDB using show dbs the command and the method. db.stats() Get the size of the database in MongoDB We can show dbs;

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial