SQL is a very powerful language to query, insert, delete, modify data. In recent years the IT industry has developed some alternative ways to store and retrieve data. NoSQL type database servers become very popular. MongoDB is a NoSQL database server to store and retrieve data. In this tutorial, we will look at how to install MongoDB on Linux and distributions like Ubuntu, Debian, CentOS, Fedora, RedHat.
SQL是一种非常强大的语言,可以查询,插入,删除,修改数据。 近年来,IT行业开发了一些替代方法来存储和检索数据。 NoSQL类型的数据库服务器变得非常流行。 MongoDB是用于存储和检索数据的NoSQL数据库服务器。 在本教程中,我们将研究如何在Linux和Ubuntu,Debian,CentOS,Fedora,RedHat等发行版上安装MongoDB。
Fedora,CentOS,RedHat (Fedora, CentOS, RedHat)
We will use yum
or DNF package managers to install MongoDB. Alternatively, we can download the installation package from the MongoDB website.
我们将使用yum
或DNF软件包管理器来安装MongoDB。 另外,我们可以从MongoDB网站下载安装包。
$ sudo dnf install mongodb-server
Ubuntu,Debian (Ubuntu, Debian)
We will use apt
package manager
我们将使用apt
包管理器
$ sudo apt install mongodb-server
检查服务状态 (Check Service Status)
After the installation, we need to start the MongoDB service which is named mongod
. The first step is checking the mongod
service status.
安装后,我们需要启动名为mongod
的MongoDB服务。 第一步是检查mongod
服务状态。
$ sudo systemctl status mongod.service
$ sudo systemctl状态mongod.service
As we can see it is stopped.
如我们所见,它已停止。
使用Systemctl启动MongoDB服务 (Start MongoDB Service with Systemctl)
Systemctl is de facto and a new tool to manage services in Linux. We will use command systemctl start
to start the MongoDB service. We need root privileges to start and stop services.
Systemctl实际上是在Linux中管理服务的新工具。 我们将使用命令systemctl start
启动MongoDB服务。 我们需要root特权才能启动和停止服务。
$ sudo systemctl start mongod.service
检查MongoDB端口 (Check MongoDB Ports)
One of the most occurred problems is a firewall that prevents accessing MongoDB database server ports. We can access with telnet from a remote host like below.
发生最多的问题之一是防火墙,该防火墙阻止访问MongoDB数据库服务器端口。 我们可以从如下所示的远程主机使用telnet访问。
First we will look on MongoDB server which ports are listened. We will use netstat -tl
command. MongoDB generally and by default uses port range 27017-27018 .
首先,我们将在MongoDB服务器上查看要侦听哪些端口。 我们将使用netstat -tl
命令。 MongoDB通常且默认情况下使用端口范围27017-27018。
$ netstat -tln
$ telnet localhost 27017
We can see that we have no problem with network connection. If we get a message like “Connection refused” this means we have a problem with the network connection to the remote host.
我们可以看到网络连接没有问题。 如果我们收到“连接被拒绝”之类的消息,则表明我们与远程主机的网络连接有问题。