Home System Tutorial LINUX Set up mongodb on Linux operating system

Set up mongodb on Linux operating system

Dec 30, 2023 pm 12:49 PM
linux linux tutorial Red Hat linux system linux command linux certification red hat linux linux video

Introduction MongoDB is a product between a relational database and a non-relational database. It is the most feature-rich among non-relational databases and is most like a relational database. The data structure it supports is very loose and is a bson format similar to json, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to an object-oriented query language. It can almost implement most functions similar to single-table queries in relational databases, and it also supports indexing of data.
1. Download the Linux installation package

As shown below, place it in a certain corner of the local area. Remember the location~
在 Linux 上配置 mongodb

2. Connect to your server
ssh root@你的IP //回车输入密码 
Copy after login
3. Installation package upload

Open another ssh window (command n). If it is windows, open a new cmd window. Because we want to operate local files, we have already logged in to the server in the previous window. There are many ways to pass, I will only demonstrate one of them.
cd "The folder where the installation package is located" //Go to the location where you just placed the installation package<br> scp "local file" root@yourIP // Enter and enter the password to start transmission
As shown below, I transferred it to the root directory of the server. In fact, it is not recommended. You can put it in an inherent directory, such as /usr/local
在 Linux 上配置 mongodb
ls -l //Expand in list form, we can see that the download has been successful.
在 Linux 上配置 mongodb

4. Unzip the installation package

tar -zxvf mongodb-linux-x86_64-3.4.6.tgz //Decompression Different files have different decompression commands, you can use Baidu yourself
在 Linux 上配置 mongodb

5. One step to fill the hole

I just said that you can put the stuff you install each time into a fixed folder, so I moved the unzipped files to the /usr/local/mongodb directory. If you have already put it in the location you like, you can Skip this step. If you don’t know how to move, you can take a look.
cd /user/local //Enter local<br> mkdir mongodb //Create mongodb folder<br> cd / //Enter the root directory<br> mv mongodb-linux-x86_64-3.4.6 /usr/local/mongodb /*Move the decompressed package just now into /usr/local/mongodb*/
在 Linux 上配置 mongodb

6. Configure mongodb running environment
mkdir data //创建data文件夹,存放数据库db文件  
mkdir logs //创建logs文件夹,存放日志文件  
cd logs //进入logs  
touch mongo.log //创建log文件  
cd .. //返回上一级  
mkdir etc //创建配置文件夹  
cd etc // 进入etc  
vim mongo.conf //编辑同时创建mongo.conf 文件
Copy after login

The following is the code in the mongo.conf file. Be careful not to make mistakes. After entering the file, you must press i on the keyboard to start writing code.

dbpath = /usr/local/mongodb/data //路径一定要输入绝对的  
logpath = /usr/local/mongodb/logs/mongo.log //路径一定要输入绝对的  
logappend = true  
journal = true  
quiet = true  
port = 27017 //端口
Copy after login

After writing, press the esc key to exit, then press shift: it will appear at the bottom: Then enter wq, save and exit.
在 Linux 上配置 mongodb
At this point it's almost the end.

7. Start mongodb
cd mongodb/mongodb-linux-x86_64-3.4.6/bin //进入安装包的bin目录下 
mongod -f /usr/local/mongodb/etc/mongo.conf  //启动1方法  或 ./mongod -f /usr/local/mongodb/etc/mongo.conf  //启动2方法  
Copy after login

If you enter this command, the following picture will appear. There is no change, only the cursor flashes.
在 Linux 上配置 mongodb

8. Whether the local test is successful

The visualization tool I use is Robo 3t. Create a new link, enter the server address as address, and fill in the port configured in your mongo.conf, which is basically 27027.
在 Linux 上配置 mongodb
Click Save and proceed as shown below to connect.
在 Linux 上配置 mongodb
If you get to this step, it's basically a success.
在 Linux 上配置 mongodb

9. Small pit warning

I previously wrote the path in mongo.conf relative, and the following problem occurred.
在 Linux 上配置 mongodb

Then it looks like this.
在 Linux 上配置 mongodb

10. Summary

There are many methods, I wrote only one of them, and it is my first time to install it. There are some pitfalls in it. Don’t admit defeat when you encounter problems, they will always be solved. If I write something wrong or bad, I hope you will give me some advice~

The above is the detailed content of Set up mongodb on Linux operating system. 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

See all articles