MongoDB is a free and open-source NoSQL Database used commonly in today’s web applications.

MongoDB是一个免费的开源NoSQL数据库,在当今的Web应用程序中普遍使用。

In this tutorial, we will show you how to install and setup MongoDB on your Ubuntu 18.04 machine in a few simple steps!

在本教程中,我们将通过几个简单的步骤向您展示如何在Ubuntu 18.04计算机上安装和设置MongoDB!



步骤1:使用Apt在Ubuntu上安装MongoDB (Step 1: Install MongoDB on Ubuntu Using Apt)

Since the MongoDB package is available in Ubuntu’s official repositories, we can simply use apt to install MongoDB on our system.

由于MongoDB软件包在Ubuntu的官方存储库中可用,因此我们可以简单地使用apt在我们的系统上安装MongoDB。

But before that, update all system critical packages first.

但是在此之前,请先更新所有系统关键软件包。


sudo apt update

Now, install the MongoDB package using:

现在,使用以下命令安装MongoDB软件包:


sudo apt install mongodb
Install MongoDB on Ubuntu
在Ubuntu上安装MongoDB

This will install the latest version of MongoDB on our system.

这将在我们的系统上安装最新版本的MongoDB。

As for any Database System, there is a server and a service associated with the task of Database Management. The MongoDB server is automatically started after the installation.

对于任何数据库系统,都有与数据库管理任务关联的服务器服务 。 安装后,MongoDB服务器将自动启动。

To ensure that our installation went smoothly, we need to ensure that the MongoDB service and the server are working correctly.

为确保安装顺利进行,我们需要确保MongoDB服务和服务器正常运行。

步骤2:检查MongoDB服务 (Step 2: Check the MongoDB Service)

To check the status of the MongoDB service, use systemctl:

要检查MongoDB服务的状态,请使用systemctl


sudo systemctl status mongodb

You’ll get an output similar to the below screenshot.

您将获得类似于以下屏幕截图的输出。

Mongodb Ubuntu Check Service
Mongodb Ubuntu检查服务

So now that we know that our service is running, let’s verify if our MongoDB Server is responding to our requests or not.

因此,既然我们知道我们的服务正在运行,就让我们验证一下MongoDB服务器是否正在响应我们的请求。

步骤3:测试MongoDB服务器 (Step 3: Test the MongoDB Server)

By default, the MongoDB Server is located at the localhost and uses port 27017. So the address of the server is:

默认情况下,MongoDB服务器位于本地主机,并使用端口27017 。 因此服务器的地址为:


127.0.0.1:27017

Let’s test our server by running this command to find the Connection Status using mongo command:

让我们通过运行以下命令来测试服务器,以使用mongo命令查找连接状态:


mongo --eval 'db.runCommand({ connectionStatus: 1 })'

You should get a response like the below screenshot, having the “ok” field as 1, ensuring that our Connection is valid.

您应该收到类似以下屏幕截图的响应,将“ ok ”字段设置为1,确保我们的连接有效。

Mongodb Ubuntu Check Connection Status
Mongodb Ubuntu检查连接状态


步骤4:允许远程访问数据库 (Step 4: Allow remote access to the Database)

By default, the MongoDB server is only allowed by the ufw firewall to operate locally.

默认情况下,仅ufw防火墙允许MongoDB服务器在本地运行。

To allow access to MongoDB on it’s port 27017 from anywhere, we need to allow incoming connections on this port.

要允许从任何地方访问其端口27017上的MongoDB,我们需要允许该端口上的传入连接。

But this is very insecure, since any person can access the Database. To prevent this, only allow IP Addresses which correspond to trusted machines/servers.

但这是非常不安全的,因为任何人都可以访问数据库。 为避免这种情况,仅允许使用与受信任机器/服务器相对应的IP地址。


sudo ufw allow from TRUSTED_IP/32 to any port 27017

Replace TRUSTED_IP with any trusted IP address in the above command.

用以上命令中的任何受信任IP地址替换TRUSTED_IP

This allows connections from your trusted server to reach the MongoDB Database, since ufw now allows these connections.

由于ufw现在允许这些连接,因此这允许来自受信任服务器的连接到达MongoDB数据库。

But we still need to ensure that the MongoDB server does not only listen locally. Therefore, we need to add our trusted machine’s IP to the mongodb.conf configuration file.

但是我们仍然需要确保MongoDB服务器不仅在本地监听。 因此,我们需要将受信任机器的IP添加到mongodb.conf配置文件中。

Use your favorite text editor and edit /etc/mongodb.conf.

使用您喜欢的文本编辑器并编辑/etc/mongodb.conf


sudo vi /etc/mongodb.conf

Go to the bind_ip value.

转到bind_ip值。

Mongodb Ubuntu Config File
Mongodb Ubuntu配置文件

Add your trusted machine’s public IP Address here, by appending to the field using a comma (,).

通过使用逗号 (,)附加到该字段,在此处添加受信任计算机的公共IP地址。

The modified file will look something like this:

修改后的文件将如下所示:

Mongodb Ubuntu Add Server Address
Mongodb Ubuntu添加服务器地址

Exit the editor, after saving changes

保存更改后退出编辑器



步骤5:重新启动MongoDB服务 (Step 5: Restart the MongoDB Service)

Now, we are almost done! We simply need to restart the mongodb service to apply our changes.

现在,我们快完成了! 我们只需要重新启动mongodb服务即可应用更改。


sudo systemctl restart mongodb

We have now successfully configured our MongoDB Server to accept remote connections!

现在,我们已成功配置MongoDB服务器以接受远程连接!



结论 (Conclusion)

In this tutorial. we showed you how you can install and configure the latest version of MongoDB on your Ubuntu 18.04 system. We also made sure that we can accept specific remote connections to our database from another trusted server.

在本教程中。 我们向您展示了如何在Ubuntu 18.04系统上安装和配置最新版本的MongoDB。 我们还确保可以接受来自其他受信任服务器到数据库的特定远程连接。

I hope this served you well and cleared any of your remaining doubts regarding MongoDB installation!

希望这对您有帮助,并消除了您对MongoDB安装的任何疑问!



翻译自: https://www.journaldev.com/33945/install-mongodb-ubuntu

在Ubuntu 18.04上安装MongoDB相关推荐

  1. ubuntu memcached php,如何在 Ubuntu 18.04 上安装 Memcached

    Memcached 是一个免费的开源高性能内存中键值数据存储. 它最常用于通过从数据库调用的结果缓存各种对象来加速应用程序. 在本教程中,我们将介绍在 Ubuntu 18.04 上安装和配置最新版 M ...

  2. skype linux 安装,如何在Ubuntu 18.04上安装Skype

    Skype是世界上最流行的通信应用程序之一,它使您可以拨打免费的在线音频和视频电话,以及可负担得起的拨打全球移动电话和固定电话的国际电话. Skype不是开源应用程序,也不包含在Ubuntu存储库中. ...

  3. 在Ubuntu 18.04上安装和使用Tesseract 4

    量子指南 (QUANTRIUM GUIDES) Today, the extraction of information from scanned documents such as letters, ...

  4. ubuntu19 安装git_在Ubuntu 18.04上安装Git

    步骤1.首先,通过运行以下命令确保您的系统和apt包列表完全更新: apt-get update -y apt-get upgrade -y 第2步.在Ubuntu 18.04上安装Git. 现在让我 ...

  5. ubuntu18.04安装python3_如何在 Ubuntu 18.04上安装 Python3.7

    Python 是世界上最流行的编程语言之一,凭借其简单易学的语法,Python是初学者和经验丰富的开发人员的绝佳选择.随着近几年人工智能和大数据的火热,Python流行度更是进一步飙升,有冲顶编程语言 ...

  6. 如何在Ubuntu 18.04上安装Django

    Django是一个免费的开源高级Python Web框架,旨在帮助开发人员构建安全,可扩展和可维护的Web应用程序. 根据您的需要,有不同的方法来安装Django.它可以使用pip在系统范围内安装或在 ...

  7. webmin安装_如何在Ubuntu 18.04上安装Webmin

    webmin安装 Are you averse to running commands on a terminal and instead prefer managing your Linux sys ...

  8. 如何在Ubuntu 18.04上安装/卸载NodeJS

    NodeJS is a JavaScript framework that allows you to build fast network applications with ease. In th ...

  9. 在Ubuntu 18.04上安装Nginx

    NGINX pronounced as engine-x is an open source and popular HTTP server and can be configured to act ...

最新文章

  1. ios 构建版本一直在处理中_iOS关于审核提交构建版本不显示问题集锦
  2. ASP.NET MVC 1.0 Result 几何?
  3. 深度挖掘 Laravel 生命周期
  4. duration java_Java Duration类| ofHours()方法与示例
  5. include php 相对路径_PHP include_path 分析
  6. 计算机套题库c版,计算机二级C语言上机题库100套(最新版)
  7. 大学课程 | 《计算机系统结构》详细知识点总结
  8. 微信生成带参数二维码以及获取此二维码参数
  9. 加拿大签证材料(一家三口)
  10. asd f sdfsd f afsda fsdasC ASDF
  11. 计算机英语中bar是什么意思啊,bar是什么意思
  12. Rust权威指南 全书笔记
  13. 【SaltStack官方版】—— EventsReactor系统—BEACONS
  14. 初学python者自学anaconda的正确姿势是什么?
  15. PHP保留两位小数的三种方法
  16. 余弦于相似度cos similarity
  17. ARM、X86/Atom、MIPS、PowerPC
  18. 计算机网络学习笔记(一)——什么是Internet
  19. kafka权限认证ssl
  20. Agile - 埃杰团队每日例会博客目录

热门文章

  1. Ruby笔记三(类、对象、属性)
  2. [转载] python中chr和str,以及ordint
  3. 如何理解FPGA的配置状态字寄存器Status Register
  4. Signaltap的使用
  5. Django之模板层
  6. TP收集一些可以用的资源
  7. Android ClassLoader笔记(二)
  8. C++程序设计方法3:类中的静态成员
  9. 21.策略模式(Strategy Pattern)
  10. hive中使用case、if:一个region统计业务(hive条件函数case、if、COALESCE语法介绍:CONDITIONAL FUNCTIONS IN HIVE)...