当前位置: 首页 > news >正文

在 CentOS 系统上直接安装 MongoDB 4.0.25

文章目录

      • 步骤 1:配置 MongoDB 官方源
      • 步骤 2:安装 MongoDB
      • 步骤 3:启动 MongoDB 服务
      • 步骤 4:验证安装
      • 步骤 5:可选配置
      • 注意事项

以下是在 CentOS 系统上直接安装 MongoDB 4.0.25 的详细步骤:


步骤 1:配置 MongoDB 官方源

  1. 使用文本编辑器创建 mongodb-org-4.0.repo 文件:

    sudo vi /etc/yum.repos.d/mongodb-org-4.0.repo
    
  2. 添加以下内容:

    [mongodb-org-4.0]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
    
  3. 保存并退出文件。


步骤 2:安装 MongoDB

  1. 安装指定版本的 MongoDB:

    sudo yum install -y mongodb-org-4.0.25
    
    [root@localhost ~]# sudo yum install -y mongodb-org-4.0.25
    已加载插件:fastestmirror, langpacks
    base                                                                                                       | 3.6 kB  00:00:00     
    centos-sclo-rh                                                                                             | 3.0 kB  00:00:00     
    centos-sclo-sclo                                                                                           | 3.0 kB  00:00:00     
    docker-ce-stable                                                                                           | 3.5 kB  00:00:00     
    extras                                                                                                     | 2.9 kB  00:00:00     
    mongodb-org-4.0                                                                                            | 2.5 kB  00:00:00     
    Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
    14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
    updates                                                                                                    | 2.9 kB  00:00:00     
    (1/3): docker-ce-stable/7/x86_64/primary_db                                                                | 152 kB  00:00:00     
    (2/3): mongodb-org-4.0/7/primary_db                                                                        | 118 kB  00:00:00     
    (3/3): updates/7/x86_64/primary_db                                                                         |  27 MB  00:00:13     
    Determining fastest mirrors* base: mirrors.nju.edu.cn* centos-sclo-rh: mirrors.nju.edu.cn* centos-sclo-sclo: mirrors.nju.edu.cn* extras: mirrors.nju.edu.cn* updates: mirrors.nju.edu.cn
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 mongodb-org.x86_64.0.4.0.25-1.el7 将被 安装
    --> 正在处理依赖关系 mongodb-org-mongos = 4.0.25,它被软件包 mongodb-org-4.0.25-1.el7.x86_64 需要
    --> 正在处理依赖关系 mongodb-org-shell = 4.0.25,它被软件包 mongodb-org-4.0.25-1.el7.x86_64 需要
    --> 正在处理依赖关系 mongodb-org-tools = 4.0.25,它被软件包 mongodb-org-4.0.25-1.el7.x86_64 需要
    --> 正在处理依赖关系 mongodb-org-server = 4.0.25,它被软件包 mongodb-org-4.0.25-1.el7.x86_64 需要
    --> 正在检查事务
    ---> 软件包 mongodb-org-mongos.x86_64.0.4.0.25-1.el7 将被 安装
    ---> 软件包 mongodb-org-server.x86_64.0.4.0.25-1.el7 将被 安装
    ---> 软件包 mongodb-org-shell.x86_64.0.4.0.25-1.el7 将被 安装
    ---> 软件包 mongodb-org-tools.x86_64.0.4.0.25-1.el7 将被 安装
    --> 解决依赖关系完成依赖关系解决==================================================================================================================================Package                             架构                    版本                          源                                大小
    ==================================================================================================================================
    正在安装:mongodb-org                         x86_64                  4.0.25-1.el7                  mongodb-org-4.0                  6.2 k
    为依赖而安装:mongodb-org-mongos                  x86_64                  4.0.25-1.el7                  mongodb-org-4.0                  9.6 Mmongodb-org-server                  x86_64                  4.0.25-1.el7                  mongodb-org-4.0                   17 Mmongodb-org-shell                   x86_64                  4.0.25-1.el7                  mongodb-org-4.0                   10 Mmongodb-org-tools                   x86_64                  4.0.25-1.el7                  mongodb-org-4.0                   41 M事务概要
    ==================================================================================================================================
    安装  1 软件包 (+4 依赖软件包)总下载量:78 M
    安装大小:259 M
    Downloading packages:
    警告:/var/cache/yum/x86_64/7/mongodb-org-4.0/packages/mongodb-org-4.0.25-1.el7.x86_64.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID e52529d4: NOKEY
    mongodb-org-4.0.25-1.el7.x86_64.rpm 的公钥尚未安装
    (1/5): mongodb-org-4.0.25-1.el7.x86_64.rpm                                                                 | 6.2 kB  00:00:00     
    (2/5): mongodb-org-mongos-4.0.25-1.el7.x86_64.rpm                                                          | 9.6 MB  00:00:10     
    (3/5): mongodb-org-server-4.0.25-1.el7.x86_64.rpm                                                          |  17 MB  00:00:15     
    (4/5): mongodb-org-shell-4.0.25-1.el7.x86_64.rpm                                                           |  10 MB  00:00:10     
    (5/5): mongodb-org-tools-4.0.25-1.el7.x86_64.rpm                                                           |  41 MB  00:00:23     
    ----------------------------------------------------------------------------------------------------------------------------------
    总计                                                                                              2.0 MB/s |  78 MB  00:00:39     
    从 https://www.mongodb.org/static/pgp/server-4.0.asc 检索密钥
    导入 GPG key 0xE52529D4:用户ID     : "MongoDB 4.0 Release Signing Key <packaging@mongodb.com>"指纹       : 9da3 1620 334b d75d 9dcb 49f3 6881 8c72 e525 29d4来自       : https://www.mongodb.org/static/pgp/server-4.0.asc
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction正在安装    : mongodb-org-shell-4.0.25-1.el7.x86_64                                                                         1/5 正在安装    : mongodb-org-mongos-4.0.25-1.el7.x86_64                                                                        2/5 正在安装    : mongodb-org-tools-4.0.25-1.el7.x86_64                                                                         3/5 正在安装    : mongodb-org-server-4.0.25-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.0.25-1.el7.x86_64                                                                               5/5 验证中      : mongodb-org-4.0.25-1.el7.x86_64                                                                               1/5 验证中      : mongodb-org-server-4.0.25-1.el7.x86_64                                                                        2/5 验证中      : mongodb-org-tools-4.0.25-1.el7.x86_64                                                                         3/5 验证中      : mongodb-org-mongos-4.0.25-1.el7.x86_64                                                                        4/5 验证中      : mongodb-org-shell-4.0.25-1.el7.x86_64                                                                         5/5 已安装:mongodb-org.x86_64 0:4.0.25-1.el7                                                                                               作为依赖被安装:mongodb-org-mongos.x86_64 0:4.0.25-1.el7   mongodb-org-server.x86_64 0:4.0.25-1.el7   mongodb-org-shell.x86_64 0:4.0.25-1.el7  mongodb-org-tools.x86_64 0:4.0.25-1.el7   完毕!
    
  2. 确保所有组件(mongodb-org-servermongodb-org-shell 等)版本一致:

    sudo yum install -y mongodb-org-server-4.0.25 mongodb-org-shell-4.0.25 mongodb-org-mongos-4.0.25 mongodb-org-tools-4.0.25
    
    [root@localhost ~]# sudo yum install -y mongodb-org-server-4.0.25 mongodb-org-shell-4.0.25 mongodb-org-mongos-4.0.25 mongodb-org-tools-4.0.25
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile* base: mirrors.nju.edu.cn* centos-sclo-rh: mirrors.nju.edu.cn* centos-sclo-sclo: mirrors.nju.edu.cn* extras: mirrors.nju.edu.cn* updates: mirrors.nju.edu.cn
    软件包 mongodb-org-server-4.0.25-1.el7.x86_64 已安装并且是最新版本
    软件包 mongodb-org-shell-4.0.25-1.el7.x86_64 已安装并且是最新版本
    软件包 mongodb-org-mongos-4.0.25-1.el7.x86_64 已安装并且是最新版本
    软件包 mongodb-org-tools-4.0.25-1.el7.x86_64 已安装并且是最新版本
    无须任何处理
    

步骤 3:启动 MongoDB 服务

  1. 启动 MongoDB:

    sudo systemctl start mongod
    
  2. 设置开机自动启动:

    sudo systemctl enable mongod
    
  3. 检查 MongoDB 服务状态:

    sudo systemctl status mongod
    
    [root@localhost ~]# sudo systemctl status mongod
    ● mongod.service - MongoDB Database ServerLoaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)Active: active (running) since 三 2024-11-20 16:05:27 CST; 29s agoDocs: https://docs.mongodb.org/manualProcess: 85819 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)Process: 85816 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)Process: 85813 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)Process: 85809 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)Main PID: 85824 (mongod)Memory: 43.7MCGroup: /system.slice/mongod.service└─85824 /usr/bin/mongod -f /etc/mongod.conf1120 16:05:27 localhost.localdomain systemd[1]: Starting MongoDB Database Server...
    1120 16:05:27 localhost.localdomain mongod[85819]: about to fork child process, waiting until server is ready for connections.
    1120 16:05:27 localhost.localdomain mongod[85819]: forked process: 85824
    1120 16:05:27 localhost.localdomain mongod[85819]: child process started successfully, parent exiting
    1120 16:05:27 localhost.localdomain systemd[1]: Started MongoDB Database Server.
    

步骤 4:验证安装

  1. 使用 MongoDB 客户端连接:

    mongo
    
    [root@localhost ~]# mongo
    MongoDB shell version v4.0.25
    connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
    Implicit session: session { "id" : UUID("47475de1-f2ee-4899-930f-4af70514c21a") }
    MongoDB server version: 4.0.25
    Welcome to the MongoDB shell.
    For interactive help, type "help".
    For more comprehensive documentation, seehttp://docs.mongodb.org/
    Questions? Try the support grouphttp://groups.google.com/group/mongodb-user
    Server has startup warnings: 
    2024-11-20T16:05:27.656+0800 I CONTROL  [initandlisten] 
    2024-11-20T16:05:27.656+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2024-11-20T16:05:27.656+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2024-11-20T16:05:27.656+0800 I CONTROL  [initandlisten] 
    2024-11-20T16:05:27.657+0800 I CONTROL  [initandlisten] 
    2024-11-20T16:05:27.657+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    2024-11-20T16:05:27.657+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2024-11-20T16:05:27.657+0800 I CONTROL  [initandlisten] 
    2024-11-20T16:05:27.657+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    2024-11-20T16:05:27.657+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2024-11-20T16:05:27.657+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()
    ---> 
    
  2. 检查版本:

    db.version()
    
    > db.version()
    4.0.25
    

步骤 5:可选配置

  1. 默认配置文件路径
    /etc/mongod.conf

    [root@localhost ~]# cd /etc/
    [root@localhost 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: filelogAppend: truepath: /var/log/mongodb/mongod.log# Where and how to store data.
    storage:dbPath: /var/lib/mongojournal:enabled: true
    #  engine:
    #  mmapv1:
    #  wiredTiger:# how the process runs
    processManagement:fork: true  # fork and run in backgroundpidFilePath: /var/run/mongodb/mongod.pid  # location of pidfiletimeZoneInfo: /usr/share/zoneinfo# network interfaces
    net:port: 27017bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.#security:#operationProfiling:#replication:#sharding:## Enterprise-Only Options#auditLog:#snmp:
    
  2. 编辑配置文件(如修改监听端口或数据存储路径):

    sudo vi /etc/mongod.conf
    
    • 修改数据目录:
      storage:dbPath: /var/lib/mongo
      
    • 修改监听端口:
      net:port: 27017bindIp: 0.0.0.0
      
  3. 保存后重启服务:

    sudo systemctl restart mongod
    

注意事项

  • 默认数据目录/var/lib/mongo
  • 默认日志目录/var/log/mongodb
  • 默认监听端口27017

如需更改这些路径,请在 /etc/mongod.conf 中编辑并保存后重启服务。


这样就可以在 CentOS 上安装 MongoDB 4.0.25 并运行!

在这里插入图片描述

http://www.lryc.cn/news/488054.html

相关文章:

  • Android和IOS的区别
  • 数据库基础(MySQL)
  • Vue前端开发子组件向父组件传参
  • javaScript语法基础(函数,对象,常用类Array,String,Math和Date)
  • WebStorm 2022.3.2/IntelliJ IDEA 2024.3出现elementUI提示未知 HTML 标记、组件引用爆红等问题处理
  • k8s-NetworkPolicy
  • 【C++】踏上C++学习之旅(九):深入“类和对象“世界,掌握编程的黄金法则(四)(包含四大默认成员函数的练习以及const对象)
  • C++——智能指针剖析
  • 241119.LeetCode——383.赎金信
  • 基于SSM的农家乐管理系统+论文示例参考
  • 用 Python 从零开始创建神经网络(九):反向传播(Backpropagation)(还在更新中。。。)
  • Flink是如何实现 End-To-End Exactly-once的?
  • 【vulhub】nginx解析漏洞(nginx_parsing_vulnerability)
  • 网络协议之邮件协议(SMTP、POP3与IMAP)
  • python学习笔记(3)运算符
  • _FYAW智能显示控制仪表的简单使用_串口通信
  • 激光雷达定位初始化的另外一个方案 通过键盘按键移动当前位姿 (附python代码)
  • 从0-1逐步搭建一个前端脚手架工具并发布到npm
  • 河道水位流量一体化自动监测系统:航运安全的护航使者
  • 维护在线重做日志
  • ASCB1系列APP操控末端回路智能微断 物联网断路器 远程控制开关 学校、工厂、农场、商业大楼等可用
  • Python入门(10)--面向对象进阶
  • Makefile 之 自动化变量
  • 鸿蒙开发:ForEach中为什么键值生成函数很重要
  • 沃丰科技智能外呼机器人:超越人工,重塑外呼体验
  • 百度飞浆:paddle 线性回归模型
  • 【JavaSE】【网络编程】UDP数据报套接字编程
  • 45.坑王驾到第九期:Mac安装typescript后tsc命令无效的问题
  • 20241120-Milvus向量数据库快速体验
  • 【Golang】——Gin 框架中间件详解:从基础到实战