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
Related
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
This question already has answers here:
MongoDB Failing to Start - ***aborting after fassert() failure
(8 answers)
Closed 5 years ago.
Having some trouble configuring mongodb to Linux ec2 after following these directions https://docs.mongodb.com/ecosystem/platforms/amazon-ec2/
[root#ip-xxx-xx-xx-xxx /]# sudo service mongod start
Error starting mongod. /var/run/mongodb/mongod.pid exists.
[root#ip-xxx-xx-xx-xxx /]# sudo service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [FAILED]
I also tried rm -f /var/run/mongodb/mongod.pid which now instantly fails.
[root#ip-xxx-xx-xx-xxx /]# sudo service mongod start
Starting mongod: [FAILED]
I have a feeling it may be my mongod.conf and tried editing the dbPath and sysLogPath according to the docs.
# mongod.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: "log/mongod.log"
# Where and how to store data.
storage:
dbPath: "/data"
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
I am new to both AWS and deploying a db, and would appreciate suggestions!
After checking to log/mongod.log as #hjpotter92 suggested I found it was ***aborting after fassert() failure
From the link below I ran the commands, which was successful.
sudo rm /tmp/mongodb-27017.sock
rm -f /var/run/mongodb/mongod.pid
sudo service mongod start
MongoDB Failing to Start - ***aborting after fassert() failure
you are using sudo while logged in as root .
Please recheck if this is is causing the issue .
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!!
Launched Ubuntu 14.04 LTS micro instance on EC2, installed latest MongoDB following their official documentation. When I run sudo mongod --fork --dbpath /somedbpath --logpath /somelogpath followed by mongo,
I get the warning that it shouldn't be run as a root user. I did notice the installation process created a mongodb user and group and I can see them in the outputs of compgen -u and compgen -g respectively. I shutdown the mongod server and even deleted all files created in the dbpath directory. Now, I'd like to run the daemon as mongodb user, as I've learned it has all the appropriate permissions and ulimits required for optimal performance.
How do I switch from ubuntu to mongodb user, though? I ran sudo passwd mongodb and updated a password. Then I tried su mongodb, entered the password when prompted, but hitting ENTER kept me logged in as ubuntu only. I tried logging out and back in. I manually created the mongodb dir under /home since it wasn't present. I even created a .ssh dir inside that and copied the authorized_keys file from /home/ubuntu/.ssh to see if I can log into the server by ssh -i pemfile mongodb#serveruri but it throws Permission denied (publickey). I'm inclined to following the best practices and would like to be able to launch the mongo daemon as mongodb.
To solve this, I had to change permissions on the data directory (and it's files) and the log path, like so -
cd /var/log
sudo chown -R mongodb:mongodb mongodb/
cd /
sudo chown -R mongodb:mongodb data/
Then I ran the command similar to 7171u's answer, i.e,
sudo -u mongodb mongod --fork --dbpath /data/ --logpath /var/log/mongodb/mongod.log
And the warning's gone!
Run commands as mangodb user do:
sudo -u mangodb mongod --fork --dbpath /somedbpath --logpath /somelogpath
Its good that you solved it on your own, but this is still not clear to you.
go through the below mentioned link, to understand the role of each user.
http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/
mongod user is the one which doesnot have a home directory, that's why not /home, and it also does not have a shell too. check your /etc/passwd file for the mongod user.
mongod:x:993:990:mongod:/var/lib/mongo:/bin/false
this is the default entry for the mongod user in the above mentioned file.
its home directory is /var/lib/mongo
and its shell is false.
I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem