在Linux服务器运维这个范畴里,软件包的安装方式,对系统的稳定性,以及后续维护的便捷性,有着直接的影响。
普通常见的安装方式方法之中,含有借助源代码来进行编译展开安装的形式,以及凭借YUM包管理器来实施安装的途径。
采用源代码进行编译,尽管其具备着较高的灵活程度,然而这个过程却是繁杂琐碎的,并且对于后续的版本更新以及依赖管理而言,是不太利于操作的。
相比来说,借助那 YUM 仓库开展安装,能够去让依赖关系自动被解决掉,并且还能够支持一键式的升级方面情况 ,比较符合有关生产环境的运维方面所规定标准。
特别尤其是在,六十四位的CentOS/RHEL系统当中,使用YUM去安装MongoDB数据库,这是一个极为典型十分具有代表性的场景。
作为一款不是关系型的数据库的MongoDB,在云服务器配置里应用广泛,在Docker环境之外里的物理机部署之中应用也广泛。
基于 YUM 源的,在 64 位 Linux 环境当中安装 MongoDB 的,实操步骤如下,务必严格遵循运维规范,从而确保方案的落地性以及专业性。
1. 准备工作:检查现有 YUM 源
在进行任何软件安装之前,首先得去确认一下,当前系统的 YUM 源里面究竟有没有包含目标软件包。
执行以下命令查看 MongoDB 的包信息:
[root@localhost ~]# yum info mongo-10gen
要是系统返回指示为“没有匹配的相关信息”,那就表明在默认的 Base/Epel 源当中,没有集成 MongoDB 的官方资源。
此刻,我们需以手动的方式,给系统增添一个存有MongoDB软件包的YUM源配置文件。
2. 配置 MongoDB 官方 YUM 源
存放 YUM 源配置文件的目录是 /etc/yum.repos.d/,需在这个目录里有一个新的 .repo 文件需要被创建出来。
运用Vim编辑器,进行创建操作,而后编辑那个名为10gen.repo的文件。
[root@localhost ~]# vi /etc/y.repos.d/10gen.repo
把这样子下文的配置内容,写入到文件里头,这里是以64位的系统作为例子,使用较为新的那MongoDB一个版本仓库地址,用来写进去的哟!
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
要留意,上述配置当中的版本号,也就是7.0,以及架构,即x86_64,需依据实际需求去进行调整。
退出并保存文件之后,执行下面这些命令去清理以及重建 YUM 缓存,从而让新配置成功生效。
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
这个时候,再度去执行查询指令,这样可以看到与MongoDB有关的包信息:
[root@localhost ~]# yum info mongodb-org
该命令将列出服务器端包的详细信息。
[root@localhost geffzhang]# yum info mongo-10gen-server
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Installed Packages
Name : mongo-10gen-server
Arch : x86_64
Version : 2.0.6
Release : mongodb_1
Size : 13 M
Repo : installed
From repo : 10gen
Summary : mongo server, sharding server, and support scripts
URL : http://www.mongodb.org
License : AGPL 3.0
Description : Mongo (from "huMONGOus") is a schema-free document-oriented
: database.
:
: This package provides the mongo server software, mongo sharding
: server softwware, default configuration files, and init.d scripts.
若要查看客户端工具的安装情况,可以使用:
[root@localhost ~]# yum search mongodb-org-shell
3. 安装 MongoDB 服务端与客户端

确认 YUM 源配置无误后,即可执行安装命令。
推行安装一整个 mongodb-org 元包,此二者会自行索取服务端(mongodb-org-server),客户端 Shell(mongodb-org-shell),路由器(mongodb-org-mongos),还有相关工具链。
[root@localhost geffzhang]#
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Installed Packages
Name : mongo-10gen
Arch : x86_64
Version : 2.0.6
Release : mongodb_1
Size : 69 M
Repo : installed
From repo : 10gen
Summary : mongo client shell and tools
URL : http://www.mongodb.org
License : AGPL 3.0
Description : Mongo (from "huMONGOus") is a schema-free document-oriented
: database. It features dynamic profileable queries, full indexing,
: replication and fail-over support, efficient storage of large
: binary data objects, and auto-sharding.
:
: This package provides the mongo shell, import/export tools, and
: other client utilities.
[root@localhost ~]# yum install -y mongodb-org
运行进程里,YUM 会自行处置全部依赖关联,靠着自所设定的仓库那儿下载而后安装 RPM 包。
安装完毕之后,能够运用 rpm -qa | grep mongodb 去检验安装情形。
4. 启动并管理 MongoDB 服务
安装完成之后,要运用 systemctl 命令去管控 MongoDB 服务 ,此适用于 CentOS 7 以及更高版本:
# 启动 MongoDB 服务
[root@localhost ~]# systemctl start mongod
# 设置开机自启
[root@localhost ~]# systemctl enable mongod
# 查看服务运行状态
[root@localhost ~]# systemctl status mongod
要是状态呈现为 active (running) 这种样子,那就表明数据库服务已经成功启动了,并且运行在默认的端口 27017 之上。
5. 版本更新与维护策略
利用 YUM 安装的最大优势在于后续维护的便捷性。
在官方公布新版本之际(尤其是那种涵盖安全修复内容的补丁版本之时),能够凭借以下这些步骤来开展平滑升级:
首先,要进行停止服务的操作,此操作是在升级之前进行的,目的是先停止数据库服务,以此来避免数据写入时出现冲突。
[root@localhost ~]# systemctl stop mongod
2. 执行更新:使用 YUM 命令更新指定软件包。
[root@localhost ~]# yum update -y mongodb-org
于生产环境里头,给出建议,锁定主版本号,仅更新补丁版本,以此来确保兼容性。
3. 重启服务:更新完成后,重新启动服务。
[root@localhost ~]# systemctl start mongod
6. 核心配置文件与优化
存储 MongoDB 的那个主配置文件,它所处的位置是 /etc/mongod.conf。
面向生产环境,特别是云服务器,提议顺应服务器硬件资源,对以下参数予以调整。
net.bindIp:默认绑定 127.0.0.1。
若存在需进行远程连接的情况,比如是借助另一台应用服务器来实现连接,那么就需要将其修改成为内网 IP 或者是 0.0.0.0,这里要留意安全组策略。
以下是重新表述的:storage.dbPath 为数据存储的路径,建议将其挂载于数据盘如 /data 的目录之下,借此防止系统盘写满从而引发故障的情况。
使认证被启用之后,须于此处将授权开启的叫做security.authorization。
运用以上这些步骤,我们于 64 位的 Linux 环境当中,达成了基于 YUM 源的 MongoDB 部署操作。
这种方法,步骤清晰,操作简便,借助仓库管理,能使得后续的安全更新与版本迭代高效及可靠,特别适用于云网站服务器以及域名业务后端环境,这类环境是需要频繁进行维护的。
1. # mongo.conf
2.
3. #where to log
4. logpath=/var/log/mongo/mongod.log
5.
6. logappend=true #以追加方式写入日志
7.
8. # fork and run in background
9. fork = true
10.
11. #port = 27017 #端口
12.
13. dbpath=/var/lib/mongo #数据库文件保存位置
14. directoryperdb=true
15. # Enables periodic logging of CPU utilization and I/O wait
16. #启用定期记录CPU利用率和 I/O 等待
17. #cpu = true
18.
19. # Turn on/off security. Off is currently the default
20. # 是否以安全认证方式运行,默认是不认证的非安全方式
21. #noauth = true
22. #auth = true
23.
24. # Verbose logging output.
25. # 详细记录输出
26. #verbose = true
27.
28. # Inspect all client data for validity on receipt (useful for
29. # developing drivers)用于开发驱动程序时的检查客户端接收数据的有效性
30. #objcheck = true
31.
32. # Enable db quota management 启用数据库配额管理,默认每个db可以有8个文件,可以用quotaFiles参数设置
33. #quota = true
34. # 设置oplog记录等级
35. # Set oplogging level where n is
36. # 0=off (default)
37. # 1=W
38. # 2=R
39. # 3=both
40. # 7=W+some reads
41. #oplog = 0
42.
43. # Diagnostic/debugging option 动态调试项
44. #nocursors = true
45.
46. # Ignore query hints 忽略查询提示
47. #nohints = true
48. # 禁用http界面,默认为localhost:28017
49. # Disable the HTTP interface (Defaults to localhost:27018).这个端口号写的是错的
50. #nohttpinterface = true
51.
52. # 关闭服务器端脚本,这将极大的限制功能
53. # Turns off server-side scripting. This will result in greatly limited
54. # functionality
55. #noscripting = true
56. # 关闭扫描表,任何查询将会是扫描失败
57. # Turns off table scans. Any query that would do a table scan fails.
58. #notablescan = true
59. # 关闭数据文件预分配
60. # Disable data file preallocation.
61. #noprealloc = true
62. # 为新数据库指定.ns文件的大小,单位:MB
63. # Specify .ns file size for new databases.
64. # nssize =
65.
66. # Accout token for Mongo monitoring server.
67. #mms-token =
68. # mongo监控服务器的名称
69. # Server name for Mongo monitoring server.
70. #mms-name =
71. # mongo监控服务器的ping 间隔
72. # Ping interval for Mongo monitoring server.
73. #mms-interval =
74.
75. # Replication Options 复制选项
76.
77. # in replicated mongo databases, specify here whether this is a slave or master 在复制中,指定当前是从属关系
78. #slave = true
79. #source = master.example.com
80. # Slave only: specify a single database to replicate
81. #only = master.example.com
82. # or
83. #master = true
84. #source = slave.example.com

Comments NOTHING