8

我使用 MongoDB Community Kubernetes Operator 建立了一个 Minikube-Cluster。要查看内容,我想设置一个连接到 Mongo-Cluster/ReplicaSet 的 mongo-express 实例。但是,如果我应用部署,容器总是会失败:

mongo-express_1  | Waiting for localhost:27017...
mongo-express_1  | Welcome to mongo-express
mongo-express_1  | ------------------------
mongo-express_1  | 
mongo-express_1  | 
mongo-express_1  | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1  | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1  | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongo-express_1  | Database connected
mongo-express_1  | Admin Database connected
mongo-express_1  | Error [MongoError]: Authentication failed.
mongo-express_1  |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1  |     at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1  |     at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1  |     at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1  |     at Socket.emit (events.js:314:20)
mongo-express_1  |     at addChunk (_stream_readable.js:297:12)
mongo-express_1  |     at readableAddChunk (_stream_readable.js:272:9)
mongo-express_1  |     at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express_1  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
mongo-express_1  |   operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1  |   ok: 0,
mongo-express_1  |   errmsg: 'Authentication failed.',
mongo-express_1  |   code: 18,
mongo-express_1  |   codeName: 'AuthenticationFailed',
mongo-express_1  |   '$clusterTime': {
mongo-express_1  |     clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1  |     signature: { hash: [Binary], keyId: [Long] }
mongo-express_1  |   }
mongo-express_1  | }
mongo-express_1  | unable to list databases
mongo-express_1  | Error [MongoError]: command listDatabases requires authentication
mongo-express_1  |     at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1  |     at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1  |     at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1  |     at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1  |     at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1  |     at Socket.emit (events.js:314:20)
mongo-express_1  |     at addChunk (_stream_readable.js:297:12)
mongo-express_1  |     at readableAddChunk (_stream_readable.js:272:9)
mongo-express_1  |     at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express_1  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
mongo-express_1  |   operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1  |   ok: 0,
mongo-express_1  |   errmsg: 'command listDatabases requires authentication',
mongo-express_1  |   code: 13,
mongo-express_1  |   codeName: 'Unauthorized',
mongo-express_1  |   '$clusterTime': {
mongo-express_1  |     clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1  |     signature: { hash: [Binary], keyId: [Long] }
mongo-express_1  |   }
mongo-express_1  | }

为了便于测试,我使用 docker-compose 启动 mango-express 并创建了一个端口转发来访问集群。

版本:

  • MongoDB 集群:尝试了 4.2.6 和 4.4.3
  • 蒙戈快递:0.54.0

这里是我用于 MongoDB 集群创建的部署/服务:

---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: example-mongodb
spec:
  members: 3
  type: ReplicaSet
  version: "4.4.3"
  security:
    authentication:
      modes: ["SCRAM"]
  users:
    - name: mongoadmin
      db: admin
      passwordSecretRef: # a reference to the secret that will be used to generate the user's password
        name: mongoadmin-password
      roles:
        - name: root
          db: admin
      scramCredentialsSecretName: my-scram

# the user credentials will be generated from this secret
# once the credentials are generated, this secret is no longer required
---
apiVersion: v1
kind: Secret
metadata:
  name: mongoadmin-password
type: Opaque
stringData:
  password: mongoadmin                                 

这里是我用于 mongo-express 的 compose-file:

version: '3.8'

services:
  mongo-express:
    image: mongo-express
    restart: on-failure
    ports:
      - 8081:8081
    network_mode: host
    environment:
      ME_CONFIG_MONGODB_SERVER: localhost
      ME_CONFIG_MONGODB_ADMINUSERNAME: mongoadmin
      ME_CONFIG_MONGODB_ADMINPASSWORD: mongoadmin

问题是,如果我通过 docker-compose 使用 mongo-express 设置一个 mongo (4.4.3) 容器,一切正常......

有人知道发生了什么吗?

4

1 回答 1

0

我已经从 mongo-express https://github.com/mongo-express/mongo-express/tree/v1.0.0-alpha.1的 alpha 版本构建了 docker 映像

这是图像uncl3mar1k/mongo-express:v1.0.0-alpha.1

它似乎与身份验证配合得很好,但我注意到它在分页方面存在问题。(如果您有很多收藏并尝试浏览页面,您会注意到有关收藏的数据没有更改)

更新:有一个更新的版本v1.0.0-alpha.3看起来所有问题都在这里修复了。请看一下新图像:staslb/mongo-express:v1.0.0-alpha.3

于 2021-06-04T08:04:22.467 回答