连接mongodb超时

连接mongodb超时

# 具体遇到的问题

# 报错信息的截图

http://img1.sycdn.imooc.com//climg/5fcb751b097f1ed819201030.jpg

http://img1.sycdn.imooc.com//climg/5fcb751b09bbf1f219201030.jpg


# 相关课程内容截图

# 尝试过的解决思路和结果
尝试:

·1.改变ip地址配置-- 输入mongod --dbpath data/ --logpath log/mongo.log --port 27017 --bind_ip 0.0.0.0 --fork

2.关闭防火墙 systemctl stop firewalld
# 粘贴全部相关代码,切记添加代码注释(请勿截图)

[root@localhost mongodb_dir]# cd

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# mongo

MongoDB shell version v4.2.11

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb

Implicit session: session { "id" : UUID("a0466ed0-0877-4190-bfca-6fcf66c895fe") }

MongoDB server version: 4.2.11

Server has startup warnings: 

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] 

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] 

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the

2020-12-05T19:07:11.319+0800 I  CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.

2020-12-05T19:07:11.319+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()

---


> exit

bye

[root@localhost ~]# mongod --dbpath data/ --logpath log/mongo.log --port 27017 --bind_ip 0.0.0.0 --fork

about to fork child process, waiting until server is ready for connections.

forked process: 6046

ERROR: child process failed, exited with error number 1

To see additional information in this output, start without the "--fork" option.

[root@localhost ~]# 



在这里输入代码,可通过选择【代码语言】突出显示

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕美 2020-12-06 18:41:20

同学,你好,

1、同学直接在终端中执行pkill mongo和pkill mongod,关闭进程

2、执行mongod --dbpath data/ --logpath log/mongo.log --port 27017 --bind_ip 0.0.0.0 --fork启动mongodb服务

3、永久开放27017端口:

firewall-cmd --zone=public --permanent --add-port=27017/tcp;

4、重启防火墙

firewall-cmd --reload

5、再执行相应代码即可连接mongodb

好帮手慕美 2020-12-06 10:24:50

同学,你好,同学可根据下述几个方法操作

1、删除 mongodb 的 db 目录下的 mongod.lock 文件;再重启mongodb;

2、看下写的dbpath和logpath的路径是否正确及是否有权限

3、启动时在后面加一个参数,将日志导出到一个可写的目录:./mongod --fork --logpath=/tmp/mongod.log,打开该文件看下具体的报错信息是什么并进行修改

  • 提问者 Buck_messic #1

    http://img1.sycdn.imooc.com//climg/5fcc97dd0959f19119201030.jpg

    方法一,老师没有找到mongodb目录下db目录

    方法三,报错 :   -bash: ./: 是一个目录

    2020-12-06 16:36:50
  • 好帮手慕美 回复 提问者 Buck_messic #2

    同学,你好,

    1、进入mongodb安装目录,删除data目录下的mongod.lock文件

    2、--fork --logpath=/tmp/mongod.log是在启动mongodb时添加的,如mongod --dbpath data/ --logpath log/mongo.log --port 27017 --bind_ip 0.0.0.0 --fork --logpath=/tmp/mongod.log

    3、这俩进程都关闭一下

    pkill mongo

    pkill mongod

    4、再次尝试启动,如果还是不成功,可尝试将--fork参数去掉再启动

    祝学习愉快~~~~

    2020-12-06 17:01:55
  • 提问者 Buck_messic 回复 好帮手慕美 #3

    http://img1.sycdn.imooc.com//climg/5fcca152097b563319201030.jpg

    删除了mongod.lock文件,输入2.4的命令报错:

    Error parsing command line: too many positional options have been specified on the command line

    try 'mongod --help' for more information


    3.不知道老师指定的是什么?

    2020-12-06 17:17:21
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星

相似问题

登录后可查看更多问答,登录/注册

4.入门主流框架Scrapy与爬虫项目实战
  • 参与学习           人
  • 提交作业       107    份
  • 解答问题       1672    个

Python最广为人知的应用就是爬虫了,有趣且酷的爬虫技能并没有那么遥远,本阶段带你学会利用主流Scrapy框架完成爬取招聘网站和二手车网站的项目实战。

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师