0

I am using the docker-compose example from

https://github.com/bitnami/containers/blob/main/bitnami/mongodb/README.md#setting-up-replication

to create a local replication in order to use Transactions in spring boot. I expect this to work out of the box

version: '2'

services:
  mongodb-primary:
    image: 'bitnami/mongodb:latest'
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongodb-primary
      - MONGODB_REPLICA_SET_MODE=primary
      - MONGODB_ROOT_PASSWORD=password123
      - MONGODB_REPLICA_SET_KEY=replicasetkey123

    volumes:
      - 'mongodb_master_data:/bitnami'

  mongodb-secondary:
    image: 'bitnami/mongodb:latest'
    depends_on:
      - mongodb-primary
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
      - MONGODB_INITIAL_PRIMARY_HOST=mongodb-primary
      - MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
      - MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=password123
      - MONGODB_REPLICA_SET_KEY=replicasetkey123

  mongodb-arbiter:
    image: 'bitnami/mongodb:latest'
    depends_on:
      - mongodb-primary
    environment:
      - MONGODB_REPLICA_SET_MODE=arbiter
      - MONGODB_INITIAL_PRIMARY_HOST=mongodb-primary
      - MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
      - MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=password123
      - MONGODB_REPLICA_SET_KEY=replicasetkey123

volumes:
  mongodb_master_data:
      driver: local

unfortunatly I get following errors in logs by primary

"id":4939300, "ctx":"monitoring-keys-for-HMAC","msg":"Failed to refresh key cache","attr":{"error":"NotYetInitialized: Cannot use non-local read concern until replica set is finished initializing.","nextWakeupMillis":5400}}

"ctx":"conn34","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"root","authenticationDatabase":"admin","remote":"10.89.1.52:54010","extraInfo":{},"error":"AuthenticationFailed: SCRAM authentication failed, storedKey mismatch"}}

and by arbiter

MongoServerError: Authentication failed.

I started it from my local machine with "docker-compose up".

DCO
  • 1,222
  • 12
  • 24

1 Answers1

0

So I read the link you provide and I read its Readme file to understand what you could've missed while trying to run the replica-set successfully.

When i created it myself it was not on docker i had to create private Auth keys myself and put them into each VM so the nodes could communicate after authentication.

In your case as i read the documentation it states Generating self-signed certificates im not really sure you did that as you only mentioned the docker-compose file.I believe for the containers to work with each other it requires them to generate certificates for each node ,in that it also requires them to sign them with private key that it asks to generate initially.

I assume this because when we created replica-set without docker we did create keys then too and it took alot of my time because when i first did it , i had not put the same keys on every virtual machine.In the configuration i attached as well you can see we add that key path as a security.reference

But if you did all that and it still didn't work then im attaching a possible duplicate as well there are people who have different variation of ans there you can check that out..SCRAM-SHA-1 authentication failed, storedKey mismatch

Skipper pk
  • 91
  • 1
  • 4