搭建【MongoDB in CentOS7.x】

准备材料

帮助文档
安装包
  • mongodb-linux-x86_64-rhel70-6.0.1.tgz
[root@mongodb01 src]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-6.0.1.tgz
[root@mongodb01 src]# ll
总用量 70012
-rw-r--r--. 1 root root 71688374 96 18:20 mongodb-linux-x86_64-rhel70-6.0.1.tgz
  • mongodb-compass-1.33.0-win32-x64.msi
    官方可视化管理工具,下载链接(一般安装在本地)

  • mongosh-1.5.4-linux-x64.tgz
    官方命令行管理工具,下载链接(安装在服务端端)

配置文件
  • mongod.conf
systemLog:
    #MongoDB发送所有日志输出的目标指定为文件
    destination: file
    #mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径
    path: "/usr/local/mongodb-6.0.1/logs/mongod.log"
    #当mongos或mongod实例重新启动时,mongos或mongod会将新条目附加到现有日志文件的末尾
    logAppend: true
storage:
    #mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。
    dbPath: "/usr/local/mongodb-6.0.1/data/db"
    #启用或禁用持久性日志以确保数据文件保持有效和可恢复
    journal:
        enabled: true
processManagement:
    #启用在后台运行mongos或mongod进程的守护进程模式
    fork: true
net:
    #服务实例绑定的IP(0.0.0.0表示不限制访问来源)
    bindIp: 0.0.0.0
    #bindIp
    #绑定的端口,默认是27017
    port: 27017

安装服务

解压并新建安装目录
[root@mongodb01 src]# tar -zxf mongodb-linux-x86_64-rhel70-6.0.1.tgz
[root@mongodb01 src]# mv mongodb-linux-x86_64-rhel70-6.0.1 mongodb-6.0.1
[root@mongodb01 src]# mv mongodb-6.0.1/ ../ && cd ../mongodb-6.0.1
[root@mongodb01 mongodb-6.0.1]# mkdir -p data/db && mkdir logs && mkdir conf && cd conf
[root@mongodb01 conf]# ll
总用量 4
-rw-r--r--. 1 root root 852 97 09:49 mongod.conf
环境变量
[root@mongodb01 mongodb-6.0.1]# vi /etc/profile.d/mongodb.sh
#!/bin/bash
export MONGO_PATH=/usr/local/mongodb-6.0.1
export PATH=${MONGO_PATH}/bin:$PATH
[root@mongodb01 mongodb-6.0.1]# . /etc/profile
启动服务
[root@mongodb01 mongodb-6.0.1]# ./bin/mongod -f /usr/local/mongodb-6.0.1/conf/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 1251
child process started successfully, parent exiting
开启防火墙
[root@mongodb01 mongodb-6.0.1]# firewall-cmd --zone=public --add-port=27017/tcp --permanent
success
[root@mongodb01 mongodb-6.0.1]# firewall-cmd --reload
success
[root@mongodb01 mongodb-6.0.1]# firewall-cmd --list-ports
27017/tcp
安装命令行工具
[root@mongodb01 src]# tar zxf mongosh-1.5.4-linux-x64.tgz
# 移动到mongodb安装目录下
[root@mongodb01 src]# mv bin/* /usr/local/mongodb-6.0.1/bin/
[root@mongodb01 src]# . /etc/profile
# 链接到本机的mongo服务器
[root@mongodb01 src]# mongosh --port 27017 --host 127.0.0.1
Current Mongosh Log ID:	63180da8deaf56f63606df6a
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
Using MongoDB:		6.0.1
Using Mongosh:		1.5.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2022-09-07T09:50:10.505+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2022-09-07T09:50:10.505+08:00: You are running this process as the root user, which is not recommended
   2022-09-07T09:50:10.505+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
   2022-09-07T09:50:10.505+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
   2022-09-07T09:50:10.505+08:00: Soft rlimits for open file descriptors too low
------

------
   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()
------

test> 
安装图形化工具

这里使用官方提供的免费管理工具:mongo-compass
安装要求:

  • 64-bit version of Microsoft Windows 7 or later.
  • MongoDB 3.6 or later.
  • window10 x86_64版本界面如下 :

管理界面截图

参考文档

  1. 在Linux环境下安装Mongodb数据库(全网最简单全面教程)
  2. Linux环境下MongoDB的下载安装
  3. 转【MongoDB 配置篇】MongoDB 配置文件详解
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值