I will share all nodes configuration:
shard nodes at </etc/mongod.conf> :
net:
port: 27017
bindIp: 192.168.11.153
security:
authorization: enabled
keyFile: /var/mongo/keyfile
replication:
replSetName: "shard3"
sharding:
clusterRole: shardsvr
config node at </etc/mongod.conf> :
net:
port: 27019
bindIp: 192.168.11.151
security:
authorization: enabled
keyFile: /var/mongo/keyfile
replication:
replSetName: configReplSet
sharding:
clusterRole: "configsvr"
and this is mongos config at </etc/mongos.conf> :
net:
port: 27017
bindIp: 192.168.11.149
#security:
# authorization: enabled
# keyFile: /var/mongo/keyfile
sharding:
configDB: configReplSet/192.168.11.151:27019
If I comment security option in all nodes, I can connect to mongos from every node in my local network using “mongo 192.168.11.149:27017”, but when I uncomment security option and try to connect to query-router, i get this error
MongoDB shell version v5.0.6
connecting to: mongodb://192.168.11.149:27017/test?compressors=disabled&gssapiServiceName=mongodb
Error: couldn’t connect to server 192.168.11.149:27017, connection attempt failed: SocketException: Error connecting to 192.168.11.149:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:372:17
@(connect):2:6
exception: connect failed
exiting with code 1
when I uncomment security option in mongos.conf and restart service using "sudo systemctl restart mongos.service ", I face this status code:
● mongos.service - Mongo Cluster Router
Loaded: loaded (/lib/systemd/system/mongos.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2022-03-14 13:56:28 UTC; 8s ago
Process: 3225231 ExecStart=/usr/bin/mongos --config /etc/mongos.conf (code=exited, status=2)
Main PID: 3225231 (code=exited, status=2)Mar 14 13:56:28 mongo-query-router systemd[1]: Started Mongo Cluster Router.
Mar 14 13:56:28 mongo-query-router mongos[3225231]: Unrecognized option: security.authorization
Mar 14 13:56:28 mongo-query-router mongos[3225231]: try ‘/usr/bin/mongos --help’ for more information
Mar 14 13:56:28 mongo-query-router systemd[1]: mongos.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Mar 14 13:56:28 mongo-query-router systemd[1]: mongos.service: Failed with result ‘exit-code’.