如何在Debian 10(Buster)上安装MongoDB 4

时间:2020-02-23 14:40:47  来源:igfitidea点击:

如何在Debian 10(Buster)上安装MongoDB 4? MongoDB是用C ++编写的开源NoSQL数据库,可实现大规模的可伸缩性,高性能和可用性。从本文更新开始,可用的存储库适用于Debian9. 我们将在Debian 10(Buster)上添加一些技巧以安装MongoDB 4. 但是一旦该存储库可用于Debian 10,则将更新本文。

这是在Debian 10(Buster)上安装MongoDB 4所需的步骤。我在Debian 10服务器的全新最小安装上执行此安装程序。建议这样做,以确保我们不会破坏正在运行的应用程序依赖性。

添加MongoDB存储库

导入MongoDB GPG密钥

sudo apt update
sudo apt -y install gnupg2
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add 

然后将存储库URL添加到Debian系统。

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org.list

在Debian 10(Stretch)上安装MongoDB Server

我们添加了必需的存储库并安装了libcurl3. 现在让我们在Debian 10(Stretch)上安装MongoDB。

sudo apt update
sudo apt -y install mongodb-org

使用apt info命令获取软件包信息。

$apt info mongodb-org
Package: mongodb-org
Version: 4.2.1
Priority: optional
Section: database
Maintainer: Ernie Hershey theitroad@localhost
Installed-Size: 13.3 kB
....

上述软件包的安装将安装以下依赖项软件包:

mongodb-org-server这提供了MongoDB daemonmongod
mongodb-org-mongos这是一个MongoDB Shard守护程序
mongodb-org-shell这为MongoDB提供了一个shell
mongodb-org-tools用于导出,转储和导入等的MongoDB工具

在Debian 10(Stretch)上启动MongoDB Server

服务器守护程序名为mongod。启动并将其设置为在服务器重新启动/启动时启动。

sudo systemctl enable --now mongod

检查其运行状态。

$systemctl status  mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-08-22 23:40:54 CEST; 4s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 5939 (mongod)
   Memory: 48.6M
   CGroup: /system.slice/mongod.service
           └─5939 /usr/bin/mongod --config /etc/mongod.conf

Aug 22 23:40:54 debian1 systemd[1]: Started MongoDB Database Server.
Aug 22 23:40:54 debian1 mongod[5939]: 2019-08-22T23:40:54.447+0200 I STORAGE  [main] Max cache overflow file size custom option: 0

默认情况下,该服务侦听localhost TCP端口27017.

$ss -tunelp
Netid   State    Recv-Q   Send-Q     Local Address:Port        Peer Address:Port                                                                   
udp     UNCONN   0        0                0.0.0.0:68               0.0.0.0:*       users:(("dhclient",pid=440,fd=7)) ino:13373 sk:1 <->           
tcp     LISTEN   0        128            127.0.0.1:27017            0.0.0.0:*       users:(("mongod",pid=5939,fd=11)) uid:106 ino:35394 sk:2 <->   
tcp     LISTEN   0        128              0.0.0.0:22               0.0.0.0:*       users:(("sshd",pid=602,fd=3)) ino:14676 sk:3 <->               
tcp     LISTEN   0        128                 [::]:22                  [::]:*       users:(("sshd",pid=602,fd=4)) ino:14678 sk:4 v6only:1 <->

可以在/etc/mongod.conf文件中更改此设置。

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

IP 127.0.0.1可以替换为服务器网络接口上要绑定的IP地址。

如果进行了更改,请重新启动mongod服务。

sudo systemctl restart mongod

要进入MongoDB shell,请运行:

$mongo
MongoDB shell version v4.2.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("9a688b2e-251c-4951-b92b-28218c9a4154") }
MongoDB server version: 4.2.1
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2019-10-25T21:07:38.418+0000 I  STORAGE  [initandlisten] 
2019-10-25T21:07:38.418+0000 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-10-25T21:07:38.418+0000 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
--
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB Jan use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
--

>