千家信息网

如何使用Yum安装MongoDB Linux版

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,本篇内容介绍了"如何使用Yum安装MongoDB Linux版"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学
千家信息网最后更新 2026年11月01日如何使用Yum安装MongoDB Linux版

本篇内容介绍了"如何使用Yum安装MongoDB Linux版"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

1、环境说明

本文使用红帽6.5进行实验。

[root@oracle-test ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.5 (Santiago)

[root@oracle-test ~]# uname -r

2.6.32-431.el6.x86_64

安装目标版本为MongoDB最新版本3.4。

2、使用yum进行安装

从MongoDB官方网站上,获取yum资源库地址。创建对应的Repo文件。

[root@oracle-test ~]# cd /etc/yum.repos.d/

[root@oracle-test yum.repos.d]# ls -l

total 12

-rw-r--r--. 1 root root 74 Dec 28 2016 localyum.repo

-rw-r--r--. 1 root root 198 Jul 16 13:02 mongodb-org-3.4.repo

-rw-r--r--. 1 root root 636 Sep 14 2016 zabbix.repo

对应信息:

[root@oracle-test yum.repos.d]# cat mongodb-org-3.4.repo

[mongodb-org-3.4]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64

gpgcheck=1

enable=1

gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

调用yum进行安装。注意:在yum安装对象上,包括几个对象,分别表示不同的安装内容:

ü mongodb-org:MongoDB全集信息,包括Server、Client(Mongo Shell)、各类型工具;

ü mongodb-org-server:服务器组件;

ü mongodb-org-shell:MongoDB Shell组件,类似于sqlplus;

ü mongodb-org-tools:备份还原工具、数据导入导出等;

[root@oracle-test yum.repos.d]# yum install -y mongodb-org

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package mongodb-org.x86_64 0:3.4.6-1.el6 will be installed

--> Processing Dependency: mongodb-org-tools = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64

--> Processing Dependency: mongodb-org-shell = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64

--> Processing Dependency: mongodb-org-server = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64

--> Processing Dependency: mongodb-org-mongos = 3.4.6 for package: mongodb-org-3.4.6-1.el6.x86_64

--> Running transaction check

---> Package mongodb-org-mongos.x86_64 0:3.4.6-1.el6 will be installed

---> Package mongodb-org-server.x86_64 0:3.4.6-1.el6 will be installed

---> Package mongodb-org-shell.x86_64 0:3.4.6-1.el6 will be installed

---> Package mongodb-org-tools.x86_64 0:3.4.6-1.el6 will be installed

(篇幅原因,有省略......)

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Dependency Installed:

mongodb-org-mongos.x86_64 0:3.4.6-1.el6

mongodb-org-server.x86_64 0:3.4.6-1.el6

mongodb-org-shell.x86_64 0:3.4.6-1.el6

mongodb-org-tools.x86_64 0:3.4.6-1.el6

Complete!

[root@oracle-test yum.repos.d]#

另外,在国内的服务器上,由于网络的原因,可能会有下载中间超时中断的情况。可以重试几次,或者知道下载地址之后,单独通过支持断点程序进行下载。

3、后续配置

使用yum方式若干好处,一个是默认就有配置文件进行程序控制,另一个就是自动以操作系统服务Service的方式组织。

同Oracle一样,我们建议将Selinux关闭。

[root@oracle-test yum.repos.d]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=disabled

以操作系统服务方式运行,避免出现单独shell执行的情况。

[root@oracle-test ~]# chkconfig | grep mongod

mongod 0:off 1:off 2:off 3:on 4:off 5:on 6:off

[root@oracle-test ~]# service mongod status

mongod (pid 2078) is running...

[root@oracle-test log]# ps -ef | grep mongo

mongod 2078 1 0 14:25 ? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf

root 2419 2336 0 14:29 pts/0 00:00:00 grep mongo

[root@oracle-test log]# id mongod

uid=495(mongod) gid=490(mongod) groups=490(mongod)

观察几个方面问题:

首先,rpm安装程序创建了单独用户mongod来作为运行程序主体。其次,mongod启动参数以配置文件/etc/mongod.conf的方式保存在操作系统上,可以编辑运行。第三,chkconfig中可以看到开机自动启动程序服务。

日志和数据文件上,tarball安装比较"简陋",都是/data/db目录和直接输入到屏幕上。使用mongod.conf配置方式后,这种灵活性要好很多。

日志文件:

[root@oracle-test ~]# cd /var/log/

[root@oracle-test log]# ls -l | grep mongo

drwxr-xr-x. 2 mongod mongod 4096 Jul 16 14:16 mongodb

[root@oracle-test mongodb]# pwd

/var/log/mongodb

[root@oracle-test mongodb]# ls -l

total 4

-rw-r-----. 1 mongod mongod 4062 Jul 16 14:25 mongod.log

初始配置文件项目:

[root@oracle-test mongodb]# cd /etc

[root@oracle-test etc]# ls -l | grep mongod.conf

-rw-r--r--. 1 root root 768 Jul 6 02:55 mongod.conf

[root@oracle-test etc]# cat mongod.conf

# mongod.conf

# for documentation of all options, see:

# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.

systemLog:

destination: file

logAppend: true

path: /var/log/mongodb/mongod.log -日志文件位置

# Where and how to store data.

storage:

dbPath: /var/lib/mongo --存储数据位置

journal:

enabled: true

# engine:

# mmapv1:

# wiredTiger:

# how the process runs

processManagement:

fork: true # fork and run in background

pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile

# network interfaces

net:

port: 27017

bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

各种配置项目,可以参见Mongodb官方文档信息:https://docs.mongodb.com/manual/reference/configuration-options/。

4、参数修改实验

尝试在mongod.conf文件上进行简单的修改。对于MongoDB,除了27017端口之外,还会有一个28017的Web方式访问接口。默认是不开放的,需要使用配置文件开启。

net:

port: 27017

bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

http:

enabled: true

JSONPEnabled: true

RESTInterfaceEnabled: true

"mongod.conf" 47L, 847C written

重新启动mongod服务。

[root@oracle-test etc]# service mongod restart

Stopping mongod: [ OK ]

Starting mongod: [ OK ]

2017-07-16T14:44:12.957+0800 I CONTROL [initandlisten]

2017-07-16T14:44:12.960+0800 I NETWORK [websvr] admin web console waiting for connections on port 28017

2017-07-16T14:44:12.961+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data'

2017-07-16T14:44:12.961+0800 I NETWORK [thread1] waiting for connections on port 27017

注意:这个时候,只能进行本地登录,从远程客户端使用shell或者网页都不能访问。

C:\Users\admin>mongo --host 172.xx.xx.xxx

MongoDB shell version v3.4.5

connecting to: mongodb://172.xx.xx.xxx:27017/

2017-07-16T15:01:45.913+0800 W NETWORK [thread1] Failed to connect to 172.16.19

.143:27017 after 5000ms milliseconds, giving up.

2017-07-16T15:01:45.914+0800 E QUERY [thread1] Error: couldn't connect to ser

ver 172.xx.xx.xxx:27017, connection attempt failed :

connect@src/mongo/shell/mongo.js:237:13

@(connect):1:6

exception: connect failed

原因在于net参数的bindIP内容,默认情况为:

net:

port: 27017

bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

需要修改为0.0.0.0,否则只能在本地项目。

net:

port: 27017

bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.

[root@oracle-test etc]# service mongod restart

Stopping mongod: [ OK ]

Starting mongod: [ OK ]

C:\Users\admin>mongo --host 172.xx.xx.xxx

MongoDB shell version v3.4.5

connecting to: mongodb://172.xx.xx.xxx:27017/

MongoDB server version: 3.4.6

Server has startup warnings:

(篇幅原因,有省略……)

2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten]

2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits

too low. rlimits set to 1024 processes, 64000 files. Number of processes should

be at least 32000 : 0.5 times number of files.

2017-07-16T15:12:19.433+0800 I CONTROL [initandlisten]

>

对于出现的soft rlimits提示,可以修改limits.conf文件,设置额外的限制数目。

[root@oracle-test ~]# vi /etc/security/limits.conf

#@student - maxlogins 4

mongod soft nofile 64000

mongod hard nofile 64000

mongod soft nproc 32000

mongod hard nproc 32000

[root@oracle-test ~]# service mongod restart

Stopping mongod: [ OK ]

Starting mongod: [ OK ]

5、结论

本文介绍了使用yum方式安装mongodb的方法。这种方法下,系统出错的情况会更少一些,配置项目也更加清晰。

"如何使用Yum安装MongoDB Linux版"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

文件 配置 方式 服务 情况 程序 内容 原因 系统 项目 操作系统 信息 参数 数据 日志 运行 位置 地址 官方 对象 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网加科技 百单网互联网科技有限公司 西安纸贵互联网科技有限公司 美国互联网保险保险科技 互联网核心科技是什么 金融科技与互联网金融 智慧科技互联网 广州凡科互联网科技 撒么互联网科技公司 互联网科技类展会 四个字互联网科技公司取名 互联网科技股午盘股票涨跌 互联网公司会议桌创意科技软装饰 互联网科技实习生岗位职责 宁夏众和广鑫互联网科技有限公司 浙江互联网科技研学营 每天都有哪些好的互联网科技 江苏互联网智能科技产品出厂价 求路客互联网科技电话 青岛易易互联网科技 互联网科技名片 广州为想互联网科技有限公司 互联网科技工作委员会副主任毛军 善班互联网科技 无锡溥仪互联网科技有限公司 小米互联网科技园设置 互联网科技公司有风险吗 未来五年的互联网科技 互联网科技创业计划的风险分析 武汉亿视互联网科技有限公司
0