Ubuntu – MongoDB – Unit mongod.service can’t found – Ubuntu 16.04

16.04mongodb

When I try to start MongoDB, I get this error:

# mongo  
MongoDB shell version: 3.2.6
connecting to: test
2016-05-21T16:14:31.183+0300 W NETWORK  [thread1] Failed to connect to      127.0.0.1:27017, reason: errno:111 Connection refused
2016-05-21T16:14:31.183+0300 E QUERY    [thread1] Error: couldn't connect $ to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6

exception: connect failed

After that I do some research and learned that I firstly need to start MongoDB server with mongod command. But when I try that, I get an error again:
try that, i get an error again:

# mongod
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] MongoDB starting : pid=32019 port=27017 dbpath=/data/db 64-bit host=ibrahim-Inspiron-3542
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] db version v3.2.6
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] git version:    05552b562c7a0b3143a729aaa0838e558dc49b25
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] OpenSSL version:   OpenSSL 1.0.2g-fips  1 Mar 2016
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] allocator: tcmalloc
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] modules: none
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] build environment:
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten]     distmod:        ubuntu1404
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten]     distarch: x86_64
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten]     target_arch: x86_64
2016-05-21T16:19:15.410+0300 I CONTROL  [initandlisten] options: {}
2016-05-21T16:19:15.451+0300 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2016-05-21T16:19:15.451+0300 I CONTROL  [initandlisten] dbexit:  rc: 100

I try start mongod service on console:

# service mongod start
Failed to start mongod.service: Unit mongod.service not found.

What I need to do?

My English is not so much good, please answer this question with a simple English.

Best Answer

The next step for this is to make sure you have a unit file for the service.

Run this command: ls /lib/systemd/system

If you see mongod.service, you should be good to go. If you need to know what that file should look like, take a look at this guide.

In theory, that should be the last thing you need to do to get it working. Basically, this is just a file to tell the system how to put the service into various states, and the little house-cleaning tasks that need to be carried out.

Related Question