MongoDB的安装(Linux环境)

embedded/2024/9/24 10:25:00/

登录到Linux服务器执行 lsb_release -a ,即可得知服务器的版本信息为:CentOS 7。

# CentOS安装lsb_release包
[root@linux100 ~]# sudo yum install redhat-lsb# 查看Linux版本
[root@linux100 ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core[root@linux100 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)[root@linux100 ~]# hostnamectlStatic hostname: linux100Icon name: computer-vmChassis: vmMachine ID: fb9d8715fff144aca93accad42cec460Boot ID: 49ec505cca3d4052a6115b36a670e7e6Virtualization: vmwareOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 3.10.0-1160.25.1.el7.x86_64Architecture: x86-64

需要在官网先确定系统对应的Mongo DB版本:平台支持的MongoDB版本比对

这里Linux服务器版本为CentOS 7 x86-64,则MongoDB选择7.0.8版本。

1 在官网下载安装包

MongoDB官网下载地址:MongoDB Enterprise Server Download | MongoDB

MongoDB从6.0.10及其之后版本中,bin目录下就没有mongo可执行文件,则需要单独安装官方客户端命令行工具MongoDB shell来连接进行数据库操作,它不支持图形用户页面 官网下载地址:https://www.mongodb.com/try/download/shell。

如需使用其他MongoDB客户端工具可看该文章:MongoDB的安装(window环境)_windows下重装mongodb-CSDN博客文章浏览阅读649次,点赞7次,收藏11次。MongoDB shell是官方客户端命令行工具,不支持图形用户页面。_windows下重装mongodbhttps://blog.csdn.net/qq_39512532/article/details/135533903

2 安装MongoDB

(1)将下载的两个压缩包上传到服务器的 /opt/software 路径下

[root@linux100 ~]# cd /opt/software/
[root@linux100 software]# ll
总用量 12922
-rw-r--r--. 1 root   root   154767684 4月  24 04:22 mongodb-linux-x86_64-enterprise-rhel70-7.0.8.tgz
-rw-r--r--. 1 root   root    80612324 4月  24 05:09 mongosh-2.2.5-linux-x64.tgz

(2)解压文件到自定义目录 /opt/module/ 路径下并改名:

# 文件解压缩
[root@linux100 software]# tar -zxvf mongodb-linux-x86_64-enterprise-rhel70-7.0.8.tgz -C /opt/module
[root@linux100 software]# tar -zxvf mongosh-2.2.5-linux-x64.tgz -C /opt/module# 修改名称
[root@linux100 software]# cd /opt/module/
[root@linux100 module]# mv mongodb-linux-x86_64-enterprise-rhel70-7.0.8 mongodb-7.0.8
[root@linux100 module]# mv mongosh-2.2.5-linux-x64 mongosh-2.2.5

扩展:以下是两个文件bin目录下的文件列表

MongoDB的bin目录下文件详解:

文件名称说明描述
mongod服务器程序,用于启动 MongoDB 服务;
mongosMongoDB 分片服务,用于管理分片集群;

(3)创建MongoDB的数据存储目录和日志存储目录

# 在mongodb-7.0.8文件下创建数据存储目录和日志存储目录
[root@linux100 module]# cd mongodb-7.0.8
[root@linux100 mongodb-7.0.8]# mkdir -p data
[root@linux100 mongodb-7.0.8]# mkdir -p log
[root@linux100 mongodb-7.0.8]# touch log/mongodb.log

(4)创建启动用的配置文件mongod.conf

[root@linux100 mongodb-7.0.8]# mdkir config
[root@linux100 mongodb-7.0.8]# vim config/mongod.conf

mongod.conf配置以下内容:

# 数据存储位置
dbpath=/opt/module/mongodb-7.0.8/data/

# 日志存储位置
logpath=/opt/module/mongodb-7.0.8/log/mongodb.log

# 运行时占用端口
port=27017

# fork为true指明以后台方式启动
fork=true

3 启动MongoDB及其客户端

[root@linux100 mongodb-7.0.8]# cd bin# 启动MongoDB服务端
[root@linux100 bin]# ./mongod -f /opt/module/mongodb-7.0.8/config/mongod.confabout to fork child process, waiting until server is ready for connections.
forked process: 21418
child process started successfully, parent exiting# 启动MongoDB客户端,默认连接本机的MongoDB服务(以默认端口连接),并进入到test数据库
[root@linux100 bin]# cd /opt/module/mongosh-2.2.5/bin/
[root@linux100 bin]# ./mongosh
Current Mongosh Log ID: 66285b69ce6a67cac62202d7
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5
Using MongoDB:          7.0.8
Using Mongosh:          2.2.5For mongosh info see: https://docs.mongodb.com/mongodb-shell/------The server generated these startup warnings when booting2024-04-24T09:07:39.038+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted2024-04-24T09:07:39.038+08:00: You are running this process as the root user, which is not recommended2024-04-24T09:07:39.038+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning2024-04-24T09:07:39.038+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' in this binary version2024-04-24T09:07:39.038+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' in this binary version2024-04-24T09:07:39.038+08:00: Soft rlimits for open file descriptors too low
------Deprecation warnings:- Using mongosh on the current operating system is deprecated, and support may be removed in a future release.
See https://www.mongodb.com/docs/mongodb-shell/install/#supported-operating-systems for documentation on supported platforms.
Enterprise test>

问题:

如果Mongodb服务和客户端不在同一台服务器,连接MongoDB服务连接不上!!!

在本地浏览器访问http://192.168.243.100:27017,访问失败!!!

解决方案:

(1)关闭MongoDB所在服务器防火墙,具体可参考下面链接:

Linux服务器防火墙的操作icon-default.png?t=N7T8https://blog.csdn.net/qq_39512532/article/details/131229204(2)mongodb启动时需要绑定所在IP:

[root@linux100 ~]# cd /opt/module/mongodb-7.0.8/bin
# 启动MongoDB服务端,并绑定该服务ip
[root@linux100 bin]# ./mongod -f /opt/module/mongodb-7.0.8/config/mongod.conf --bind_ip 192.168.243.100# 启动Mongodb客户端
[root@linux100 bin]# ./mongosh mongodb://192.168.243.100:27017

在浏览器中输入地址测试MongoDB是否启动成功:http://192.168.243.100:27017

4 操作数据库

MongoDB数据库的详细操作步骤可参考该链接:

MongoDB的数据库操作icon-default.png?t=N7T8https://blog.csdn.net/qq_39512532/article/details/135533055

 5 关闭MongoDB

# 使用lsof命令查看MongoDB是否运行,也可找到该端口上运行的进程ID
[root@linux100 bin]# lsof -i :27017
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mongod  21418 root   15u  IPv4 505796      0t0  TCP localhost:27017 (LISTEN)# 关闭MongoDB服务
[root@linux100 bin]# kill -9 21418


http://www.ppmy.cn/embedded/21045.html

相关文章

hive创建hbase外部关联表实例

在cdh6.3.2已经做好hbase和hive相关配置&#xff0c;这里不阐述。 要创建上述的表结构&#xff0c;你需要先在HBase中创建相应的表&#xff0c;然后在Hive中创建一个EXTERNAL TABLE来映射到这个HBase表。以下是详细的步骤&#xff1a; 步骤1&#xff1a;在HBase中创建表 确定…

Java学习1:java入门

java入门 1.介绍Java java——sun公司——被甲骨文收购 一开始叫Oak&#xff0c;后期改名为java; java之父詹姆斯高斯林 企业级应用开发 JavaSE JavaEE JavaME 高级编程语言 2.搭建开发环境 JDK8&#xff0c;JDK11&#xff0c;JDK17————>LTS长期支持版 ps:在…

设计模式:单例、原型和生成器

在这篇文章中&#xff0c;我们将重点介绍其余的创建模式&#xff1a;Singleton&#xff0c;Builder和Prototype。 在我看来&#xff0c;这些模式不如工厂重要。然而&#xff0c;了解它们仍然很有用。我将提供UML描述&#xff0c;简单的java示例&#xff08;这样即使你不了解jav…

Vitis HLS 学习笔记--IDE软件高效操作指引

目录 1. 简介 2. 实用软件操作 2.1 C/RTL Cosimulation 选项 2.2 Do not show this dialog again 2.3 New Solution 2.4 对比 Solution 2.5 以命令行方式运行&#xff08;windows&#xff09; 2.6 文本缩放快捷键 2.7 查看和修改快捷键 2.8 将Vitis HLS RTL 导入 Viv…

vscode 使用文件模板功能来添加版权信息

vscode 新建文件的时候&#xff0c;自动填充作者及版权信息 无需使用插件&#xff0c;操作如下&#xff1a; 选择 “首选项(Preferences)”。在搜索框中输入 “file template” 或者 “文件模板”&#xff0c;然后选择相关的设置项。 {"C_Cpp.clang_format_fallbackSt…

Vue3、Vite和HTML5之间的关系

Vue3、Vite 和 HTML5 分别代表不同的技术和概念&#xff0c;它们之间存在相互关联。 1、Vue3 Vue3是一个用于创建用户界面的 JavaScript 框架&#xff0c;通过数据绑定、组件化设计和响应式系统&#xff0c;帮助开发者高效构建和维护复杂的互动界面。Vue3 中的模板使用 HTML&…

【并行计算】【《云计算与分布式系统·从并行处理到物联网》笔记】第一章:分布式系统模型和关键技术

文章目录 [toc]1.1|互联网之上的可扩展计算互联网计算的时代高性能计算高吞吐量计算三种新的计算范式 可扩展性计算趋势和新的范式并行度 物联网和CPS物联网信息物理融合系统CPS 个人主页&#xff1a;丷从心 系列专栏&#xff1a;计算机网络 1.1|互联网之上的可扩展计算 互联…

微软发布Phi-3 Mini,性能媲美GPT-3.5、Llama-3,可在手机端运行

前言 微软发布了最新版的Phi系列小型语言模型(SLM) - Phi-3。这个系列包括3个不同参数规模的版本&#xff1a;Phi-3 Mini (38亿参数)、Phi-3 Small (70亿参数)和Phi-3 Medium (140亿参数)。 Phi系列模型是微软研究团队开发的小规模参数语言模型。从第一代Phi-1到第二代Phi-2&…