i followed the official instruction of mongodb install_intruction on my Ubuntu 20.04 LTS,
when i started mongodb by this line:
sudo systemctl start mongod
i got an error like this:
Failed to start mongod.service: Unit mongod.service not found.
of course i tried to reload as mongdb instruction:
sudo systemctl daemon-reload
it still shows:
Failed to start mongod.service: Unit mongod.service not found.
then i tried:
systemctl list-unit-files --type=service
to find mongod.service but i couldnt find it. and i tried:
ls /lib/systemd/system
that didnt work either there is no mongod.service file
i really need a hand!!!
It's too late to answer, but may be it will help someone.
In my case, if my run ls /lib/systemd/system | grep mongo there was no file relating to Mongo. So, I created one service file manually.
Step 1.
sudo touch /lib/systemd/system/mongod.service
Step 2.
Open file in vim/nano and paste below script.
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
This is default service file for mongod. Now run sudo systemctl start mongod. It will hopefully work.
Do a reinstall, after purging the current installation.
sudo apt purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Run the command without sudo for the first time
systemctl start mongod.service
How can we setup multiple versions of MongoDB on Ubuntu 16.04?
MongoDB 3.4.1 is already up and running on my system and wanted to setup MongoDB 2.6 for other application. Because our Application running on MongoDB 2.6 is having DB driver which is not compatible with MongoDB 3.4 hence wanted run both MongoDB version on same linux server.
Tried to follow below link but couldn't succeed.
How can I install two versions of mongodb parallely in Ubuntu 12.04
?
multiple versions of Mongo
multiple instances of Mongo DB on same server
To do that, you must have both versions of MongoDB available on your system.
For instance, let's say you have downloaded the 2.6 version binaries to /opt/mongo/26/ and the other version's at /opt/mongo/34/, you could run both versions of the database daemon on different ports:
/opt/mongo/26/mongod --dbpath /data/26/ --port 27017
/opt/mongo/34/mongod --dbpath /data/34/ --port 28018
This is what I do.
1. Choose version:
Community: https://www.mongodb.com/download-center/community/releases/archive
Enterprise: https://www.mongodb.com/download-center/enterprise/releases/archive
2. Install and Configuration
I use Ubuntu 20.04 and I want to install mongodb Community ver 2.6.12
Installing:
$ cd ~/Downloads
$ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
$ tar -zxvf mongodb-linux-x86_64-2.6.12.tgz
$ mv mongodb-linux-x86_64-2.6.12 2.6.12
$ cd /opt && mkdir -p mongodb
$ cd ~/Downloads
$ cp -R 2.6.12 /opt/mongodb
$ cp /mongod.conf /opt/mongodb/2.6.12/
Configuration:
Configuration options on version <3.0 is different with version >3.0 so I googled it. This is what I had.
systemLog:
destination: file
path: "/var/log/mongodb/mongodb.log"
logAppend: true
storage:
journal:
enabled: true
processManagement:
fork: true
net:
bindIp: 127.0.0.1
port: 27018
setParameter:
enableLocalhostAuthBypass: false
On this file, you need change systemLog.path, net.port and net.bindIp to your own. One important thing is we cannot run 2 versions at same time with same port. So here I set 27018 for older version.
Put it wherever you want, I did:
$ cp ~/mongod.conf /opt/mongodb/2.6.12/
DON'T RUN THIS because it will overwrite current mongodb version commands
$ export PATH=/opt/mongodb/2.6.12/bin:$PATH
Create data and log directories and set permission.
$ mkdir -p /data/db
$ mkdir -p /var/log/mongodb
Running:
Now you can start 2.6 version with command.
$ /opt/mongodb/2.6.12/bin/mongod --fork --dbpath /data/db --config /opt/mongodb/2.6.12/mongod.conf
It is too long, isn't it? So make it shorter with alias.
$ sudo nano ~/.bash_profile
or
$ sudo nano ~/.bashrc
and add this to file
alias mongo26="/opt/mongodb/2.6.12/bin/mongo --port 27018"
alias mongoRestore26="/opt/mongodb/2.6.12/bin/mongorestore --port 27018"
alias mongoDump26="/opt/mongodb/2.6.12/bin/mongodump --port 27018"
alias startMongo26="/opt/mongodb/2.6.12/bin/mongod --fork --dbpath /data/db --config /opt/mongodb/2.6.12/mongod.conf"
alias stopMongo26="/opt/mongodb/2.6.12/bin/mongod --dbpath /data/db --shutdown"
alias nanoMongo="nano /opt/mongodb/2.6.12/mongod.conf"
alias tailMongo="tail -f /var/log/mongodb/mongod.log"
alias tailMongo26="tail -f /var/log/mongodb/mongodb.log"
Apply these alias
$ source ~/.bash_profile
or
$ source ~/.bashrc
Now we can simply start mongodb version 2.6 by
$ startMongo26
about to fork child process, waiting until server is ready for connections.
forked process: 1049481
child process started successfully, parent exiting
Run shell version 2.6
$ mongo26
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27018/test
>
Run shell current version
$ mongo
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("3ae6094f-86dc-4741-aa72-1e48efc5273a") }
MongoDB server version: 4.4.3
>
3.Troubleshooting
Cannot start by startMongo26 please check log at /var/log/mongodb/mongod.log
about to fork child process, waiting until server is ready for connections.
forked process: 1049890
ERROR: child process failed, exited with error number 100
Check log at /var/log/mongodb/mongod.log
If log has this line:
2021-02-26T15:51:13.493-0700 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
This is because your current user doesn't have permission to run and write into this directory. You can set permission to /data/db or change directory. I changed to ~/datamongo
$ /opt/mongodb/2.6.12/bin/mongod --fork --dbpath ~/datamongo --config /opt/mongodb/2.6.12/mongod.conf
Do the same with error on /var/log/mongodb/mongodb.log
Cannot shutdown by stopMongo26
There doesn't seem to be a server running with dbpath: /data/db
Do this:
$ mongo26
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27018/test
> use admin
switched to db admin
> db.shutdownServer()
2021-02-26T15:45:19.738-0700 DBClientCursor::init call() failed
server should be down...
2021-02-26T15:45:19.742-0700 trying reconnect to 127.0.0.1:27018 (127.0.0.1) failed
2021-02-26T15:45:19.742-0700 warning: Failed to connect to 127.0.0.1:27018, reason: errno:111 Connection refused
2021-02-26T15:45:19.742-0700 reconnect 127.0.0.1:27018 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27018 (127.0.0.1), connection attempt failed
Do step by step with my instruction you gonna be ok. Good luck and enjoy!!!
I am using CentOS 7.3 as a guest VM from Oracle VirtualBox. The host is Windows 7 and I have a physical USB stick (aka flash drive) to house the data directory for Postgres. I can use a USB stick as a mounted directory in Linux. I can read and write files to it.
I expect to be able to have Postgres databases on my USB stick. But I cannot get Postgres databases on my USB stick. I installed Postgres on the Linux VM.
To change the default data directory of Postgres, I followed these directions.
If you do not have time to go to the link, I simply installed Postgres with these two commands:
yum -y install postgresql-server postgresql-contrib
postgresql-setup initdb
then I ran these two commands:
mv /var/lib/pgsql/data/* /mnt/windows-share/data
ln -s /mnt/windows-share /var/lib/pgsql/data
Afterward I try to start the Postgres service, I get an error.
Here is the command that I try (as root):
systemctl start postgresql
Here is the error:
Job for postgresql.service failed because the control process exited
with error code. See "systemctl status postgresql.service" and
"journalctl -xe" for detail.
I tried systemctl status postgresql.service and I found this:
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled
vendorpreset: disabled)
Active: failed (Result exit-code)... Process ...
ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited,
status=1/FAILURE)
... failed to start PostgreSQL... ...Unit postgresql.service...
...postgresql.service failed
I used journalctl -xe but that did not tell me anything meaningful.
To change the default data directory of Postgres, I tried this:
postgresql-setup initdb --pgdata=/mnt/windows-share/
But I got
failed to find PGDATA setting in --pgdata=/mnt/mar/data.service
How do I get Postgres installed with a customized data directory? I need it to be in a the "/mnt/" directory. I want to create all my databases on a USB stick.
To install Postgres on a customized location (e.g. home/postgres directory) follow these steps
install the required version of Postgres e.g. 13
create postgres directory in Home. and grant its access to posgres user
mkdir postgres
chown postgres:postgres postgres
usermod -m -d /home/postgres postgres
Move data directory to the new location as:
rsync -av /var/lib/pgsql/ /home/postgres/
update the location in postgres server as:
find / -name postgresql-9.5.service
vi /usr/lib/systemd/system/postgresql-9.5.service
update the data location in the file:
from the old location, e.g.
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/13/data/
to the new location, e.g.
# Location of database directory
Environment=PGDATA=/home/postgres/13/data/"
Stop postgres, reload deamon and start postgres
stop postgres
systemctl daemon-reload
start postgres
Done...
I' ve solved the same problem on CentOS 6
Maybe u can try it.
Add your disk
Check your disk is existing (in my case new disk is /dev/sdb1/)
# fdisk -l
Mount new disk
# mkdir /hdd2
# mount -t ext3 /dev/sdb1 /hdd2/
Auto mount hard disk by add new line:
# vi /etc/fstab
Add line: /dev/sdb1 /hdd2 ext3 defaults 0 0
Config postgres
# service postgresql stop
# vi /etc/sysconfig/pgsql/postgresql
Add line: PGDATA=/hdd2/data
# service postgresql start
Hope it useful to you!!
I am getting this error when I run command sudo forever start mongod
[root#ip-1**-3*-**-5* ec2-user]# sudo forever mongod start
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
error: Cannot start forever
error: script /home/ec2-user/mongod does not exist.
but normally when I run mongod or sudo mongod it just works fine. help me whats the issue.
You should specify OS Name, OS version, MongoDB version so that we can easy help you. I hope you are using Amazon Linux so you need to use systemctl start/stop mongodb, following command to enable and start
sudo su
chkconfig mongod on
sudo service mongod start
and to stop
sudo service mongod stop
Please have a look MongoDB Amazon Linux Doc
I am running Fedora 20 and installed MongoDB per the Red Hat installation guide on the official documentation. I was able to run the mongod daemon as a service without error the very first time but when I shut down my machine and came back, the service refused to start due to some failure.
In my log, listed after the successful run, I see this:
***** SERVER RESTARTED *****
ERROR: Cannot write pid file to /var/run/mongodb/mongod.pid: No such file or directory
If I try starting mongod or running mongod --repair manually, I get this message in a start up failure:
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
This is odd considering that in my config file in /etc/mongod.conf, the settings for the database path are as follows:
dbpath=/var/lib/mongo
Finally, if I run this command:
mongod --dbpath /var/lib/mongo
The daemon starts up just fine. However, I am unable to replicate that error free behavior for starting a service.
Can anyone tell me what exactly is wrong and how I can begin running mongod as a service?
EDIT
I get this message if I run mongod --config /etc/mongod.conf:
about to fork child process, waiting until server is ready for connections. forked process: 2702 ERROR: child process failed, exited with error number 1
The /var/run/mongodb directory did not exist, so I created and assigned it to the mongod user. That did not make much of a difference, unfortunately.
My /var/log/mongodb/mongod.log shows this message:
[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /var/lib/mongo/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
What worked for me on Fedora 20: we need to create the temp dir on every boot, and that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf and put one line in it:
d /var/run/mongodb 0755 mongod mongod
That seems to handle it on restarts; if you don't want to restart right away, you can execute that with:
sudo systemd-tmpfiles --create mongodb.conf
(See the man pages for systemd-tmpfiles)
I have the same problem, I solved it temporarily, disabling SELinux, rebooted the machine, eliminated mongod.lock:
#rm /var/lib/mongo/mongod.lock
By creating the file /var/run/mongodb/mongo.pid (as mentioned in the configuration file /etc/mongod.conf):
#mkdir /var/run/mongodb
#touch /var/run/mongodb/mongod.pid
and giving 777 permissions:
#chmod 777 /var/run/mongodb/mongod.pid
and starting mongo:
#service mongod start
But the problem persists after restarting the machine. The folder and file disappear.
I've spent a while looking into this, and it appears as if the pid folder and file permissions don't work with the default daemon.
The simplest solution I've come across is disable the pid file by just putting a # in front of the line in the config file.
vi /etc/mongod.conf
find the line that says pidfilepath=/var/run/mongodb/mongod.pid and change it accordingly.
# pidfilepath=/var/run/mongodb/mongod.pid
For information on what commenting it out does check here.
http://docs.mongodb.org/manual/reference/configuration-options/#processManagement.pidFilePath
If you’re starting mongod as a service using:
sudo service mongod start
Make sure the directories defined for logpath, dbpath, and pidfilepath in your mongod.conf exist and are owned by mongod:mongod.
I was having the same problem running mongodb 3.0.4 on OpenSuse 13.2, and I found that the mongod directory under /var/run was missing. If I created the directory manually it would disappear after a reboot.
I solved it by adding the following lines to my /etc/init.d/mongod startup script:
mkdir -p /var/run/mongod
chown $MONGO_USER:$MONGO_GROUP /var/run/mongod
This worked for me in Ubuntu:
sudo kill $(sudo lsof -t -i:27017)
sudo rm -rf /tmp/mongodb-27017.sock
sudo rm -f /var/lib/mongo/mongod.lock
sudo rm -f /var/run/mongodb/mongod.pid
sudo mkdir -p /var/run/mongodb/
sudo touch /var/run/mongodb/mongod.pid
sudo chown -R mongodb:mongodb /var/run/mongodb/
sudo chown mongodb:mongodb /var/run/mongodb/mongod.pid
sudo service mongod start
i met the same issue,when i modify my mongod.conf as follow and problem resolved~
port=27017
dbpath=/usr/local/mongodb/data/db/
logpath=/usr/local/mongodb/logs
fork = true
tips: logpath is the logfile not a folder.
I just experience a similar problem on ubuntu. Encountered nearly every ERROR tips, like
child process failed, exited with error number 1
orchild process failed, exited with error number 100
or [signalProcessingThread] got signal 2 (Interrupt: 2), will terminate after current cmd ends
For many times I remove the Mongodb and try to install again, but the problem remains....
Finally I came to this way:
Backup your data first, then remove Mongodb with
#sudo apk-get autoremove mongodb-org
Find out all the files related with mongodb:
/#find -name mongo*
Delete them all with "rm" or "rmdir", including the packages in the /var/cache/... and everthing.
Then repeat the installation as the first time you did :
#echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
#sudo apt-get update
#sudo apt-get install -y mongodb-org
It will run again.
Comment below the line from your "mongo.conf" file.
pidfilepath=/var/run/mongodb/mongod.pid
Following commands solved for cent os
ERROR:
service mongod status
Error starting mongod. /var/run/mongodb/mongod.pid exists
FIXED BY:
rm /var/lib/mongo/mongod.lock
chown -R mongod:mongod /var/log/mongodb/
chown -R mongod:mongod /var/run/mongodb/
chown -R mongod:mongod /var/lib/mongo/
chmod 777 /var/run/mongodb/mongod.pid
mongod --dbpath /var/lib/mongo
We need to create the temp dir location of pidfile /var/run/mongodb that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf as root:
lnx#> sudo su
lnx#> cd /lib/tmpfiles.d
lnx#> echo “d /var/run/mongodb 0755 mongod mongod” > mongodb.conf
Then reboot or run this command to activate that temp directory:
lnx#>sudo systemd-tmpfiles --create mongodb.conf
Start mongod service:
lnx#> sudo systemctl start mongod.service
Bibliography: Fedora And Mongodb · l33tsource