2

I'm trying to install and configure rocketchat and mongodb in separatelly hosts. One for application and another one for mongodb. I follown this tutorial https://rocket.chat/docs/installation/manual-installation/ubuntu/

and I did all steps for each part separately (mongodb and rocketchat)

when I ran the main.js command:

MONGO_URL=mongodb://<mongodb-ip-host>:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://<mongodb-ip-host>:27017/local?replicaSet=rs01 ROOT_URL=http://0.0.0.0:3000 PORT=3000 node /var/Rocket.Chat/main.js

I got this error below:

                        throw(ex);
                        ^

MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
  name: 'MongoNetworkError',
  errorLabels: [Array],
  [Symbol(mongoErrorContextSymbol)]: {}
}]
    at Pool.<anonymous> (/var/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:311:20)
    at /var/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:557:14
    at /var/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:39:11
    at callback (/var/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:261:5)
    at Socket.<anonymous> (/var/Rocket.Chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connect.js:286:7)
    at Object.onceWrapper (events.js:418:26)
    at Socket.emit (events.js:311:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {}
}

PS.: I set the RocketChat on /var/Rocket.Chat folder

I'd like to understand why some part of application are trying to connect in a mongodb locally : 127.0.0.1:27017

Celso Agra
  • 1,389
  • 2
  • 15
  • 37
  • FYI: more info about this issue, in the following link: https://forums.rocket.chat/t/how-configure-rocket-chat-and-mongodb-in-separatelly-hosts/6285/5 – Celso Agra Oct 27 '20 at 18:22

1 Answers1

0

I think the issue is in the replica set in your mongodb server. It is wrongly configured with the 127.0.0.1 IP address for the mongodb server.

You can get this in the shell of the mongodb server. mongo or mongosh depending on your version of mongodb. I am using mongo here but you might need to use mongosh

$ mongo
> rs.conf()

the result to the mongo js rs.conf() function call should be something similar to the following:

{
        "_id" : "rs01",
        "version" : 2,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "127.0.0.1:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "catchUpTimeoutMillis" : -1,
                "catchUpTakeoverDelayMillis" : 30000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("<<masked>>")
        }
}

Notice that host for the replica set is configured to 127.0.0.1:27017

This can be fixed by executing the following commands in the mongo shell of on the mongo server where the replica set is located.

> cfg = rs.conf()
> cfg.members[0].host = "mongodb-server-ip:27017"
> rs.reconfig(cfg)

you can read more on this here:

https://github.com/RocketChat/Rocket.Chat/issues/26519

Ouss
  • 2,912
  • 2
  • 25
  • 45