Reputation: 23
My Java Application is able to connect to two of the secondary instances of the replica set but not to the primary instance. error log below
org.springframework.dao.DataAccessResourceFailureException: Timed out after 90000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=mongo2:27019, type=REPLICA_SET_SECONDARY, roundTripTime=3.5 ms, state=CONNECTED}, {address=mongo3:27020, type=REPLICA_SET_SECONDARY, roundTripTime=5.5 ms, state=CONNECTED}, {address=mongo1:27018, type=UNKNOWN, state=CONNECTING}]
I am running the replicaSet using colima docker instance and following are the lis to commands I followed,
# pull the official mongo docker container
docker pull mongo:4.2
# create network
docker network create my-mongo-cluster
# create mongos
docker run -d --net my-mongo-cluster -p 27018:27018 --name mongo1 mongo:4.2 mongod --replSet rs0 --port 27018
docker run -d --net my-mongo-cluster -p 27019:27019 --name mongo2 mongo:4.2 mongod --replSet rs0 --port 27019
docker run -d --net my-mongo-cluster -p 27020:27020 --name mongo3 mongo:4.2 mongod --replSet rs0 --port 27020
# add hosts in /etc/hosts
sudo vim /etc/hosts
# add the below line
127.0.0.1 mongo1 mongo2 mongo3
# setup replica set
docker exec -it mongo1 mongo -port 27018
config={"_id":"rs0","members":[{"_id":0,"host":"mongo1:27018"},{"_id":1,"host":"mongo2:27019"},{"_id":2,"host":"mongo3:27020"}]}
rs.initiate(config)
Upvotes: 0
Views: 23