【发布时间】:2020-04-27 00:06:54
【问题描述】:
起初我遇到了一个问题,mongod 服务完全停止工作。于是我完全卸载了 mongodb 并重新安装它并按照这个线程的说明进行操作:https://askubuntu.com/questions/921753/failed-to-start-mongod-service-unit-mongod-service-not-found
这导致mongod 服务最终启动。
为了让它工作,我还必须遵循这个线程的说明: mongo - couldn't connect to server 127.0.0.1:27017
到目前为止,这个配置只工作了 1 次,那是在我按照说明删除 mongod 目录中的 .lock 文件然后修复 mongod 之后。
我还尝试删除 sock 文件,如下所述:MongoDB Failing to Start - ***aborting after fassert() failure
全部项目重置
然后我尝试完全断开项目;关闭后端的nodemon,退出前端的ng服务,停止并删除mongo docker容器......然后再试一次。这是我在所有事情都应该修复后的分步过程:
重启mongod服务
sudo service mongod restart
重启前端 (从前端目录执行)
ng serve frontend
重启后端 (从后端目录执行)
npx nodemon backend
重启 mongo 容器 (从部署目录执行,mongo 是 docker 容器名称,我是从现有提供的部署脚本构建的)
sudo docker-compose up -d mongo
sudo docker ps -a # check container was created and is running
调试信息:
sudo service mongod 状态
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset:
Active: active (running) since Thu 2020-01-09 11:21:43 CET; 3min 40s ago
Docs: https://docs.mongodb.org/manual
Main PID: 17242 (mongod)
CGroup: /system.slice/mongod.service
└─17242 /usr/bin/mongod --config /etc/mongod.conf
janv. 09 11:21:43 junior-LIFEBOOK-E752 systemd[1]: Started MongoDB Database Server
sudo mongod2020-01-09T11:25:45.983+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] MongoDB starting : pid=17727 port=27017 dbpath=/data/db 64-bit host=junior-LIFEBOOK-E752
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] db version v4.2.2
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] allocator: tcmalloc
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] modules: none
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] build environment:
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distmod: ubuntu1804
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distarch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] target_arch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] options: {}
2020-01-09T11:25:45.987+0100 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] now exiting
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] shutting down with code:48
sudo mongo
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8e813fc2-049c-440d-83ce-0b1d8516c4d0") }
MongoDB server version: 4.2.2
Server has startup warnings:
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten]
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten]
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-01-09T11:21:44.848+0100 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()
所以这里发生了一些奇怪的事情,它没有从项目中找到数据库,我不知道为什么。据我所见,它创建了一个包含我的系统详细信息的新数据库。 请问如何解决这个问题并连接到项目数据库?在我这样做之前,我无法继续前进。
【问题讨论】:
-
好像你已经在mongo端口监听了一些东西,阻塞了启动过程?
-
@JohannesB 嗨,现在有人告诉我,如果 docker 容器中已经包含 mongo,我不需要运行 mongod 服务,所以我在本地禁用了该服务,只是想获取它使用 docker 容器工作,但仍然没有得到输出