Remote connection with mongodb - mongodb

I have gone through the the official documentation to install mongodb in linux environment in amazon.
after installation i did
[root#ip-172-31-20-51 etc]# service mongod restart
dirname: missing operand
Try 'dirname --help' for more information.
Stopping mongod: [ OK ]
Starting mongod: [FAILED]
the start is failed but when i write only mongod is says
[root#ip-172-31-20-51 etc]# mongod
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] MongoDB starting : pid=16633 port=27017 dbpath=/data/db 64-bit host=ip-172-31-20-59
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] db version v3.2.9
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-09-21T05:23:57.703+0000 I CONTROL [initandlisten] modules: none
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] build environment:
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] distmod: amazon
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] distarch: x86_64
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-09-21T05:23:57.704+0000 I CONTROL [initandlisten] options: {}
2016-09-21T05:23:57.726+0000 I - [initandlisten] Detected data files in /data/db created by the 'mmapv1' storage engine, so setting the active storage engine to 'mmapv1'.
2016-09-21T05:23:57.735+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
2016-09-21T05:23:57.735+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2016-09-21T05:23:57.899+0000 I JOURNAL [durability] Durability thread started
2016-09-21T05:23:57.899+0000 I JOURNAL [journal writer] Journal writer thread started
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten]
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten]
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten]
2016-09-21T05:23:57.907+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-09-21T05:23:57.907+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2016-09-21T05:23:57.907+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
and then on another console i started mongo
[root#ip-172-31-20-59 etc]# mongo
MongoDB shell version: 3.2.9
connecting to: test
Server has startup warnings:
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten]
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten]
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-09-21T05:23:57.905+0000 I CONTROL [initandlisten]
>
and in mongod console it accepted the connnection
2016-09-21T05:25:09.684+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:49068 #1 (1 connection now open)
Now i have a couple of questions,
1.i am not able to understand is my mongo is working or not? (beacause starting mongod always failed but on typing only mongod is working)
2.i can not connect to remote mongo server through my robomongo it says "cannot connect to mongodb"
my mongo.config file -- >
# 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
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
bindIp: 0.0.0.0,10.0.0.1,127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

Your bindIp setting is a bit weird. Why the comma separated list? Just use 0.0.0.0.
After that, open port 27017 in your Security Group and you will be able to connect.

To answer your questions:
If you can connect using the mongo shell, then the server is running. Otherwise you'll see an error like Connection refused and exception: connect failed
By default, AWS firewall is very restrictive. Please check if you allow incoming connection to port 27017 from any host. There will be a warning saying you are opening the port to everyone, but it is necessary to allow connections to the database.

Related

WSL2 ubuntu Mongod Keeps changing ports whenever I start a local server up

I followed this link to setup mongodb on ubuntu wsl, and it kind of worked
https://github.com/michaeltreat/Windows-Subsystem-For-Linux-Setup-Guide/blob/master/readmes/installs/MongoDB.md
However, whenever I use the command sudo mongod --dbpath ~/data/db
It will open a Mongod server locally and display this
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] allocator: tcmalloc
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] modules: none
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] build environment:
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] distmod: ubuntu1604
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] distarch: x86_64
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] target_arch: x86_64
2020-05-07T14:50:56.880-0700 I CONTROL [initandlisten] options: { storage: { dbPath: "/home/misterjoe/data/db" } }
2020-05-07T14:50:56.880-0700 I - [initandlisten] Detected data files in /home/misterjoe/data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2020-05-07T14:50:56.880-0700 I STORAGE [initandlisten]
2020-05-07T14:50:56.880-0700 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-05-07T14:50:56.880-0700 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-05-07T14:50:56.880-0700 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=5840M,cache_overflow=(file_max=0M),session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),compatibility=(release="3.0",require_max="3.0"),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2020-05-07T14:50:57.360-0700 I STORAGE [initandlisten] WiredTiger message [1588888257:360834][18606:0x7f3480c394c0], txn-recover: Main recovery loop: starting at 6/13440
2020-05-07T14:50:57.409-0700 I STORAGE [initandlisten] WiredTiger message [1588888257:409482][18606:0x7f3480c394c0], txn-recover: Recovering log 6 through 7
2020-05-07T14:50:57.441-0700 I STORAGE [initandlisten] WiredTiger message [1588888257:441849][18606:0x7f3480c394c0], txn-recover: Recovering log 7 through 7
2020-05-07T14:50:57.467-0700 I STORAGE [initandlisten] WiredTiger message [1588888257:467231][18606:0x7f3480c394c0], txn-recover: Set global recovery timestamp: 0
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten]
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten]
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten]
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten]
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-05-07T14:50:57.486-0700 I CONTROL [initandlisten]
2020-05-07T14:50:57.488-0700 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/home/misterjoe/data/db/diagnostic.data'
2020-05-07T14:50:57.489-0700 I NETWORK [initandlisten] listening via socket bound to 127.0.0.1
2020-05-07T14:50:57.489-0700 I NETWORK [initandlisten] listening via socket bound to /tmp/mongodb-27017.sock
2020-05-07T14:50:57.489-0700 I NETWORK [initandlisten] waiting for connections on port 27017
Then if I start an application with a mongo database I get this
2020-05-07T14:53:19.392-0700 I NETWORK [listener] connection accepted from 127.0.0.1:60332 #1 (1 connection now open)
2020-05-07T14:53:19.395-0700 I NETWORK [conn1] received client metadata from 127.0.0.1:60332 conn1: { driver: { name: "nodejs", version: "3.5.5" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "4.19.84-microsoft-standard" }, platform: "'Node.js v13.10.1, LE (legacy)" }
I am trying to keep it on the same port so I can use mongodb compass and have it go to a certain db of my choice. Like RedditClone or todoApp database. However if I type in that IP into it doesn't exist, and the only way I can see anything from this database is by using a .find({}) in javascript. Please help :(
What is your actual problem? Everything in your logs shows that you have set up a server and are able to successfully connect to it (from your local machine). It doesn't look like Compass provides a way to set a default database, like the mongo shell command line. If you can browse the available databases or create a new database in Compass, then you have connected to the server.
2020-05-07T14:50:57.489-0700 I NETWORK [initandlisten] waiting for connections on port 27017
This line indicates your started the server and it is listening on localhost:27017
2020-05-07T14:53:19.392-0700 I NETWORK [listener] connection accepted from 127.0.0.1:60332 #1 (1 connection now open)
This line indicates a new client successfully opened a connection to this server (in your case hosted on port 27017) from port 60332.
If you run the mongo shell, you will see another connection get opened to the server in the logs. Each client (in your case it sounds like Compass) will run on a dynamic port so you can run multiple clients at the same time. You don't connect to the client ports, just the server. The client port is telling the server what port to return results to.
The database specified in the URL is the authentication database, and since you don't have authentication enabled, it is ignored. To quote the docs:
mongodb://[username:password#]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
...
defaultauthdb
Optional. The authentication database to use if the connection string includes username:password# authentication credentials but the authSource option is unspecified.
If both authSource and defaultauthdb are unspecified, the client will attempt to authenticate the specified user to the admin database.

How to make mongodb listen on specific IP in Azure VM with Ubuntu 18.04?

I got the MongoDB (4.0.10) running on Azure VM with Ubuntu 18.04 using default localhost. Now, I want to add my IP address to bindIp in /etc/mongod.conf so that I can access the db from my machine. Based on document (also from this example), I just need to append it to bindIp line after a comma.
net:
port: 27017
bindIp: 127.0.0.1,70.123.39.234
ipv6: true
(Note, I added ipv6 based on my reading of the document, but it doesn't seem to have any effect).
However, it doesn't work for me because service fails to start. I got something like this:
$ sudo service mongod restart
$ sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-06-10 15:59:35 UTC; 2s ago
Docs: https://docs.mongodb.org/manual
Process: 8140 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=48)
Main PID: 8140 (code=exited, status=48)
Jun 10 15:59:35 mllinux systemd[1]: Started MongoDB Database Server.
Jun 10 15:59:35 mllinux systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Jun 10 15:59:35 mllinux systemd[1]: mongod.service: Failed with result 'exit-code'.
I tried many ways like
bindIp: 127.0.0.1, 70.123.39.234
or
bindIp: "127.0.0.1,70.123.39.234"
or
bindIp: "127.0.0.1, 70.123.39.234"
I got the same error.
However if I use space instead of comma like
bindIp: 127.0.0.1 70.123.39.234
or
bindIp: "127.0.0.1 70.123.39.234"
Service seems to start ok because
$ sudo service mongod restart
$ sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-06-10 16:37:39 UTC; 3s ago
Docs: https://docs.mongodb.org/manual
Main PID: 14629 (mongod)
CGroup: /system.slice/mongod.service
└─14629 /usr/bin/mongod --auth --config /etc/mongod.conf
Jun 10 16:37:39 mllinux systemd[1]: Started MongoDB Database Server.
However, I still cannot connect to it from my laptop.
For testing, if I set
bindIp: 0.0.0.0
or
bindIpAll: true
Then, I can connect to it from my laptop.
What did I do wrong?
UPDATE: Appending db log
2019-06-10T02:52:27.682+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2019-06-10T02:52:27.684+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] MongoDB starting : pid=3757 port=27017 dbpath=/var/lib/mongodb 64-bit host=mllinux
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] db version v4.0.10
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] modules: none
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] build environment:
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] distarch: x86_64
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,70.123.39.234", port: 27017 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, security: { authorizatio$2019-06-10T02:52:27.697+0000 E STORAGE [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] now exiting
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] shutting down with code:48
2019-06-10T02:53:53.313+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2019-06-10T02:53:53.315+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] MongoDB starting : pid=3934 port=27017 dbpath=/var/lib/mongodb 64-bit host=mllinux
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] db version v4.0.10
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] modules: none
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] build environment:
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] distarch: x86_64
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1 70.123.39.234", port: 27017 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, security: { authorizatio$2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten]
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1448M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=jou$2019-06-10T02:53:54.146+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:146511][3934:0x7fe345319a40], txn-recover: Main recovery loop: starting at 2/6656 to 3/256
2019-06-10T02:53:54.249+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:249632][3934:0x7fe345319a40], txn-recover: Recovering log 2 through 3
2019-06-10T02:53:54.317+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:317186][3934:0x7fe345319a40], txn-recover: Recovering log 3 through 3
2019-06-10T02:53:54.366+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:366900][3934:0x7fe345319a40], txn-recover: Set global recovery timestamp: 0
2019-06-10T02:53:54.485+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten]
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten]
2019-06-10T02:53:54.515+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2019-06-10T02:53:54.517+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2019-06-10T02:56:27.392+0000 I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2019-06-10T02:56:27.392+0000 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...
2019-06-10T02:56:27.392+0000 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2019-06-10T02:56:27.395+0000 I CONTROL [signalProcessingThread] Shutting down free monitoring
2019-06-10T02:56:27.395+0000 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture
2019-06-10T02:56:27.397+0000 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down
2019-06-10T02:56:27.397+0000 I STORAGE [signalProcessingThread] Shutting down session sweeper thread
2019-06-10T02:56:27.397+0000 I STORAGE [signalProcessingThread] Finished shutting down session sweeper thread
2019-06-10T02:56:27.558+0000 I STORAGE [signalProcessingThread] shutdown: removing fs lock...
2019-06-10T02:56:27.558+0000 I CONTROL [signalProcessingThread] now exiting
2019-06-10T02:56:27.558+0000 I CONTROL [signalProcessingThread] shutting down with code:0
You cannot use bindip to limit access from the outside to the mongodb. bindip selects the desired server listen IPs, not the client IPs.
If you only want to be able to connect to the server from your IP address, you should use the Network Security Group feature of Azure. It is more secure than handling it via the software installed on the VM, since traffic does not even reach the VM.
For your issue, you should know what does the three IPs mean and then you will know what you need to do as you wish.
First one: 127.0.0.1
This IP is just for the test inside the machine, it cannot access outside. It's just a loop IP.
Second one: 0.0.0.0
Then this IP is set, then you can access outside and also can access inside. It means the localhost for all the application in this machine, no matter inside or outside.
Third one: private IP
This is the IP assigned in your private network, not the public IP. For example, it means the IP 192.168.1.100 in the document you provide. And for the Azure VM, it means the private IP assigned from the subnet. But it only works when you access this IP.
So, in your question, if you want to access both outside and inside. Then you can set the bind IP in the simplest way:
0.0.0.0
private IP
Note: do not forget to expose the port in the NSG associated with your Azure VM. If you do not have a special requirement, I will suggest you bind the IP 0.0.0.0, it's the best way.

How to fix 'Sessions collection is not set up' error when trying to convert existing mongodb instance to replica set

I have installed the latest version of mongodb (v4.0.5) using the following link
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
Following this now I'm trying to set up replication using the instructions provided in the following tutorial
But as soon as i try the command at point "2.Start your mongod instances in their own shell windows by issuing the following commands"
it gives me the following error
"Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured"
Command I used: mongod --replSet rs0 --port 27019 --bind_ip localhost,[MY_IP] --dbpath /srv/mongodb/rs0-2 --smallfiles --oplogSize 128
A more detailed output for the command is as follows:
2018-12-31T15:37:03.618+0530 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] MongoDB starting : pid=xxx port=27017 dbpath=/srv/mongodb/rs0-0 64-bit host=xxx
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] db version v4.0.5
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] git version: xxx
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] allocator: tcmalloc
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] modules: none
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] build environment:
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] distmod: rhel70
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] distarch: x86_64
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] target_arch: x86_64
2018-12-31T15:37:03.623+0530 I CONTROL [initandlisten] options: { net: { bindIp: "localhost,xxx", port: 27017 }, replication: { replSet: "rs0" }, storage: { dbPath: "/srv/mongodb/rs0-0" } }
2018-12-31T15:37:03.624+0530 I STORAGE [initandlisten] Detected data files in /srv/mongodb/rs0-0 created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-12-31T15:37:03.625+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3399M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-12-31T15:37:04.683+0530 I STORAGE [initandlisten] WiredTiger message [1546250824:683476][30064:0x7f4cb133db40], txn-recover: Main recovery loop: starting at 5/6144 to 6/256
2018-12-31T15:37:04.796+0530 I STORAGE [initandlisten] WiredTiger message [1546250824:796244][30064:0x7f4cb133db40], txn-recover: Recovering log 5 through 6
2018-12-31T15:37:04.871+0530 I STORAGE [initandlisten] WiredTiger message [1546250824:871037][30064:0x7f4cb133db40], txn-recover: Recovering log 6 through 6
2018-12-31T15:37:04.945+0530 I STORAGE [initandlisten] WiredTiger message [1546250824:945584][30064:0x7f4cb133db40], txn-recover: Set global recovery timestamp: 0
2018-12-31T15:37:04.964+0530 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-12-31T15:37:04.975+0530 I CONTROL [initandlisten]
2018-12-31T15:37:04.975+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-12-31T15:37:04.975+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-12-31T15:37:04.975+0530 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-12-31T15:37:04.975+0530 I CONTROL [initandlisten]
2018-12-31T15:37:04.975+0530 I CONTROL [initandlisten]
2018-12-31T15:37:04.976+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-12-31T15:37:04.976+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-12-31T15:37:04.976+0530 I CONTROL [initandlisten]
2018-12-31T15:37:04.976+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-12-31T15:37:04.976+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-12-31T15:37:04.976+0530 I CONTROL [initandlisten]
2018-12-31T15:37:04.995+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/srv/mongodb/rs0-0/diagnostic.data'
2018-12-31T15:37:04.996+0530 I REPL [initandlisten] Did not find local voted for document at startup.
2018-12-31T15:37:04.997+0530 I REPL [initandlisten] Rollback ID is 1
2018-12-31T15:37:04.997+0530 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument: Did not find replica set configuration document in local.system.replset
2018-12-31T15:37:04.997+0530 I CONTROL [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured
2018-12-31T15:37:04.997+0530 I NETWORK [initandlisten] waiting for connections on port 27017
2018-12-31T15:37:04.998+0530 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist
I tried following other tutorials where the commands were without the --ip_bind option but i still faced the same error.
I tried searching on the net for this specific error but have not come across any solution for my error.
You need to initiate it with rs.initiate().
Once you launched as you did, you can run this from an other terminal
mongo --eval 'rs.initiate();'
If you are familiar with docker, you can reproduce the error and the initialisation:
docker run --rm -it mongo:4.0 /bin/bash -c "\
mongod --replSet rs0 --fork --logpath /var/log/mongodb/mongod.log &&\
sleep 5 &&\
mongo --eval 'rs.initiate();' &&\
tail -n +0 -f /var/log/mongodb/mongod.log"
I used the --fork to run mongod as a deamon, in order to be able to call the rs.initiate() a bit later

mongo: “exception: connect failed”

I am trying to connect to the mongo server, using the "mongo" command in the command prompt and this error is showing: "exception: connect failed"
Here is how I am trying to do it:
enter image description here
This is the mongodb.log
2018-03-27T14:00:19.299+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2018-03-27T14:00:19.647+0800 I CONTROL [main] Trying to start Windows service 'MongoDB'
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] MongoDB starting : pid=10480 port=27017 dbpath=d:\mongodbData\db 64-bit host=DESKTOP-KEA31I3
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] db version v3.6.3
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] allocator: tcmalloc
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] modules: none
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] build environment:
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] distarch: x86_64
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] options: { service: true, storage: { dbPath: "d:\mongodbData\db" }, systemLog: { destination: "file", logAppend: true, path: "d:\mongodbData\log\mongodb.log" } }
2018-03-27T14:00:19.651+0800 I - [initandlisten] Detected data files in d:\mongodbData\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-03-27T14:00:19.651+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7632M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-03-27T14:00:19.834+0800 I STORAGE [initandlisten] WiredTiger message [1522130419:833660][10480:140722874245456], txn-recover: Main recovery loop: starting at 4/6272
2018-03-27T14:00:19.970+0800 I STORAGE [initandlisten] WiredTiger message [1522130419:970024][10480:140722874245456], txn-recover: Recovering log 4 through 5
2018-03-27T14:00:20.046+0800 I STORAGE [initandlisten] WiredTiger message [1522130420:46191][10480:140722874245456], txn-recover: Recovering log 5 through 5
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** WARNING: The file system cache of this machine is configured to be greater than 40% of the total memory. This can lead to increased memory pressure and poor performance.
2018-03-27T14:00:20.174+0800 I CONTROL [initandlisten] See http://dochub.mongodb.org/core/wt-windows-system-file-cache
2018-03-27T14:00:20.174+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.402+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/mongodbData/db/diagnostic.data'
2018-03-27T14:00:20.404+0800 I NETWORK [initandlisten] waiting for connections on port 27017
2018-03-27T14:00:20.404+0800 I STORAGE [initandlisten] Service running
Please help me. How to fix it
Run this following command :
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
mongo

mongod HostnameCanonicalizationWorker error on OS X

I've just installed MOngoDB via homebrew und want to start it via command line mongod.
When I do that, i'll get this message:
2016-03-05T19:23:55.763+0100 I CONTROL [initandlisten] MongoDB starting : pid=52426 port=27017 dbpath=/data/db 64-bit host=Matthias-MBP
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] db version v3.2.3
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] allocator: system
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] modules: none
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] build environment:
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] distarch: x86_64
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] target_arch: x86_64
2016-03-05T19:23:55.764+0100 I CONTROL [initandlisten] options: {}
2016-03-05T19:23:55.765+0100 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-03-05T19:23:55.765+0100 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-03-05T19:23:56.483+0100 I CONTROL [initandlisten]
2016-03-05T19:23:56.483+0100 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2016-03-05T19:23:56.486+0100 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-03-05T19:23:56.486+0100 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-03-05T19:23:56.488+0100 I NETWORK [initandlisten] waiting for connections on port 27017
2016-03-05T19:23:56.513+0100 W NETWORK [HostnameCanonicalizationWorker] Failed to obtain address information for hostname Matthias-MBP: nodename nor servname provided, or not known
The last line doesn't sound correct. What is the problem?
The first line of logs says
MongoDB starting : pid=52426 port=27017 dbpath=/data/db 64-bit host=Matthias-MBP".
Notice that host name is Matthias-MBP, so you can add 127.0.0.1 Matthias-MBP in /etc/hosts file. After Ctrl-C and re-run mongod, the error message will disappear.
$ cd /private/etc
open hosts file in that directory
copy the following code:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 Matthias-MBP
255.255.255.255 broadcasthost
::1 localhost