I follow all the steps mention in MongoDB installation documents for Ubuntu 16.04.
Steps 1:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Steps 2:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
Steps 3:
sudo apt-get update
Steps 4:
sudo apt-get install -y mongodb-org
Steps 5:
sudo service mongod start
when I started MongoDB got an error as:
Failed to start mongod.service: Unit mongod.service not found.
Most probably unit mongodb.service is masked. Use following command to unmask it.
sudo systemctl unmask mongod
and re-run
sudo service mongod start
Please follow the below steps, it should work.
1 - Uninstall current installation completely
Source - official instructions
sudo service mongod stop
Remove Packages
sudo apt-get purge mongodb-org*
Remove the folders
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
2 - Reinstall as described on official site, I will just write down the all steps. enter link description here
Import the public key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Create a list file for Ubuntu 16.04
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
update the list
sudo apt-get update
Install the latest package
sudo apt-get install -y mongodb-org
3 - Now it should work, please try below command
sudo service mongod start
and check the status
mongo
it should appear the mongo shell
You are missing a 'b' I think?
sudo service mongod start
should be
sudo service mongodb start
I think this is the case?
Failed to start mongod.service: Unit mongod.service not found
If you are following the official doc and are coming across with the error above that means mongod.service is not enabled yet on you machine (I am talking about Ubuntu 16.04). You need to do that using following command
sudo systemctl enable mongod.service
Now you can start mongodb using the following command
sudo service mongod start
[Solution]
Just type
sudo mongod
It will work.
Case with me
Worked fine after the install; this problem occurred after I rebooted.
What worked for me is
sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/log/mongodb
After running the above commands open a new terminal and run:
sudo systemctl restart mongod
and run the mongo shell to check:
mongo
Note
If this problem occurs again (as with me every time I reboot), make it as a shell script to be run at startup.
Permanent solution (shell script at startup)
Step 1:
Make a file in the /etc/init.d directory
sudo gedit /etc/init.d/custom-mongo-fix.sh
Step 2:
Put below code in the file you just opened in Step 1
#!/bin/bash
# mongodb fix
sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/log/mongodb
Step 3:
After the next boot you can normally start the mongod server by:
sudo systemctl start mongod
Explanation: mongodb requires the above two folders with owner as mongodb. When we shutdown/reboot, one or both of them gets removed. So, we need to create them and change their ownership.
Edit: I was using Stacer's cleaning tool before every shutdown. This also removes log files and folders. And hence, the error at every startup. Now I unselect the mongodb option and then clean.
Namaste. 🙏
$service mongodb start
$service mongodb status
the status is active when I started using above command
For Ubuntu 16.04.5, it is noticed that MongoDB installations does not auto enable the mongod.service file after installation in my case after I have installed on several servers, so we need to enable it like below:
Issue below to check whether mongod is enabled
systemctl list-unit-files --type=service
If it shows as "disabled", then you need to enable it.
sudo systemctl enable mongod.service
If we want to see whether mongod.service file exists in case this file is missing, check in
ls /lib/systemd/system
You will see a file
/lib/systemd/system/mongod.service
This happened to me while adding users in admin db.
sudo systemctl daemon-reload
is recommended from the official mongo website, but did not help.
If you get
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
While executing
sudo systemctl start mongod
run journalctl -xe and if the issue is
Failed to start MongoDB Database Server.
-- Subject: Unit mongod.service has failed
Then run sudo mongod --> mongo
This will fix the issue and if you want to run with systemctl, then terminate the windows for mongod and mongo and run
sudo systemctl start mongod
and then mongo
Just try with this command:
$ sudo systemctl enable mongod
You can repair
$ sudo rm /var/lib/mongodb/mongod.lock
$ mongod --repair
$ sudo service mongodb start
For Stop
$ sudo service mongodb stop
For Restart-
$ sudo service mongodb restart
For Status-
$ sudo service mongodb status
As per documentation:
Run this command to reload the daemon:
sudo systemctl daemon-reload
After this you need to restart the mongod service:
sudo systemctl start mongod
To verify that MongoDB has started, run:
sudo systemctl status mongod
To ensure that MongoDB will start following a system reboot, run:
sudo systemctl enable mongod
May be you are using a wrong version of mongodb list file. I faced this problem but it's my mistake when not selecting the right list file for Ubuntu 16.04. The default selected is for Ubuntu 14.04 and it's the reason for my error: "Failed to start mongod.service: Unit mongod.service not found."
The following steps helped me solve the problem of not being able to start mongodb on Ubuntu Server 18.04 LTS
Step 1: First, remove MongoDB from previous if installed:
sudo apt remove --autoremove mongodb-org
Step 2: Remove any mongodb repo list files:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
Step 3: Import the public key used by the package management system:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Step 4: Create a list file for MongoDB:
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Step 5: Reload local package database:
sudo apt-get update
Step 6: Install the MongoDB packages:
sudo apt-get install -y mongodb-org
Step 7: Start MongoDB:
sudo service mongod start
Step 8: Begin using MongoDB:
mongo
Hope it helps you.
In some cases for some security reasons the unit would be marked as masked. This state is much stronger than being disabled in which you cannot even start the service manually.
to check this, run the following command:
systemctl list-unit-files | grep mongod
if you find out something like this:
mongod.service masked
then you can unmask the unit by:
sudo systemctl unmask mongod
then you may want to start the service:
sudo systemctl start mongod
and to enable auto-start during system boot:
sudo systemctl enable mongod
However if mongodb did not start again or was not masked at all, you have the option to reinstall it this way:
sudo apt-get --purge mongo*
sudo apt-get install mongodb-org
thanks to #jehanzeb-malik
None of the 30+ existing answers helped me, because my service file was actually missing, not masked or disabled. Re-installing wasn't creating it either for some reason. Solution:
cd /lib/systemd/system
sudo touch mongodb.service
# Copy and paste text to go into service file from snippet below horizontal rule
sudo nano mongodb.service
sudo systemctl daemon-reload
sudo systemctl start mongodb
sudo systemctl status mongodb
[Unit]
Description=An object/document-oriented database
Documentation=man:mongod(1)
After=network.target
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
You should check that /etc/mongod.conf is actually the location of your conf file, it may be /etc/mongodb.conf instead.
As for how your service file may have gone missing in the first place. I managed to break it by uninstalling 3.0.15, trying and failing to install 5.* due to ubuntu 16 not being able to run it since some dependencies clashed, then re-installing 3.0.15 again.
I got the same error for a long while, tried almost all installation isntruciton on google but could not find te answer...
I followed the instructions from https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ but keep getting the error Failed to start mongod.service: Unit mongod.service not found
I firstly installed using: sudo apt-get install -y mongodb-org
Then noticed that wher I run:
$ sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
mongodb-org-mongos mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed
mongodb-org mongodb-org-mongos mongodb-org-shell mongodb-org-tools
0 to upgrade, 4 to newly install, 0 to remove and 46 not to upgrade.
Need to get 0 B/40.1 MB of archives.
After this operation, 178 MB of additional disk space will be used.
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 379307 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.0.3_amd64.deb ...
Unpacking mongodb-org-shell (4.0.3) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
Preparing to unpack .../mongodb-org_4.0.3_amd64.deb ...
Unpacking mongodb-org (4.0.3) ...
Setting up mongodb-org-shell (4.0.3) ...
Setting up mongodb-org-mongos (4.0.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up mongodb-org-tools (4.0.3) ...
Setting up mongodb-org (4.0.3) ...
$ mongod --version
db version v2.6.12
2018-10-26T12:03:12.362+0200 git version: d73c92b1c85703828b55c2916a5dd4ad46535f6a
The db version was 2.6.12 instead of the latest one 4.0.3.
So make sure you dont have mongodb-org-server already installed, if yes, then make sure you uupdate it to your target version (as indicated #https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ -> Step 4 - Install a specific release of MongoDB.)
target_version = 4.0.3
sudo apt-get install -y mongodb-org=target_version mongodb-org-server=target_version mongodb-org-shell=target_version mongodb-org-mongos=target_version mongodb-org-tools=target_version
$ sudo apt-get install -y mongodb-org=4.0.3 mongodb-org-server=4.0.3 mongodb-org-shell=4.0.3 mongodb-org-mongos=4.0.3 mongodb-org-tools=4.0.3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
mongodb-org mongodb-org-mongos mongodb-org-shell mongodb-org-tools
The following packages will be upgraded:
mongodb-org-server
1 to upgrade, 4 to newly install, 0 to remove and 45 not to upgrade.
Need to get 15.7 MB/55.8 MB of archives.
After this operation, 217 MB of additional disk space will be used.
Get:1 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0/multiverse amd64 mongodb-org-server amd64 4.0.3 [15.7 MB]
Fetched 15.7 MB in 2s (6,289 kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 379306 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.0.3_amd64.deb ...
Unpacking mongodb-org-shell (4.0.3) ...
**Preparing to unpack .../mongodb-org-server_4.0.3_amd64.deb ...
Failed to stop mongod.service: Unit mongod.service not loaded.
invoke-rc.d: initscript mongod, action "stop" failed.
dpkg: warning: old mongodb-org-server package pre-removal script subprocess returned error exit status 5
dpkg: trying script from the new package instead ...
dpkg: ... it looks like that went OK
Unpacking mongodb-org-server (4.0.3) over (2.6.12) ...**
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
Preparing to unpack .../mongodb-org_4.0.3_amd64.deb ...
Unpacking mongodb-org (4.0.3) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up mongodb-org-shell (4.0.3) ...
Setting up mongodb-org-mongos (4.0.3) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up mongodb-org-tools (4.0.3) ...
Setting up mongodb-org-server (4.0.3) ...
Installing new version of config file /etc/mongod.conf ...
Setting up mongodb-org (4.0.3) ...
and after doing this its all working for me :D
Well.... My answer may be considered naive but in fact it has been the only way MongoDB has work in my case, Ubuntu 19.10. I tried to run the commands from the most voted comments and none worked, when running:
mongod --repair
I got this alert:
With some research I found out that running the DB in another port could be a solution, then:
mongod --port 27018
And it works great for me every time. Long answer but wanted to give context before giving such a simple solution.
(If I'm doing it wrong or doesn't seem logical, plz tell me! Relevant for me)
Do not remove your db if you already have some data you found useful. Just run the command below and you're good.
sudo systemctl restart mongodb.service
To solve the problem of not being able to start mongodb on ubuntu 16.04
1) look at mongodb log file
2) we find that the error is due to "Failed to unlink socket file /tmp/mongodb-27017"
3) Look at the permission of file /tmp/mongdb-27017.lock
and find that the owner is root instead of mongodb
4) Delete the /tmp/mongodb-27017.sock file manually and use the command
"sudo chown mongodb:mongodb /tmp/mongodb*"
5) Start the service with systemcl and use netstat to check whther mongdob has been started on port 27017
Credit: https://www.mkyong.com/mongodb/mongodb-failed-to-unlink-socket-file-tmpmongodb-27017/
https://hevodata.com/blog/install-mongodb-on-ubuntu/
I just encountered this on my parrot os and this is how I solved it.
sudo service mongodb start
Just follow the below commands. This has worked for me.
Uninstall your mongo completely from your system:
sudo service mongod stop
sudo apt-get purge mongodb-org
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Now reinstall mongodb using following commands:
sudo apt update
sudo apt install -y mongodb**
Note: The database server is automatically started after installation.
Next, let's verify that the server is running and works correctly.
sudo systemctl status mongodb
You'll see this output:
mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-05-26 07:48:04 UTC; 2min 17s ago
Docs: man:mongod(1)
Main PID: 2312 (mongod)
Tasks: 23 (limit: 1153)
CGroup: /system.slice/mongodb.service
└─2312 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf**
For those that run into this and end up on this answer, as I did, where they got this error during uninstall orupgrade and Ubuntu keeps failing to uninstall the previous because the service doesn't exist this one line will get you past that and allow the uninstall or upgrade to continue.
sudo touch /lib/systemd/system/mongod.service
It worked for me on ubuntu 20.04: In my case, mongod.service file was locked so it was giving me the same error.
To resolve the issue:-
Step 1: Use following command to check if the mongod.service is present there
cd /usr/lib/systemd/system
ls
Step 2: If the file is present there then Run the following command to unlock the file mongod.service
sudo chmod 777 /usr/lib/systemd/system/mongod.service -R
Step 3: Now run the following commands:
sudo systemctl daemon-reload
sudo systemctl start mongod
sudo systemctl enable mongod
For Ubuntu, if you have old mongodb installed (e.g 3.x).
Then you might need to:
Remove old mongodb first.
Remove old data, WARNING: this may cause data lose.
e.g sudo rm -r /var/lib/mongodb
Remove init script.
e.g sudo rm /etc/init.d/mongodb
Then re-install new mongodb, (e.g 4.x)
Refer: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
Then start with sudo service mongod start.
Then check status with sudo service mongod status.
Tips:
Don't use sudo service mongodb start, there is an extra b, that's for old mongodb, that's why we do sudo rm /etc/init.d/mongodb.
Backup your old data before remove it.
This is because Ubuntu or any other OS, won't work proparly for the system files if you have closed rootlogin. That is right. Even when you enter the root on filesystem. I know it seems not logical but it is all about 1 and 0's here.
Even I have su -
or
ssh root#934.2349.234243 (random IP, won't expose myself here:))
Still it didn't start!
"Failed to restart mongodb.service: Unit mongodb.service not found."
Then...
You need to activate root login. You can download cyberduck or any file explorer to quickly find the file .
go to:
/etc/ssh/
if you couldn't go with a software tool, you can use for the step above:
vi /etc/ssh/sshd_config
then press ctrl-c
write to console for saving it
:wq
Change this file called sshd_config:
/etc/ssh/sshd_config
Edit to line to yes:
PermitRootLogin yes
REBOOT VPS
then write
sudo systemctl restart mongodb
Voila!
if that didn't help either because your VPS initiates services just before on the root, you should reinstall the VPS maybe
Note that if using the Windows Subsystem for Linux, systemd isn't supported and therefore commands like systemctl won't work:
Failed to connect to bus: No such file or directory
See Blockers for systemd? #994 on GitHub, Microsoft/WSL.
The mongo server can still be started manual via mondgod for development of course.
The second step of mongo installation is
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Instead of this command do it manually
cd /etc/apt/
nano sources.list
Write it deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse
And save the file,
Continue all process as in installation docs
It works for me:
Try this: sudo systemctl start mongod and to check whether its running use sudo systemctl status mongod
sudo systemctl unmask mongod
The above command worked for me!
sudo service mongod start
Try starting the service it after unmasking it
sudo systemctl status mongod
Check the status using the above command or simply start the mongodb server using mongo command, I hope it works.
Cheers
Environment
Linux Mint 17.1
localhost
Default MongoDB port 27017
No username or password needed to connect from script.
Background
I installed MongoDB with:
apt-get install mongodb-10gen=2.4.9
I then 'pinned' the package so that no updates would be applied to it:
echo "mongodb-10gen hold" | sudo dpkg --set-selections
Desired Behaviour
I want to upgrade to the latest version of MongoDB and am looking at the official guide for this process:
http://docs.mongodb.org/manual/release-notes/2.6-upgrade
Early on it states:
To begin the upgrade procedure, connect a 2.6 mongo shell to your MongoDB 2.4 mongos or mongod and run the db.upgradeCheckAllDBs() to check your data set for compatibility.
Question
How do I connect a 2.6 mongo shell to a 2.4.9 mongod?
I would guess that I somehow need to just install the 2.6 mongo shell and run it but:
I don't know how to do that and
I don't want to break anything.
I've done a mongodump of all database so have a backup.
I made an attempt to install mongo 2.6 individually but that caused the other packages to be marked for removal. I ended up just uninstalling the old packages and re-installing the new ones and include the process here for reference.
Some of the steps below didn't work, but i've included them and their results as documentation of what was tried. I had previously done a mongodump of all databases so had a backup.
The end result is that everything currently seems to be 'working' apart from the admin database restore.
01. Shut down mongod
mongo
use admin
db.shutdownServer()
from: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
02. Removed the 'pinned package' state of mongodb-10gen with:
echo "mongodb-10gen install" | sudo dpkg --set-selections
from: https://help.ubuntu.com/community/PinningHowto
03. I then tried to install the latest mongo with:
sudo apt-get install -y mongodb-org-shell
from: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
04. The shell version seemed to be updated:
mongo --version
MongoDB shell version: 2.6.6
05. But then I couldn't connect with mongo:
mongo
connecting to: test
2015-01-04T00:08:50.482+1000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-04T00:08:50.483+1000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
or mongod:
mongod
The program 'mongod' is currently not installed. You can install it by typing:
sudo apt-get install mongodb-server
06. I ran the following to see the history of apt-get installs/removals:
less /var/log/apt/history.log
and got:
Start-Date: 2015-01-04 00:02:08
Commandline: apt-get install -y mongodb-org-shell
Install: mongodb-org-shell:amd64 (2.6.6)
Remove: mongodb-10gen:amd64 (2.4.9)
End-Date: 2015-01-04 00:02:21
07. I ran:
dpkg --get-selections
and saw:
mongodb-10gen deinstall
I think 'deinstall' means it is marked for removal.
08. I decided to remove all mongodb-10gen packages with:
sudo apt-get purge mongodb-10gen
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gir1.2-clutter-gst-2.0 gir1.2-ges-1.0 gstreamer1.0-gnonlin libav-tools
libavdevice53 libavfilter3 libavresample1 libges-1.0-0 libgoocanvas-common
libgoocanvas3 libmlt++3 libmlt-data libmlt6 libqjson0 libquicktime2
libsoprano4 melt python-dateutil python-gst-1.0 python-matplotlib
python-matplotlib-data python-mlt python-pygoocanvas python-pyparsing
python-tz python3-bs4 python3-markdown shared-desktop-ontologies
soprano-daemon wkhtmltopdf
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
mongodb-10gen*
0 to upgrade, 0 to newly install, 1 to remove and 3 not to upgrade.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Y
(Reading database ... 246460 files and directories currently installed.)
Removing mongodb-10gen (2.4.9) ...
Purging configuration files for mongodb-10gen (2.4.9) ...
dpkg: warning: while removing mongodb-10gen, directory '/var/lib/mongodb' not empty so not removed
from: https://askubuntu.com/a/147177
09. I made a backup of the directory that could not be removed ie /var/lib/mongodb:
sudo cp -avr /var/lib/mongodb/ /home/
10. And then removed it.
cd /var/lib/
sudo rm -rf mongodb/
11. I searched to see if any mongodb-10gen packages were remaining:
dpkg --get-selections | grep "mongodb-10gen"
which returned nothing.
12. I installed mongodb-org at version 2.6.6 through Synaptic Package Manager.
13. I checked all mongodb packages were at the same version:
mongodump --version
mongorestore --version
mongo --version
mongod --version
mongos --version
# all returned 2.6.6
14. I then did a mongorestore with each database dump eg:
mongorestore --db dname_01 /path/to/dump/dbname_01/
mongorestore --db dname_02 /path/to/dump/dbname_02/
It seems to have worked on all databases but fails on the admin database:
assertion: 17415 Cannot restore users with schema version 1 to a system with server version 2.5.4 or greater
And the users database threw some anomalies eg:
Restoring to users.pending_registrations without dropping. Restored data will be inserted without raising errors; check your server log
Restoring to users.roles without dropping. Restored data will be inserted without raising errors; check your server log
Restoring to users.users without dropping. Restored data will be inserted without raising errors; check your server log
15. I ran db.upgradeCheckAllDBs():
mongo
use admin
db.upgradeCheckAllDBs()
Checking database local
Checking collection local.startup_log
Checking collection local.system.indexes
Checking database dname_01
...
Checking database admin
Everything is ready for the upgrade!
true
from: http://docs.mongodb.org/manual/release-notes/2.6-upgrade/#preparedness
I know you have managed to solve your question, but the following link helped me and I thought I could post it here for future reference and in case somebody else finds it hard upgrading mongodb:
http://blog.lecstor.com/mongodb-upgrade-24-to-26-in-debian
EDIT: A more appropriate answer, quoting the link above:
You have to download the tar version of MongoDB and run the shell straight from there:
$ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
$ tar -zxvf mongodb-linux-x86_64-2.6.1.tgz
$ ./mongodb-linux-x86_64-2.6.1/bin/mongo
To run the check, you also need to be using the admin database, so..
>use admin
switched to db admin
>db.upgradeCheckAllDBs()
Checking database mydb1
Checking collection mydb1.coll1
Checking collection mydb1.coll2
Checking database mydb2
Checking collection mydb2.coll1
Checking collection mydb2.coll2
Everything is ready for the upgrade!
true
I just installed mongoDB on ubuntu 14.0.4.
I tried to start the shell but I'm getting a connection refused error.
me#medev:/etc/init.d$ mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-10T15:06:28.084-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-10T15:06:28.085-0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
So I decided to try to restart the service but that's failing too. I get the following error message:
me#medev:/etc/init.d$ sudo service mongodb restart
mongodb: unrecognized service
me#medev:/etc/init.d$
This is what I have in my /var/log/mongodb/mongod.log - http://pastebin.com/MrHt8tce
what i've tried so far:
I found another post here: can't start mongodb as sudo
which made a comment about remove the mongo lock file.
I deleted the lock file and then retried my command but it still fails as you can see below:
me#medev:/var/lib/mongodb$ sudo rm mongod.lock
me#medev:/var/lib/mongodb$ ls
journal local.0 local.ns _tmp
me#medev:/var/lib/mongodb$ sudo service mongodb start
mongodb: unrecognized service
But I can start it using /etc/init.d as you can see below:
me#medev:/var/lib/mongodb$ sudo /etc/init.d/mongod start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod
mongod start/running, process 27469
me#medev:/var/lib/mongodb$ ls
journal local.0 local.ns mongod.lock
me#medev:/var/lib/mongodb$ mongo
MongoDB shell version: 2.6.5
connecting to: test
> db
test
>
Any ideas on why I can't start it using the service command would be appreciated. From what I've read, i should be using sudo service mongodb
Try this:
Write mongodb instead of mongod
sudo service mongodb status
I got the same error one day You should use this:
1.Get the status of your mongo service:
/etc/init.d/mongod status
or
sudo service mongod status
2.If it's not started repair it like this:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
And check again if the service is started again(1)
For me the solution was to replace
service mongod start
with
start mongod
You need to make sure the file (ex. /etc/init.d/mongodb) has execute permissions.
chmod +x /etc/init.d/mongodb
For debian, from the 10gen repo, between 2.4.x and 2.6.x, they renamed the init script /etc/init.d/mongodb to /etc/init.d/mongod, and the default config file from /etc/mongodb.conf to /etc/mongod.conf, and the PID and lock files from "mongodb" to "mongod" too. This made upgrading a pain, and I don't see it mentioned in their docs anywhere. Anyway, the solution is to remove the old "mongodb" versions:
update-rc.d -f mongodb remove
rm /etc/init.d/mongodb
rm /var/run/mongodb.pid
diff -ur /etc/mongodb.conf /etc/mongod.conf
Now, look and see what config changes you need to keep, and put them in mongod.conf.
Then:
rm /etc/mongodb.conf
Now you can:
service mongod restart
I installed mongo server on Debian Jessie using manual from official site.
It didn't started after recommended command sudo service mongod restart with the same error - mongodb: unrecognized service.
After looking into installed package contents, I noticed that it contains only Systemd service unit, but no SystemV init script:
# dpkg -L mongodb-org-server
/.
/usr
/usr/bin
/usr/bin/mongod
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/mongodb-org-server
/usr/share/doc
/usr/share/doc/mongodb-org-server
/usr/share/doc/mongodb-org-server/LICENSE-Community.txt
/usr/share/doc/mongodb-org-server/README
/usr/share/doc/mongodb-org-server/copyright
/usr/share/doc/mongodb-org-server/changelog.gz
/usr/share/doc/mongodb-org-server/GNU-AGPL-3.0.gz
/usr/share/doc/mongodb-org-server/THIRD-PARTY-NOTICES.gz
/usr/share/doc/mongodb-org-server/MPL-2.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/mongod.1.gz
/etc
/etc/mongod.conf
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/mongod.service
But my system was running on SysV init:
# stat /proc/1/exe
File: '/proc/1/exe' -> '/sbin/init'
So, there are 2 options now:
(Continue on SysV) Write sysV init script manually as #khylo mentioned above
(Switch to SystemD) and run systemctl start mongod
For me nothing have helped, I've ended up with a solution:
create /lib/systemd/system/mongod.service file with content
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
then start/stop commands should work
$ sudo service mongod start
For reference - I have Ubuntu 14.04 LTS, MongoDB 3.2.9 installed from
deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse
You can use mongod command instead of mongodb, if you find any issue regarding dbpath in mongo you can use my answer in the link below.
https://stackoverflow.com/a/53057695/8247133
I think you may have installed the version of mongodb for the wrong system distro.
Take a look at how to install mongodb for ubuntu and debian:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
I had a similar problem, and what happened was that I was installing the ubuntu packages in debian
Original Source - https://www.techrepublic.com/article/how-to-install-mongodb-community-edition-on-ubuntu-linux/
If you're on Ubuntu 16.04 and face the unrecognized service error, these instructions will fix it for you:-
Open a terminal window.
Issue the command sudo apt-key adv —keyserver hkp://keyserver.ubuntu.com:80 —recv EA312927
Issue the command sudo touch /etc/apt/sources.list.d/mongodb-org.list
Issue the command sudo gedit /etc/apt/sources.list.d/mongodb-org.list
Copy and paste one of the following lines from below (depending upon your release) into the open file.
For 12.04: deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.6 multiverse
For 14.04: deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse
For 16.04: deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse
Make sure to edit the version number with the appropriate latest version and save the file.
Installation
Open a terminal window and issue command sudo apt-get update && sudo apt-get install -y mongodb-org
Let the installation complete.
Running MongoDB To start the database, issue the command sudo service mongodb start. You should now be able to issue the command to see that MongoDB is running: systemctl status mongodb
Ubuntu 16.04 solution
If you are using Ubuntu 16.04, you may run into an issue where you see the error mongodb: unrecognized service due to the switch from upstart to systemd. To get around this, you have to follow these steps.
If you added the /etc/apt/sources.list.d/mongodb-org.list, remove it with the command sudo rm /etc/apt/sources.list.d/mongodb-org.list
Update apt with the command sudo apt-get update
Install the official MongoDB version from the standard repositories with the command sudo apt-get install mongodb in order to get the service set up properly
Remove what you just installed with the command sudo apt-get remove mongodb && sudo apt-get autoremove
Now follow steps 1 through 5 listed above to install MongoDB; this should re-install the latest version of MongoDB with the systemd services already in place. When you issue the command systemctl status mongodb you should see that the server is active.
I mostly copy pasted the above (with minor modifications and typo fixes) from here - https://www.techrepublic.com/article/how-to-install-mongodb-community-edition-on-ubuntu-linux/
This is a simple solution that worked for me with the same problem (I think):
mv /var/lib/mongodb /var/lib/mongodb_backup
mkdir /var/lib/mongodb
chmod 700 /var/lib/mongodb
chown mongodb:daemon /var/lib/mongodb
systemctl restart mongodb or service mongod restart
If you're running Ubuntu in WSL (Windows Subsystem for Linux), you will have issues because WSL does not currently support systemd.
The link below explains how to run MongoDB without systemd, and even how to add a script for using the service command with WSL.
https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database#mongodb-init-system-differences
tutorials may start MongoDB using the operating system's built-in init system. You might see the command sudo systemctl status mongodb used in tutorials or articles. Currently WSL does not have support for systemd (a service management system in Linux).
You shouldn't notice a difference, but if a tutorial recommends using sudo systemctl, instead use: sudo /etc/init.d/. For example, sudo systemctl status docker, for WSL would be sudo /etc/init.d/docker status ...or you can also use sudo service docker status.
I am attempting to install and run a postgreSQL server, whenever I install it using
sudo apt-get install postgresql
I get the following error:
* Starting PostgreSQL 9.1 database server
* The PostgreSQL server failed to start. Please check the log output:
2014-04-03 17:18:16 PDT FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
[fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-common (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of postgresql-9.1:
postgresql-9.1 depends on postgresql-common (>= 115~); however:
Package postgresql-common is not configured yet.
dpkg: error processing postgresql-9.1 (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of postgresql:
postgresql depends on postgresql-9.1; however:
Package postgresql-9.1 is not configured yet.
dpkg: error processing postgresql (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while
processing:
postgresql-common
postgresql-9.1
postgresql
E: Sub-process /usr/bin/dpkg returned an error code (1)
I am guessing it's a permissions issue; how do I go about solving it?
I am running Ubuntu 13.10
Change the owner of /var/run/postgresql and set it to postgres:
sudo chown -R postgres:postgres /var/run/postgresql
If the user you are running as does not have sudo privilege, then
Change to root:
su -
Change ownership of /var/run/postgresql to user postgres and group postgres:
chown -R postgres:postgres /var/run/postgresql
I had the same problem when installing postgres on Ubuntu 14.04 and changing the ownership fixed the problem for me.
The lock file ends up in /var/run. To fix the permissions of this dir, I needed to run sudo chmod a+w /var/run/postgresql.
Could you check the file permissions of /var/run?
ls -l /var/run
If 'write' permission is missing, try
sudo chmod o+w /var/run