Askani
Askani

Reputation: 458

MongoDB aborting when running mongod command on terminal

when i run mongod command on ubuntu terminal i get this error:

{"t":{"$date":"2020-10-28T22:27:29.341+05: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":"2020-10-28T22:27:29.348+05:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-10-28T22:27:29.349+05: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":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":9479,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"E7250"}}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-10-28T22:27:29.350+05:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}
{"t":{"$date":"2020-10-28T22:27:29.350+05:00"},"s":"F",  "c":"-",        "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2020-10-28T22:27:29.350+05:00"},"s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

mongod process is running when i enter command sudo systemctl status mongod

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: ena>
     Active: active (running) since Wed 2020-10-28 22:02:55 PKT; 32min ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 7566 (mongod)
     Memory: 159.0M
     CGroup: /system.slice/mongod.service
             └─7566 /usr/bin/mongod --config /etc/mongod.conf

Oct 28 22:02:55 E7250 systemd[1]: Started MongoDB Database Server.

what went wrong?

etc/mongod.conf file

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

Upvotes: 1

Views: 3098

Answers (2)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59476

When you start the mongod service with sudo systemctl start mongod then the systemd reads the service file /usr/lib/systemd/system/mongod.service.

By default it sets the user to mongod and reads the config file /etc/mongod.conf:

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"

When you start the service with sudo mongod then your mongo runs as root and no config file is read.

In the default mongod.conf file the dbPath is set to

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true

However, when dbPath is not provided then default /data/db applies.

You may start the MongoDB with sudo mongod -f /etc/mongod.conf which correspond to sudo systemctl start mongod - however your mongod is running as root rather than mongod user.

Note, usually you don't edit settings directly in /usr/lib/systemd/system/mongod.service file. Create a copy to /etc/systemd/system/mongod.service and customize this copy. See https://unix.stackexchange.com/questions/206315/whats-the-difference-between-usr-lib-systemd-system-and-etc-systemd-system

Upvotes: 1

Askani
Askani

Reputation: 458

This works for me:

  1. Stop mongod process by entering the following command in terminal: sudo systemctl stop mongod

  2. You have to make directory for "dbPath" with following command: sudo mkdir -p /data/db and sudo chown -R `id -un` /data/db

  3. Then run sudo mongod --port 27017

Done!

you can't run sudo systemctl start mongod and sudo mongod --port 27017 at same time. Stop mongod by sudo systemctl stop mongod then run sudo mongod --port 27017

Hope this solution works for all who have same problem.

Upvotes: 3

Related Questions