我不是网管 - RHEL 8 / CENTOS 8 上安装 MongoDB

MongoDB 是一个可扩展的、开源的、高性能的、面向文档的 NoSQL 数据库。它由 10gen 开发和支持,MongoDB 不使用表和行。

与其他数据库相比,MongoDB 提供了更好的性能,因为它将数据保存在像文档一样的 JASON 中,并使用动态模式。

在本指南中,我们将介绍 MongoDB 在 RHEL 8 和 CentOS 8 系统上的社区版安装。

(1) 启用 MongoDB 4.4 YUM 存储库

MongoDB package and its dependencies are not available in RHEL 8 and CentOS 8 package repositories. So, to install mongodb with yum or dnf command, create the following repository file with beneath contents.

MongoDB 包及其依赖项在 RHEL 8 和 CentOS 8 包存储库中不可用。因此,要使用 yum 或 dnf 命令安装 mongodb,请创建包含以下内容的存储库文件。

$ sudo vi /etc/yum.repos.d/mongodb-org-4.repo

[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

保存并关闭该文件。

(2) 使用 DNF / YUM 命令安装 MongoDB 软件包

要安装 MongoDB 及其依赖包,请使用以下 dnf 命令

$ sudo yum install -y mongodb-org

Install-mongodb4-rhel-centos-dnf-command

上面的命令将安装以下 MongoDB 包

Mongodb-org-package-component

MongoDB 包安装完成后,将创建以下文件和目录。

  • /etc/mongod.conf — Configuration file of MongoDB [ By default localhost IP (127.0.0.1) is bind IP and 27017 is the default port ]
  • /var/lib/mongo — Data directory of MongoDB
  • /var/log/mongodb/mongod.log — Log file of MongoDB

(3) 启动并启用 MongoDB 服务

注意: 在演示期间,我一直将 selinux 状态保持为允许状态。运行以下命令将 selinux 设置为允许的。

$ getenforce
Enforcing
$ sudo setenforce 0
$ sudo sed -i s/^SELINUX=.*$/SELINUX=permissive/ /etc/selinux/config

运行以下命令在重启时启动并启用 mongodb 服务。

$ sudo systemctl start mongod
$ sudo systemctl enable mongod
$ sudo systemctl status mongod

output-mongod-service

如果防火墙已经启用,使用以下 firewall -cmd 命令打开 MongoDB 端口 27017

$ sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent
$ sudo firewall-cmd --reload

(4) 从终端连接到 MongoDB

从终端输入命令 mongo 连接 MongoDB

$ mongo

连接到 Mongo shell 后,我们将得到以下内容

Mongo-Shell-RHEL-CentOS

以上确认 mongodb 安装已经完成,因为我们能够连接 mongo shell。

卸载 /删除 MongoDB

要完全删除 MongoDB,从控制台依次运行如下命令

$ sudo systemctl stop mongod
$ sudo yum erase $(rpm -qa | grep mongodb-org)
$ sudo rm -rf /var/log/mongodb
$ sudo rm -rf /var/lib/mongo

我的开源项目

酷瓜云课堂-开源网课系统

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为什么会这样[user_mongo@nosql01 replicaset]$ cd /opt [user_mongo@nosql01 opt]$ ll total 0 drwxr-xr-x. 3 root root 25 Mar 16 17:08 servers drwxr-xr-x. 2 root root 51 Mar 16 17:10 software [user_mongo@nosql01 opt]$ tar -zxvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/MPL-2 tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/MPL-2: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/README tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/README: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos: Cannot open: No such file or directory tar: Exiting with failure status due to previous errors [user_mongo@nosql01 opt]$ tar -zcvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information.
最新发布
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值