Centos 7安装MongoDB

备注:
MongoDB 4.2 版本
CentOS 7.8

一.配置mongodb的yum源

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

二.yum安装mondodb

[root@10-31-1-124 ~]# yum install -y mongodb-org
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base                                                                                                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                                                                                                               | 2.9 kB  00:00:00     
mongodb-org-4.2                                                                                                                                                                      | 2.5 kB  00:00:00     
updates                                                                                                                                                                              | 2.9 kB  00:00:00     
mongodb-org-4.2/7/primary_db                                                                                                                                                         |  47 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mongodb-org.x86_64.0.4.2.10-1.el7 将被 安装
--> 正在处理依赖关系 mongodb-org-mongos = 4.2.10,它被软件包 mongodb-org-4.2.10-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-org-tools = 4.2.10,它被软件包 mongodb-org-4.2.10-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-org-shell = 4.2.10,它被软件包 mongodb-org-4.2.10-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-org-server = 4.2.10,它被软件包 mongodb-org-4.2.10-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mongodb-org-mongos.x86_64.0.4.2.10-1.el7 将被 安装
---> 软件包 mongodb-org-server.x86_64.0.4.2.10-1.el7 将被 安装
---> 软件包 mongodb-org-shell.x86_64.0.4.2.10-1.el7 将被 安装
---> 软件包 mongodb-org-tools.x86_64.0.4.2.10-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

============================================================================================================================================================================================================
 Package                                               架构                                      版本                                              源                                                  大小
============================================================================================================================================================================================================
正在安装:
 mongodb-org                                           x86_64                                    4.2.10-1.el7                                      mongodb-org-4.2                                    5.9 k
为依赖而安装:
 mongodb-org-mongos                                    x86_64                                    4.2.10-1.el7                                      mongodb-org-4.2                                     15 M
 mongodb-org-server                                    x86_64                                    4.2.10-1.el7                                      mongodb-org-4.2                                     25 M
 mongodb-org-shell                                     x86_64                                    4.2.10-1.el7                                      mongodb-org-4.2                                     17 M
 mongodb-org-tools                                     x86_64                                    4.2.10-1.el7                                      mongodb-org-4.2                                     62 M

事务概要
============================================================================================================================================================================================================
安装  1 软件包 (+4 依赖软件包)

总下载量:119 M
安装大小:283 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/mongodb-org-4.2/packages/mongodb-org-4.2.10-1.el7.x86_64.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID 058f8b6b: NOKEY                              ]  0.0 B/s | 181 kB  --:--:-- ETA 
mongodb-org-4.2.10-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mongodb-org-4.2.10-1.el7.x86_64.rpm                                                                                                                                           | 5.9 kB  00:00:01     
(2/5): mongodb-org-mongos-4.2.10-1.el7.x86_64.rpm                                                                                                                                    |  15 MB  00:00:06     
(3/5): mongodb-org-shell-4.2.10-1.el7.x86_64.rpm                                                                                                                                     |  17 MB  00:00:04     
(4/5): mongodb-org-tools-4.2.10-1.el7.x86_64.rpm                                                                                                                                     |  62 MB  00:00:13     
mongodb-org-server-4.2.10-1.el FAILED                                                  84% [================================================================-            ]  1.7 B/s | 100 MB 3202:08:53 ETA 
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.10-1.el7.x86_64.rpm: [Errno 12] Timeout on https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.10-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
mongodb-org-server-4.2.10-1.el FAILED                                                  87% [===================================================================          ]  3.5 B/s | 104 MB 1237:08:30 ETA 
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.10-1.el7.x86_64.rpm: [Errno 12] Timeout on https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.10-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
(5/5): mongodb-org-server-4.2.10-1.el7.x86_64.rpm                                                                                                                                    |  25 MB  00:00:05     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                        215 kB/s | 119 MB  00:09:24     
从 https://www.mongodb.org/static/pgp/server-4.2.asc 检索密钥
导入 GPG key 0x058F8B6B:
 用户ID     : "MongoDB 4.2 Release Signing Key <packaging@mongodb.com>"
 指纹       : e162 f504 a20c df15 827f 718d 4b7c 549a 058f 8b6b
 来自       : https://www.mongodb.org/static/pgp/server-4.2.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mongodb-org-mongos-4.2.10-1.el7.x86_64                                                                                                                                                  1/5 
  正在安装    : mongodb-org-tools-4.2.10-1.el7.x86_64                                                                                                                                                   2/5 
  正在安装    : mongodb-org-shell-4.2.10-1.el7.x86_64                                                                                                                                                   3/5 
  正在安装    : mongodb-org-server-4.2.10-1.el7.x86_64                                                                                                                                                  4/5 
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
  正在安装    : mongodb-org-4.2.10-1.el7.x86_64                                                                                                                                                         5/5 
  验证中      : mongodb-org-server-4.2.10-1.el7.x86_64                                                                                                                                                  1/5 
  验证中      : mongodb-org-4.2.10-1.el7.x86_64                                                                                                                                                         2/5 
  验证中      : mongodb-org-shell-4.2.10-1.el7.x86_64                                                                                                                                                   3/5 
  验证中      : mongodb-org-tools-4.2.10-1.el7.x86_64                                                                                                                                                   4/5 
  验证中      : mongodb-org-mongos-4.2.10-1.el7.x86_64                                                                                                                                                  5/5 

已安装:
  mongodb-org.x86_64 0:4.2.10-1.el7                                                                                                                                                                         

作为依赖被安装:
  mongodb-org-mongos.x86_64 0:4.2.10-1.el7           mongodb-org-server.x86_64 0:4.2.10-1.el7           mongodb-org-shell.x86_64 0:4.2.10-1.el7           mongodb-org-tools.x86_64 0:4.2.10-1.el7          

完毕!
[root@10-31-1-124 ~]# 

三.启动及配置

/var/lib/mongo(数据文件所在目录)
/var/log/mongodb(日志文件所在目录)
/etc/mongod.conf(配置文件所在目录)

-- 启动mongodb
systemctl start mongod
-- 查看mongodb服务的状态
systemctl status mongod
-- 开机启动mongodb
systemctl enable mongod
-- 重启mongodb服务
systemctl restart mongod

测试记录:

[root@10-31-1-124 mongodb]# systemctl start mongod
[root@10-31-1-124 mongodb]# 
[root@10-31-1-124 mongodb]# 
[root@10-31-1-124 mongodb]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2020-11-05 15:29:24 CST; 53s ago
     Docs: https://docs.mongodb.org/manual
  Process: 12568 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 12566 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 12562 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 12560 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 12571 (mongod)
   CGroup: /system.slice/mongod.service
           └─12571 /usr/bin/mongod -f /etc/mongod.conf

11月 05 15:29:24 10-31-1-124 systemd[1]: Starting MongoDB Database Server...
11月 05 15:29:24 10-31-1-124 mongod[12568]: about to fork child process, waiting until server is ready for connections.
11月 05 15:29:24 10-31-1-124 mongod[12568]: forked process: 12571
11月 05 15:29:24 10-31-1-124 systemd[1]: Started MongoDB Database Server.
[root@10-31-1-124 mongodb]# 
[root@10-31-1-124 mongodb]# 
[root@10-31-1-124 mongodb]# systemctl enable mongod
[root@10-31-1-124 mongodb]# 
[root@10-31-1-124 mongodb]# systemctl restart mongod
[root@10-31-1-124 mongodb]# 

开始使用mongodb

[root@10-31-1-124 mongodb]# mongo
MongoDB shell version v4.2.10
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8230936a-78e2-4c50-88a8-8adc43b8e83c") }
MongoDB server version: 4.2.10
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
Server has startup warnings: 
2020-11-05T15:33:01.738+0800 I  CONTROL  [initandlisten] 
2020-11-05T15:33:01.738+0800 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-11-05T15:33:01.738+0800 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-11-05T15:33:01.738+0800 I  CONTROL  [initandlisten] 
2020-11-05T15:33:01.739+0800 I  CONTROL  [initandlisten] 
2020-11-05T15:33:01.739+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-11-05T15:33:01.739+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-11-05T15:33:01.739+0800 I  CONTROL  [initandlisten] 
2020-11-05T15:33:01.739+0800 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-11-05T15:33:01.739+0800 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2020-11-05T15:33:01.739+0800 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 may 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()
---

> 

四.开启认证后mongodb重启方式

mongod.conf 配置文件开启了认证
security:
  authorization: enabled

使用systemctl启动mongod报错
[root@10-31-1-124 ~]# systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See “systemctl status mongod.service” and “journalctl -xe” for details.

此时使用指定配置文件的方式启动mongo

-- 关闭mongo
pkill mongod
-- 启动mongo
mongod -f /etc/mongod.conf --fork

测试记录:

[root@10-31-1-124 ~]# pkill mongod
[root@10-31-1-124 ~]# 
[root@10-31-1-124 ~]# mongod -f /etc/mongod.conf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 5502
child process started successfully, parent exiting
[root@10-31-1-124 ~]# 
[root@10-31-1-124 ~]# 

五.配置文件

mongodb的配置文件有变动,参考官方文档:
https://docs.mongodb.com/v4.2/administration/configuration/#configure-the-database

参考

1.https://docs.mongodb.com/v4.2/tutorial/install-mongodb-on-red-hat/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值