mongodb 安装问题

本文介绍了MongoDB5.0及以上版本启动时遇到的非法指令、childprocess失败、配置服务器和添加节点错误,重点讲解了如何通过setDefaultRWConcern调整写入安全级别以及处理openfiles限制。还提到节点异常关闭后的数据修复方法和注意事项。
摘要由CSDN通过智能技术生成

1. mongodb启动时显示 Illegal instruction (core dumped)

mongodb 5.0之后(包括5.0) 开始使用需要使用 AVX 指令集
在这里插入图片描述

2.启动时报错 ERROR: child process failed, exited with 1在这里插入图片描述

通过指令 bin/mongod --repair./bin/mongod -f configs/mongodb.conf --repair查看报错信息
在这里插入图片描述
根据报错信息进行修改

3. 配置服务器添加节点时报错

Reconfig attempted to install a config that would change the implicit defaul... Use the setDefaultRWConcern command to set a cluster-wide write concern and try the reconfig again

解决方法,修改默认读写关注配置
官网修改地址

db.adminCommand({
  "setDefaultRWConcern" : 1,
  "defaultWriteConcern" : {
    "w" : 2
  }
})

选项信息
在这里插入图片描述
“w” : 1 只要主节点写入成功,就直接返回成功的响应,而不管副节点的同步情况

“w” : majority 超过节点半数【(节点数+1)/2】写入成功,才返回成功响应

“w” : 0 不等待任何节点确认写操作,只需写入到内存就返回成功,这是最低级别的写安全级别,这个配置可以提供写入性能,但也有一定的风险

“w” : 等待指定数量的节点确认写成功

其他注意: 配置服务器不能有裁决节点(7.0.8版本测试所得)

路由添加分片集群时报错

Cannot add ***/***  as a shard since the implicit default write concern on this shard is set to {w : 1}, because number of arbiters in the shard's configuration caused the number of writable voting members not to be strictly more than the voting majority. Change the shard configuration or set the cluster-wide write concern using the setDefaultRWConcern command and try again.

在 mongos 实例中 我们使用命令 db.adminCommand({ “getDefaultRWConcern”: 1 }) 可以查看到当前mongos 默认设置的写入安全机制defaultWriteConcern,默认是 majority (多数确认),这是mongodb5.0后开始的默认设置 ,这意味着当进行写操作时,至少要有超过大多数的数据节点确认写操作成功,才会返回成功的响应,目前我们是3个节点,mongo系统定义的一半节点数是 (3+1)/2=2,需要超过2,也就是至少要有3个节点写入成功才行,但是我们设置了一个 仲裁节点,导致3个shard节点中,只有2个可写数据的节点,怎么也不会写成功了,所以导致失败

解决方法,将写入安全级别调低,在路由上使用以下命令

db.adminCommand({  "setDefaultRWConcern" : 1,  "defaultWriteConcern" : {    "w" : 1  }})

4. 节点异常关闭后无法重启

  1. 删除data/db下的mongod.lock文件,再启动
  2. 如果还是启动失败
    在这里插入图片描述
    An incomplete repair has been detected! This is likely because a repair operation unexpectedly failed before completing. MongoDB will not start up again without --repair.
//修复数据
mongod --dbpath db目录 --repair

尝试删除storage.bson文件
```
//删除db目录里面的storage.bson 
rm -rf db目录/storage.bson
```

5.注意设置服务器**open files,防止出现报错"error":“Too many open files”}**

查看配置当前open files信息

ulimit -a

修改

 sudo su
 ulimit -n 102400
# 临时修改(仅当前窗口有效)

以下全局有效(需重启)


 vim /etc/security/limits.conf

# 添加以下配置

* soft nofile 102400

* hard nofile 102400

例如:


# - chroot - change root to directory (Debian-specific)
#
#<domain> <type> <item> <value>
#

#* soft core 0
#root hard core 100000
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#ftp - chroot /ftp
#@student - maxlogins 4


* soft nofile 102400
* hard nofile 102400

# End of file
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装 MongoDB,你可以按照以下步骤进行操作: 1. 前往 MongoDB 官方网站(https://www.mongodb.com/try/download/community)下载适合你操作系统的 MongoDB 安装程序。 2. 根据你的操作系统,选择合适的安装程序。如果你使用的是 Windows,选择 MSI 安装程序;如果你使用的是 macOS,选择 TGZ 压缩文件;如果你使用的是 Linux,选择对应的发行版安装包。 3. 下载完成后,运行安装程序,并按照提示进行安装。在 Windows 上,只需双击 MSI 安装程序并按照向导进行安装;在 macOS 上,解压 TGZ 压缩文件并将解压后的文件夹移动到合适的位置;在 Linux 上,使用适当的包管理器进行安装。 4. 安装完成后,你可以选择将 MongoDB 的可执行文件路径添加到系统环境变量中,这样你就可以在任何位置使用 `mongod` 和 `mongo` 命令了。 5. 启动 MongoDB 服务。在 Windows 上,可以通过服务管理器启动 MongoDB 服务;在 macOS 和 Linux 上,打开终端并运行 `mongod` 命令启动 MongoDB 服务。 6. 运行 `mongo` 命令,连接到 MongoDB 数据库服务器。默认情况下,MongoDB 使用本地主机上的端口 27017 进行连接。 完成以上步骤后,你就成功安装MongoDB。你可以使用 `mongo` 命令行工具或者 MongoDB 的官方驱动程序来进行数据库操作。如果你需要更多详细的信息,可以参考 MongoDB 官方文档(https://docs.mongodb.com)。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值