Unable to connect with mongodb from internal kubernetes cluster - mongodb

I tried setting up mongodb via bitnami stable/mongodb helm chart, the helm chart installation command is as follows -
helm install --name mongo --set mongodbRootPassword=mongo,mongodbUsername=mongo,mongodbPassword=mongo,mongodbDatabase=database stable/mongodb
after creation of it, I am looking to connect my applications by following format of connection string
mongodb://[user]:[password]#[service].[namespace].svc.cluster.local:27017/[db]?replicaSet=rs0&authSource=admin
But I am getting error for this -
failed to connect to server
[mongo.shift-resourcing.svc.cluster.local:27017] on first connect
[MongoNetworkError: Client network socket disconnected before secure
TLS connection was established]
The mongod.conf file is as follows -
# where and how to store data.
storage:
dbPath: /bitnami/mongodb/data/db
journal:
enabled: true
directoryPerDB: false
# where to write logging data.
systemLog:
destination: file
quiet: false
logAppend: true
logRotate: reopen
path: /opt/bitnami/mongodb/logs/mongodb.log
verbosity: 0
# network interfaces
net:
port: 27017
unixDomainSocket:
enabled: true
pathPrefix: /opt/bitnami/mongodb/tmp
ipv6: false
bindIpAll: true
# replica set options
#replication:
#replSetName: replicaset
#enableMajorityReadConcern: true
# process management options
processManagement:
fork: false
pidFilePath: /opt/bitnami/mongodb/tmp/mongodb.pid
# set parameter options
setParameter:
enableLocalhostAuthBypass: false
# security options
security:
authorization: enabled
#keyFile: replace_me

Related

MongoDB Sharding

I am new to mongodb.
I want to create a Shard Cluster with single Replica Set,In future, if I want to want to extend it will be easy.
Now, Have 4 Ubuntu machine, 1 will work as Router(mongos) and remaining 3 as used as replica set(Primary,Secondary,Secondary).
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /mnt/md0/data/mongodb/dbdata/
journal:
enabled: true
# engine:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /mnt/md0/data/mongodb/logs/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
#processManagement:
security:
keyFile: /opt/mongo/mongo-keyfile
#operationProfiling:
replication:
replSetName: rs0
sharding:
clusterRole: configsvr
## Enterprise-Only Options:
#auditLog:
#snmp:**strong text**
#mongos.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongos.log
# network interfaces
net:
port: 27017
#bindIp: 127.0.0.1,192.10.10.10
security:
keyFile: /opt/mongo/mongo-keyfile
sharding:
configDB: rs0/Primary_Rs:27017,Secondary1_Rs:27017,Secondary2_Rs:27017
When I am trying to add the Shard in mongos console, I am getting error
Please help me to resolve me the issue.
Thank you In Advance
See you have 2 sharding part in your conf file... and first one config clusterRole as configsvr => remove/comment this one, and retry

Cannot connect remotely to mongodb installed on AWS instance

I have installed and started mongodb on my RHEL AWS instance. Now I want to connect to the mongodb server from my local machine but am not able to do so.
I have made changes to the bind_ip parameter in the mongodb.conf file and also have added rules to the security group for the AWS instance to allow connections on port 27017 for any inbound request. Am I missing anything ??
MongoDB Version - 3.4.14
AWS Instance - RHEL
Thanks in advance !!!
Adding the mongod.conf file
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /home/ec2-user/AutoMaTics/setup/dbData
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
# bindIpAll: true
# bindIp: 127.0.0.1,13.127.31.137 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:

Mongodb restrict to given IP to localhost

I am trying to restrict the mongodb to local ip, it is not working.
Using MongoDb 3.2 version.
Below is the configuration file for the service, which is located in "C:\Program Files\MongoDB\Server\3.2\mongod.cfg"
systemLog:
destination: file
path: c:\data\mongo.log
quiet: false
logAppend: true
storage:
dbPath: C:\data\db
directoryPerDB: true
wiredTiger:
engineConfig:
cacheSizeGB: 2
directoryForIndexes: true
net:
port: 27017
bindIp: [127.0.0.0, 10.64.87.231]
replication:
oplogSizeMB: 500
replSetName: "mongoDbRepSet"
setParameter:
enableLocalhostAuthBypass: false
processManagement:
windowsService:
serviceName: "MongoDB"
displayName: "MongoDB 3.2 Standard"
description: "This is the service for MongoDB 3.2 Standard version"
I am using below command
mongod --config "C:\Program Files\MongoDB\Server\3.2\mongod.cfg" --install
I am restarting the mongo service after installing it with the configuraiton.
Strange thing is, when I open in RoboMongo and try to connect using 127.0.0.0 and 10.64.87.231 it is not working.
Also noticed that, it is connecting with ip addresses 127.0.0.1 to 127.0.0.255 (so many loopback ips?)
I also checked by assigning enableLocalhostAuthBypass: true but still not working.
What is wrong happening no idea. Please help me to restrict mongo service to give ip address.

Error while starting Mongod with config file option

I am not able to start mongod servers with replication using config file.
when issue the command
mongod --config /etc/mongod1.conf
throws an error-
Unrecognized option: replSet
Unrecognized option: oplogSizeMB
MongoDB Version: 3.0
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo/test
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27030
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
replication:
replSet: testrep
oplogSizeMB: 1024
#sharding:
## Enterprise-Only Options
please help me.
Just ident replSet and oplogSizeMB lines two spaces to the right. That's the thing with yaml

MongoDB replica set not starting

My mongodb replica set server is failing on start. followin is my config file:
# mongod.conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
# bindIp: 127.0.0.1
security:
authorization: enabled
keyFile: /home/gurbakhshish/dbKey/mongodb.key
replication:
replSetName: "nm-prd-dbs"
is this config correct. I dont have the issue if i comment security section of config file