连接问题升级和/或从3.4还原数据到3.6后与Mongodb

huangapple go评论67阅读模式
英文:

Connection issues to Mongodb after upgrade and/or data restore from 3.4 to 3.6

问题

我使用 Docker。

我正在尝试更新我的本地机器上的 MongoDB 版本。我注意到,当我将图像从版本 3.4 更新到版本 3.6(在 docker-compose.yml 中),尽管 MongoDB 图像已启动,但没有客户端(我的应用程序和 Studio 3T)能够连接到新图像(出现连接超时)。

我尝试了另一种方法,即创建两个新的干净容器(一个版本为 3.4,另一个版本为 3.6,两者具有相同的凭据),然后从 3.4 获取转储并将其复制到 3.6 容器中,进行还原操作。还原操作成功,但当我尝试使用 Studio 3T 连接到 3.6 数据库时,再次出现连接问题。

以下是我的 docker-compose.yml 文件:

version: '3.9'
services:
  mongo:
    image: mongo:3.4
    ports:
      - 27020:27017
    volumes:
      - mongo-test:/data/db
  mongo-new:
    image: mongo:3.6
    ports:
      - 27021:27017
    volumes:
      - mongo-test-new:/data/db
volumes:
  mongo-test:
  mongo-test-new:

我的转储文件只包含一个小文档。

我感到相当困惑。为什么这么简单的事情竟然不可能呢?

EDIT 1: 这是错误日志:

连接失败。

服务器 [localhost:27021](类型:UNKNOWN)
|_/ 连接错误(MongoSocketReadException):过早到达流的末尾

详细信息:
在等待连接时,超时为5000毫秒。集群状态的客户端视图为 {type=UNKNOWN, servers=[{address=localhost:27021, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]}

EDIT 2: 添加 Docker 日志

test-mongo-new-1  | 2023-04-17T02:58:54.545+0000 I CONTROL  [initandlisten] MongoDB starting : pid=7 port=27017 dbpath=/data/db 64-bit host=f7bff9e5afa8
(更多日志内容)
英文:

I am using docker.

I am trying to update the mongo version for my local machine. I noticed that when I update the image from version (from 3.4 to 3.6 in docker-compose.yml) then although the mongo image starts, no clients (my app and studio3T) can connect to the new image (get connection timeouts).

Another method I tried is creating two new clean containers (one version 3.4 and the other 3.6 with both having same credentials) and getting a dump from 3.4 and copying it to the 3.6 container and doing a restore. The restore worked however when I tried to connect to the 3.6 database using studio3T, I got a connection issue again.

Here's my docker-compose.yml file:

version: '3.9'
services:
  mongo:
    image: mongo:3.4
    ports:
      - 27020:27017
    volumes:
      - mongo-test:/data/db
  mongo-new:
    image: mongo:3.6
    ports:
      - 27021:27017
    volumes:
      - mongo-test-new:/data/db
volumes:
  mongo-test:
  mongo-test-new:

My dump contained one small document.

I am quite lost. How come something so simple isn’t possible?

EDIT 1: Here's the error log:

Connection failed.

SERVER [localhost:27021] (Type: UNKNOWN) 
|_/ Connection error (MongoSocketReadException): Prematurely reached end of stream

Details:
Timed out after 5000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27021, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]

EDIT 2: Adding docker logs

test-mongo-new-1  | 2023-04-17T02:58:54.545+0000 I CONTROL  [initandlisten] MongoDB starting : pid=7 port=27017 dbpath=/data/db 64-bit host=f7bff9e5afa8
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] db version v3.6.23
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] git version: d352e6a4764659e0d0350ce77279de3c1f243e5c
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] allocator: tcmalloc
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] modules: none
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] build environment:
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten]     distarch: x86_64
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I CONTROL  [initandlisten]     target_arch: x86_64
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I CONTROL  [initandlisten] options: {}
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 W -        [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3417M,cache_overflow=(file_max=0M),session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),compatibility=(release="3.0",require_max="3.0"),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
test-mongo-new-1  | 2023-04-17T02:58:55.610+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:610320][7:0x7f24b4718a40], txn-recover: Main recovery loop: starting at 3/4480
test-mongo-new-1  | 2023-04-17T02:58:55.611+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:611263][7:0x7f24b4718a40], txn-recover: Recovering log 3 through 4
test-mongo-new-1  | 2023-04-17T02:58:55.696+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:696453][7:0x7f24b4718a40], txn-recover: Recovering log 4 through 4
test-mongo-new-1  | 2023-04-17T02:58:55.744+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:744249][7:0x7f24b4718a40], txn-recover: Set global recovery timestamp: 0
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:55.772+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
test-mongo-new-1  | 2023-04-17T02:58:55.773+0000 I NETWORK  [initandlisten] listening via socket bound to 127.0.0.1
test-mongo-new-1  | 2023-04-17T02:58:55.773+0000 I NETWORK  [initandlisten] listening via socket bound to /tmp/mongodb-27017.sock
test-mongo-new-1  | 2023-04-17T02:58:55.773+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
test-mongo-new-1  | 2023-04-17T02:58:56.011+0000 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK

答案1

得分: 2

线索在容器日志中...

警告:此服务器绑定到本地主机。
       远程系统将无法连接到此服务器。

详见MongoDB 3.6中的兼容性更改

当仅绑定到本地主机时,这些MongoDB 3.6二进制文件只能接受来自在同一台机器上运行的客户端(包括mongo shell、副本集和分片集群中的其他成员)的连接。无法从远程客户端连接到仅绑定到本地主机的二进制文件。

不幸的是,这意味着默认情况下你无法从容器外部连接。

最简单的解决方法是通过添加command后缀将其绑定到所有可用的网络接口

mongo-new:
  image: mongo:3.6
  ports:
    - 27021:27017
  volumes:
    - mongo-test-new:/data/db
  command: --bind_ip_all

详见无配置文件自定义配置

英文:

The clue is in the container logs...

> none
> WARNING: This server is bound to localhost.
> Remote systems will be unable to connect to this server.
>

See Compatibility Changes in MongoDB 3.6

> When bound only to the localhost, these MongoDB 3.6 binaries can only accept connections from clients (including the mongo shell, other members in your deployment for replica sets and sharded clusters) that are running on the same machine. Remote clients cannot connect to the binaries bound only to localhost.

Unfortunately, this means you won't be able to connect from outside the container by default.

The simplest fix is to bind on all available network interfaces by adding a command suffix

mongo-new:
  image: mongo:3.6
  ports:
    - 27021:27017
  volumes:
    - mongo-test-new:/data/db
  command: --bind_ip_all

See Customize configuration without configuration file

huangapple
  • 本文由 发表于 2023年4月17日 10:36:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定