Исключить исключение с помощью Spring boot и репликации mongodb - PullRequest
0 голосов
/ 16 ноября 2018

env: - Spring boot 2.1.0 (с пружинными зависимостями по умолчанию).

  • MongoDB 3.4.9 (replicaset: 2 рабочих узла + 1 арбитр), 1 база данных с 2 пользователями (admin иконкретный пользователь для этой базы данных с ролью readWrite)

config свойств: data: mongodb: uri: mongodb: // $ USER: $ PWD @ HOST: 27017, HOST: 27018 / $ DATABASE

Один из моих объектов pojo использует Index (unique = true), я использую хранилище mongo для операции CRUD.

Итак, когда начинается весенняя загрузка, у меня есть этот стек:

com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'not authorized on DATABASE to execute command { createIndexes: "XXX a", indexes: [ { key: { oid: 1 }, name: "oid", ns: "XXXX", unique: true } ] }' on server XXXX:27017. The full response is { "ok" : 0.0, "errmsg" : "not authorized on XXX to execute command { createIndexes: \"XXXX\", indexes: [ { key: { oid: 1 }, name: \"oid\", ns: \"XXXXX\", unique: true } ] }", "code" : 13, "codeName" : "Unauthorized" }

Журнал из mongo.log:

2018-11-16T10:19:44.897+0100 I NETWORK [thread1] connection accepted from 127.0.0.1:46678 #169 (5 connections now open) 2018-11-16T10:19:44.938+0100 I NETWORK [conn169] received client metadata from 127.0.0.1:46678 conn169: { driver: { name: "mongo-java-driver", version: "3.8.2" }, os : { type: "Linux", name: "Linux", architecture: "amd64", version: "2.6.32-642.15.1.el6.x86_64" }, platform: "Java/Oracle Corporation/1.8.0_77-b03" } 2018-11-16T10:19:46.062+0100 I NETWORK [thread1] connection accepted from 127.0.0.1:46680 #170 (6 connections now open) 2018-11-16T10:19:46.062+0100 I NETWORK [conn170] received client metadata from 127.0.0.1:46680 conn170: { driver: { name: "mongo-java-driver", version: "3.8.2" }, os : { type: "Linux", name: "Linux", architecture: "amd64", version: "2.6.32-642.15.1.el6.x86_64" }, platform: "Java/Oracle Corporation/1.8.0_77-b03" } 2018-11-16T10:19:46.077+0100 I ACCESS [conn170] Unauthorized: not authorized on xxx to execute command { createIndexes: "xxxx", indexes: [ { key: { oid: 1 }, name: "oid", ns: "xxxxx", unique: true } ] } 2018-11-16T10:19:46.200+0100 I - [conn170] end connection 127.0.0.1:46680 (6 connections now open) 2018-11-16T10:19:46.200+0100 I - [conn169] end connection 127.0.0.1:46678 (5 connections now open)

Когда я использую оболочку mongo напрямую: mongo mongodb://$USER:$PWD@HOST:27017,HOST:27018/$DATABASE

Я могу выполнитьcreateIndexes без ошибок.

Журнал из mongo.log: 2018-11-16T10:21:16.448+0100 I NETWORK [thread1] connection accepted from 127.0.0.1:46682 #171 (5 connections now open) 2018-11-16T10:21:16.448+0100 I NETWORK [conn171] received client metadata from 127.0.0.1:46682 conn171: { driver: { name: "MongoDB Internal Client", version: "3.4.9" }, os: { type: "Linux", name: "Red Hat Enterprise Linux Server release 6.8 (Santiago)", architecture: "x86_64", version: "Kernel 2.6.32-642.15.1.el6.x86_64" } } 2018-11-16T10:21:16.485+0100 I ACCESS [conn171] Successfully authenticated as principal XX on XX 2018-11-16T10:21:16.486+0100 I NETWORK [thread1] connection accepted from XXX:59698 #172 (6 connections now open) 2018-11-16T10:21:16.486+0100 I NETWORK [conn172] received client metadata from XX:59698 conn172: { driver: { name: "MongoDB Internal Client", version: "3.4 .9" }, os: { type: "Linux", name: "Red Hat Enterprise Linux Server release 6.8 (Santiago)", architecture: "x86_64", version: "Kernel 2.6.32-642.15.1.el6.x86_64" } } 2018-11-16T10:21:16.522+0100 I ACCESS [conn172] Successfully authenticated as principal XX on XX 2018-11-16T10:21:16.523+0100 I NETWORK [thread1] connection accepted from XXX:59702 #173 (7 connections now open) 2018-11-16T10:21:16.524+0100 I NETWORK [conn173] received client metadata from XX:59702 conn173: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.9" }, os: { type: "Linux", name: "Red Hat Enterprise Linux Server release 6.8 (Santiago)", architecture: "x86_64", version: " Kernel 2.6.32-642.15.1.el6.x86_64" } } **2018-11-16T10:21:16.528+0100 I ACCESS [conn173] Successfully authenticated as principal XX on XX 2018-11-16T10:21:16.533+0100 I ACCESS [conn173] Successfully authenticated as principal XX on XX** 2018-11-16T10:21:16.538+0100 I ACCESS [conn173] Unauthorized: not authorized on admin to execute command { getLog: "startupWarnings" } 2018-11-16T10:21:16.541+0100 I ACCESS [conn173] Unauthorized: not authorized on admin to execute command { replSetGetStatus: 1.0, forShell: 1.0 } 2018-11-16T10:21:22.190+0100 I -[conn173] end connection XXX:59702 (7 connections now open) 2018-11-16T10:21:22.195+0100 I -[conn171] end connection 127.0.0.1:46682 (6 connections now open) 2018-11-16T10:21:22.195+0100 I -[conn172] end connection XXX:59698 (6 connections now open)

С mongoshell я "успешно аутентифицирован как основной" перед выполнением createIndexes.

Так почему этослучай с пружинной загрузкой?

У меня нет ошибки без репликации.

...