I am trying to connect the forum docker with MongoDB cluster.
The configurations are -
environment:
SEARCH_SERVER: "http://elasticsearch:9200"
MONGODB_USERNAME: "mongouser"
MONGODB_PASSWORD: "password"
MONGODB_HOST: "mongo_primary_host_url"
MONGODB_PORT: 27017
MONGODB_DATABASE: "cs_comments_service"
MONGOID_USE_SSL: true
MONGOID_SSL_VERIFY: true
MONGOID_READ_MODE: "primary"
MONGOID_AUTH_MECH: ":mongodb_x509"
MONGOID_SSL_CA_CERT: "My_certificate_path_in_the_forum_docker"
MONGOID_TIMEOUT: 10
This is the error i get in the forum.
tutor_local-forum-1 | Waiting for mongodb/elasticsearch…
tutor_local-forum-1 | 2022/06/13 08:47:46 Waiting for: tcp://mongo_primary_host_url:27017
tutor_local-forum-1 | 2022/06/13 08:47:46 Waiting for: http://elasticsearch:9200/
tutor_local-forum-1 | 2022/06/13 08:47:46 Connected to tcp://mongo_primary_host_url:27017
tutor_local-forum-1 | 2022/06/13 08:47:46 Received 200 from http://elasticsearch:9200/
tutor_local-forum-1 | W, [2022-06-13T08:47:47.948442 #17] WARN – : Overwriting existing field _id in class User.
tutor_local-forum-1 | W, [2022-06-13T08:47:47.977085 #17] WARN – : MONGODB | Unsupported client option ‘max_retries’. It will be ignored.
tutor_local-forum-1 | W, [2022-06-13T08:47:47.977157 #17] WARN – : MONGODB | Unsupported client option ‘retry_interval’. It will be ignored.
tutor_local-forum-1 | W, [2022-06-13T08:47:47.977173 #17] WARN – : MONGODB | Unsupported client option ‘timeout’. It will be ignored.
tutor_local-forum-1 | /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/mongo-2.5.3/lib/mongo/server_selector/selectable.rb:110:in select_server': No server is available matching preference: #<Mongo::ServerSelector::Primary:0x47181947531780 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015 (Mongo::Error::NoServerAvailable) tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/mongo-2.5.3/lib/mongo/collection/view/iterable.rb:41:in block in each’
tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/mongo-2.5.3/lib/mongo/retryable.rb:44:in read_with_retry' tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/mongo-2.5.3/lib/mongo/collection/view/iterable.rb:40:in each’
tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/mongoid-7.0.5/lib/mongoid/query_cache.rb:227:in each' tutor_local-forum-1 | from /app/cs_comments_service/app.rb:175:in map’
tutor_local-forum-1 | from /app/cs_comments_service/app.rb:175:in <top (required)>' tutor_local-forum-1 | from config/unicorn_tcp.rb:4:in require’
tutor_local-forum-1 | from config/unicorn_tcp.rb:4:in reload' tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/lib/unicorn/configurator.rb:84:in instance_eval’
tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/lib/unicorn/configurator.rb:84:in reload' tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/lib/unicorn/configurator.rb:77:in initialize’
tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/lib/unicorn/http_server.rb:77:in new' tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/lib/unicorn/http_server.rb:77:in initialize’
tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/bin/unicorn:126:in new' tutor_local-forum-1 | from /app/cs_comments_service/vendor/bundle/ruby/2.5.0/gems/unicorn-5.3.1/bin/unicorn:126:in <top (required)>’
tutor_local-forum-1 | from ./bin/unicorn:16:in load' tutor_local-forum-1 | from ./bin/unicorn:16:in ’
Can follow the previous conversation here.
To create a MongoDB cluster
First we need to enable replSet.
mongod --port 27017 --replSet rs0
or you can add it in the configuration file /etc/mongod.conf
.
replication:
replSetName: rs0
Make sure the three nodes are having the same replSetName.
Follow this link to setup replset.
Enable authentication and ssl/tls certificated.
security:
authorization: enabled
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
Follow these links to setup authentication and ssl/tls.
https://hevodata.com/learn/mongodb-configuration-file/
https://www.mongodb.com/docs/manual/tutorial/configure-ssl/
Make sure to have all the 3 nodes to have the security, authentication and ssl/tls enabled.
After the nodes are ready to connect in replset state.
Connect the nodes with each other.
To connect all the 3 nodes with each other. Login to one of the Mongodb shell.
rs.initiate()
rs.add('ip1:port1')
rs.add('ip2:port2')
rs.add('ip3:port3')
rs.status()
Follow this to connect all the three nodes.
Note - I am working on a completly cloud based cluster. I do not need to manually setup everything. But for development purposes we need to do them manually.