mongoDB / Rasberry Pi, with Raspberry Pi OS

I want to share a problem I am facing with installing a mongoDB replica set on Rasberry Pi, hoping someone can give me some help. My goal is to do what I did before here. But this time I want to use Raspberry Pi OS instead of Ubuntu.

I have already reached the point where mongoDB is installed.

This is my environment:

root@raspberrypi:~ # uname -a
Linux raspberrypi 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux
root@raspberrypi:~ # 
root@raspberrypi:~ # mongo --version
MongoDB shell version v4.4.4
Build Info: {
    "version": "4.4.4",
    "gitVersion": "8db30a63db1a9d84bdcad0c83369623f708e0397",
    "openSSLVersion": "OpenSSL 1.1.1d  10 Sep 2019",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1804",
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}
root@raspberrypi:~ # 

And this is the configuration file for the first server:

root@raspberrypi:~ # cat /home/mongodb/mongo-One.cfg 
storage:
  dbPath: /mnt/mongoDB-One/DB_Data
  journal:
    enabled: true
net:
  bindIp: localhost,192.168.10.116
  port: 22330
systemLog:
  destination: file
  path: /mnt/mongoDB-One/DB_Data/mongod.log
  logAppend: true
replication:
  replSetName: mngoRepSet
root@raspberrypi:~ # 

The server is (meant to be) started at boot time, using systemd.

This is when things go wrong.

First we can check that the mongod-One service did not start, during system boot, as it should have, by running the following command.

pi@raspberrypi:~ $ systemctl status mongod-One
● mongod-One.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod-One.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2021-03-20 12:51:15 JST; 3min 50s ago
     Docs: https://docs.mongodb.org/manual
  Process: 534 ExecStart=/usr/bin/mongod --config /home/mongodb/mongo-One.cfg (code=exited, status=48)
 Main PID: 534 (code=exited, status=48)

Mar 20 12:51:14 raspberrypi systemd[1]: Started MongoDB Database Server.
Mar 20 12:51:15 raspberrypi systemd[1]: mongod-One.service: Main process exited, code=exited, status=48/n/a
Mar 20 12:51:15 raspberrypi systemd[1]: mongod-One.service: Failed with result 'exit-code'.
pi@raspberrypi:~ $ 

Next looking further, here is the log file contents:

root@raspberrypi:~ # cat /mnt/mongoDB-One/DB_Data/mongod.log
{"t":{"$date":"2021-03-20T12:51:15.782+09:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-03-20T12:51:15.838+09:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-03-20T12:51:15.839+09:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2021-03-20T12:51:15.842+09:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-03-20T12:51:15.846+09:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":534,"port":22330,"dbPath":"/mnt/mongoDB-One/DB_Data","architecture":"64-bit","host":"raspberrypi"}}
{"t":{"$date":"2021-03-20T12:51:15.847+09:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.4","gitVersion":"8db30a63db1a9d84bdcad0c83369623f708e0397","openSSLVersion":"OpenSSL 1.1.1d  10 Sep 2019","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"aarch64","target_arch":"aarch64"}}}}
{"t":{"$date":"2021-03-20T12:51:15.847+09:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"","version":"Kernel 5.10.17-v8+"}}}
{"t":{"$date":"2021-03-20T12:51:15.847+09:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/home/mongodb/mongo-One.cfg","net":{"bindIp":"localhost,192.168.10.116","port":22330},"replication":{"replSetName":"mngoRepSet"},"storage":{"dbPath":"/mnt/mongoDB-One/DB_Data","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/mnt/mongoDB-One/DB_Data/mongod.log"}}}}
{"t":{"$date":"2021-03-20T12:51:15.862+09:00"},"s":"E",  "c":"STORAGE",  "id":20568,   "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Cannot assign requested address"}}}
{"t":{"$date":"2021-03-20T12:51:15.863+09:00"},"s":"I",  "c":"REPL",     "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":10000}}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"REPL",     "id":4784907, "ctx":"initandlisten","msg":"Shutting down the replica set node executor"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"CONTROL",  "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"STORAGE",  "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"STORAGE",  "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"FTDC",     "id":4784926, "ctx":"initandlisten","msg":"Shutting down full-time data capture"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":48}}
root@raspberrypi:~ # 

The problem is of course: Why doesn’t the mongod-One service starts as expected?

Another piece of information may be useful here:

If I use this command, after the boot is over, to start the service manually, then it works.

root@raspberrypi:~ # systemctl start mongod-One

I have also been able to do the same with the other servers (all of them having the same issue) and finally initialize a replica set.

Searching the net shows somewhat similar issues, but without leading to a solution.

You got the error:

{"t":{"$date":"2021-03-20T12:51:15.862+09:00"},"s":"E",  "c":"STORAGE",  "id":20568,   "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Cannot assign requested address"}}}

One of the following:

  1. wrong IP address
  2. another process is listening for the same host/port combination

Well, I don’t really know how to make use of either of your suggestions. I have of course checked the IP. And I don’t have any other process listening for the same host/port combination.

Beside if this was the case, how can we explain that I can then simply start the service by hand?
(Right after the boot process is over, without doing anything except running the systemctl start command)

Hi @Michel_Bouchet,

The error message and direct causes that @steevej suggested are correct.

A likely scenario is that your MongoDB service is starting before the networking service has finished setting up the non-localhost IP you are asking mongod to bind to. Localhost/loopback interfaces are unconditionally available; other network interfaces require setup which can be dependent on remote services like DHCP.

What have you set as the After target in the [Unit] section of your mongod-One.service definition?

I suspect that may need to be network-online.target.

For reference info, see systemd usage (Rasperry Pi) and Running Services After the Network is Up.

Regards,
Stennie

Hi @Stennie;

Well, what you write makes sense.
And to fix the the situation I went to see the contents of the mongod-One.service file.

Here is the [Unit] section:

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

As you can see, it is already what you want it to be.
So there must be something else to my problem.

In the mean time I finally got it all to work. And my tutorial now supports installing a mongodb replicaset on raspberry pis with RaspBerry Pi OS see here if you are interested.

Hi @Michel_Bouchet, thanks for sharing your write ups!

What was the solution to your issues with bindIp?

Regards,
Stennie

It’s a while ago. I suggest you take a look at this, the solution is included:
https://tutorama.info/RazBiMong/

Hi…I’m speculating you have introduced the Raspbian mongo bundle with “well-suited get introduce mongo” or whatever.

On the off chance that so mono form in Raspiban is quite old, Hence the adaptation befuddle. This is frequently the situation with Raspbian/Debian bundles however particularly mongo as more up to date forms of mongo don’t uphold 32 cycle working framework. Know that Mono on 32 digit frameworks is restricted to just 2GB of information.