Тайм-аут выбора сервера через 10000 мс - Невозможно подключить Compass к mongoDB на локальном хосте - PullRequest
1 голос
/ 30 сентября 2019

Я изучаю MongoDB и пытаюсь подключить Compass к моей базе данных на моем локальном компьютере, но постоянно получаю сообщение об ошибке «Выбор сервера истек через 10000 мс» на Compass каждый раз,

enter image description here

вот лог в моем терминале:

    ~$ mongod
2019-09-30T08:51:56.372+0700 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] MongoDB starting : pid=4661 port=27017 dbpath=/data/db 64-bit host=dell
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] db version v4.2.0
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] git version: a4b751dcf51dd249c5865812b390cfd1c0129c30
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] allocator: tcmalloc
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] modules: none
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] build environment:
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten]     distmod: ubuntu1804
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten]     distarch: x86_64
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten]     target_arch: x86_64
2019-09-30T08:51:56.377+0700 I  CONTROL  [initandlisten] options: {}
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] 
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3427M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2019-09-30T08:51:57.030+0700 I  STORAGE  [initandlisten] WiredTiger message [1569808317:30575][4661:0x7f5edea92b00], txn-recover: Recovering log 4 through 5
2019-09-30T08:51:57.072+0700 I  STORAGE  [initandlisten] WiredTiger message [1569808317:72698][4661:0x7f5edea92b00], txn-recover: Recovering log 5 through 5
2019-09-30T08:51:57.130+0700 I  STORAGE  [initandlisten] WiredTiger message [1569808317:130714][4661:0x7f5edea92b00], txn-recover: Main recovery loop: starting at 4/6144 to 5/256
2019-09-30T08:51:57.209+0700 I  STORAGE  [initandlisten] WiredTiger message [1569808317:209489][4661:0x7f5edea92b00], txn-recover: Recovering log 4 through 5
2019-09-30T08:51:57.292+0700 I  STORAGE  [initandlisten] WiredTiger message [1569808317:291996][4661:0x7f5edea92b00], txn-recover: Recovering log 5 through 5
2019-09-30T08:51:57.340+0700 I  STORAGE  [initandlisten] WiredTiger message [1569808317:340285][4661:0x7f5edea92b00], txn-recover: Set global recovery timestamp: (0,0)
2019-09-30T08:51:57.597+0700 I  RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-09-30T08:51:57.601+0700 I  STORAGE  [initandlisten] Timestamp monitor starting
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] 
2019-09-30T08:51:57.681+0700 I  SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
2019-09-30T08:51:57.681+0700 I  STORAGE  [initandlisten] Flow Control is enabled on this deployment.
2019-09-30T08:51:57.681+0700 I  SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
2019-09-30T08:51:57.681+0700 I  SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
2019-09-30T08:51:57.682+0700 I  SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
2019-09-30T08:51:57.682+0700 I  FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-09-30T08:51:57.683+0700 I  SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
2019-09-30T08:51:57.684+0700 I  NETWORK  [initandlisten] Listening on /tmp/mongodb-27017.sock
2019-09-30T08:51:57.684+0700 I  NETWORK  [initandlisten] Listening on 127.0.0.1
2019-09-30T08:51:57.684+0700 I  SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
2019-09-30T08:51:57.684+0700 I  NETWORK  [initandlisten] waiting for connections on port 27017
2019-09-30T08:56:56.140+0700 I  NETWORK  [listener] connection accepted from 127.0.0.1:59152 #1 (1 connection now open)
2019-09-30T08:56:56.142+0700 I  NETWORK  [conn1] received client metadata from 127.0.0.1:59152 conn1: { driver: { name: "nodejs-core", version: "3.2.7" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "5.0.0-29-generic" }, platform: "Node.js v10.2.0, LE", application: { name: "MongoDB Compass" } }
2019-09-30T08:56:56.143+0700 I  NETWORK  [conn1] end connection 127.0.0.1:59152 (0 connections now open)

На самом деле я не вижу никакой другой ошибки, поэтому я не знаю, как Google.

Как видите, mongo получает запрос клиента от компаса, но он немедленно закрывается

2019-09-30T08:51:57.684+0700 I  NETWORK  [initandlisten] Listening on /tmp/mongodb-27017.sock
2019-09-30T08:51:57.684+0700 I  NETWORK  [initandlisten] Listening on 127.0.0.1
2019-09-30T08:51:57.684+0700 I  SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
2019-09-30T08:51:57.684+0700 I  NETWORK  [initandlisten] waiting for connections on port 27017
2019-09-30T08:56:56.140+0700 I  NETWORK  [listener] connection accepted from 127.0.0.1:59152 #1 (1 connection now open)
2019-09-30T08:56:56.142+0700 I  NETWORK  [conn1] received client metadata from 127.0.0.1:59152 conn1: { driver: { name: "nodejs-core", version: "3.2.7" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "5.0.0-29-generic" }, platform: "Node.js v10.2.0, LE", application: { name: "MongoDB Compass" } }
2019-09-30T08:56:56.143+0700 I  NETWORK  [conn1] end connection 127.0.0.1:59152 (0 connections now open)
=

И Compass, и MongoDB работают на одной машине, которая работает на Ubuntu 18.04

вот еще один терминал, в котором я запускаю команду 'mongo'

~$ mongo
MongoDB shell version v4.2.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c60d27ad-75d1-4a8c-83c8-6bb5482fd745") }
MongoDB server version: 4.2.0
Server has startup warnings: 
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] 
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-09-30T08:51:56.377+0700 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2019-09-30T08:51:57.672+0700 I  CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2019-09-30T08:51:57.672+0700 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()
---

> 

Спасибо за чтение,

1 Ответ

2 голосов
/ 30 сентября 2019

похоже, что я должен набрать 127.0.0.1 вместо того, чтобы сохранить значение по умолчанию, и все работает,

enter image description here

Обновление: после медленного соединения, когда яподключиться к моей базе данных на локальном хосте, я наконец выясняю, что произошло в этой ситуации,

Если мы разрешим имя хоста localhost, для соединения потребуется много времени (более 10 с), поэтому он устанавливает соединениевремя ожидания

Мы должны изменить localhost на 127.0.0.1, и он будет так же быстр, как ветер.

То же самое произошло, если вы позволили строке подключения в Node.js иметь значение 127.0.0.1 вместо localhost

до:

The server is running in port 6969 !
DB connection succesful! 10046.88992600143 ms

после:

The server is running in port 6969!
DB connection succesful! 43.67024099826813 ms

Более подробную информацию вы можете получить здесь: https://github.com/Automattic/mongoose/issues/6211

В документации Mongoose также сказано об этом:

Если на вашем компьютере не удается подключиться, попробуйте использовать 127.0.0.1 вместо localhost. https://mongoosejs.com/docs/connections.html

...