centos7 安装mongodb

Yum 安装

vi /etc/yum.repos.d/mongodb-org-6.0.repo

填充内容如下:

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

sudo yum install -y mongodb-org

 

用这个命令可以指定版本:

sudo yum install -y mongodb-org-6.0.2 mongodb-org-database-6.0.2 mongodb-org-server-6.0.2 mongodb-mongosh-6.0.2 mongodb-org-mongos-6.0.2 mongodb-org-tools-6.0.2

vi /etc/mongod.conf

修改

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 2007
  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

启动:

systemctl start mongod

遇到问题:

journalctl -xe

10月 10 06:07:17 localhost.localdomain systemd[1]: Unit mongod.service entered failed state. 
10月 10 06:07:17 localhost.localdomain systemd[1]: mongod.service failed. 
10月 10 06:07:17 localhost.localdomain polkitd[787]: Unregistered Authentication Agent for unix-process:32471:1252991 (system bus name :1.227, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, 
10月 10 06:07:19 localhost.localdomain polkitd[787]: Registered Authentication Agent for unix-process:32496:1253177 (system bus name :1.228 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org 
10月 10 06:07:19 localhost.localdomain systemd[1]: Starting MongoDB Database Server... -- Subject: Unit mongod.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mongod.service has begun starting up. 
10月 10 06:07:19 localhost.localdomain mongod[32511]: about to fork child process, waiting until server is ready for connections. 
10月 10 06:07:19 localhost.localdomain mongod[32511]: forked process: 32513 
10月 10 06:07:19 localhost.localdomain mongod[32511]: ERROR: child process failed, exited with 48 
10月 10 06:07:19 localhost.localdomain mongod[32511]: To see additional information in this output, start without the "--fork" option. 
10月 10 06:07:19 localhost.localdomain systemd[1]: mongod.service: control process exited, code=exited status=48 
10月 10 06:07:19 localhost.localdomain systemd[1]: Failed to start MongoDB Database Server. -- Subject: Unit mongod.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mongod.service has failed. -- -- The result is failed.

查看日志 vi /var/log/mongodb/mongod.log, 得到:

{
	"t": {
		"$date": "2022-10-10T06:36:19.084-04:00"
	},
	"s": "E",
	"c": "CONTROL",
	"id": 20568,
	"ctx": "initandlisten",
	"msg": "Error setting up listener",
	"attr": {
		"error": {
			"code": 9001,
			"codeName": "SocketException",
			"errmsg": "Permission denied"
		}
	}
}

解决方案:

用命令 mongod -f /etc/mongod.conf --nounixsocket --fork 启动

不用 systemctl start

 

附: nounixsocket: 套接字文件,默认为false ,意为生成socket文件。可在 conf 中配置 当设置为true时,不会生成socket文件。 nounixsocket = false

参考:

Install MongoDB Community Edition on Red Hat or CentOS — MongoDB Manual

https://www.jianshu.com/p/ba63f6c5ad04

https://blog.csdn.net/kakalairen/article/details/119395309

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爬上树顶

打赏可验证我能否靠此文财务自由

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值