Mongodb 3.4 on 64bit Ubuntu 16.04 mongodb-27017.sock ERROR - mongodb

There are a few posts related Mongodb 3.2, but when I attempted to install 3.4 the startup does not occur. Instead an unusual error appears in the log file (shown at the very end of the listing).
Is this perhaps because of an older version that was installed?
I did do an apt-get remove and purge.
Can anybody suggest why the error appears?
I followed the steps below, as outlined here,
$ sudo apt-get remove mongodb*
$ sudo apt-get purge mongodb*
$ sudo rm -rf /usr/lib/mongodb
$ sudo rm -rf /usr/log/mongodb
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
..
..
E: There were unauthenticated packages and -y was used without --allow-unauthenticated
$ sudo apt-get install mongodb-org # removed -y to get it going
..
..
Setting up mongodb-org (3.4.2) ...
$ sudo chown -R mongodb:mongodb /var/log/mongodb
$ sudo chown -R mongodb:mongodb /var/lib/mongodb # modified ownership in view of what is stated on the mongodb installation note
$ # created the following file
$ cat /etc/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Service 3.4
Wants=network.target
After=network.target
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
# startup
$ sudo systemctl daemon-reload
$ sudo service mongod start
# nothing happens, I then viewed the log file and the following error appears:
$ cat /var/log/mongodb/mongod.log
2017-02-08T22:08:26.155+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] MongoDB starting : pid=11384 port=27017 dbpath=/var/lib/mongodb 64-bit host=12g
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] db version v3.4.2
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] modules: none
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] build environment:
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] distarch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-02-08T22:08:26.178+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted

Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
That means the mongod process was started by root user.So you can just remove the sock file or run this command to fix this issue :
sudo chown `whoami` /tmp/mongodb-*.sock
Make sure that the port you assign needs to be accessible and not blocked by your firewall and then just restart the mongod process.
The waiting for connections message in the console output indicates
that the mongod.exe process is running successfully.
You can check out Install MongoDB Community Edition on Ubuntu.
Hope this helps.

#mcgraddy, thanks, that was helpful indeed. Creating the directory and copying the service file was the answer.
$ sudo cp /etc/systemd/system/mongod.service /etc/systemd/system/mongodb.service
$ sudo mkdir -p /data/db
$ sudo chown -R $USER:$USER /data
I had to change ownership for /data.
Starting the service and viewing status shows everything is running as expected:
$ sudo service mongod start
$ sudo systemctl status mongodb
● mongodb.service - MongoDB Database Service
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset:
Active: active (running) since Thu 2017-02-09 13:26:07 GMT; 9min ago
Main PID: 1184 (mongod)
CGroup: /system.slice/mongodb.service
└─1184 /usr/bin/mongod --quiet --config /etc/mongod.conf
Feb 09 13:26:07 systemd[1]: Started MongoDB Database Service.

Related

MonogDB 3.4 in Ubuntu 20.04

In the production application, we are using MongoDB 3.4 version.I have installed ubuntu 20.04 LTS on my local machine and tried to install Mongo 3.4 and bang my head against the wall. Please let me know your thoughts. Here are my steps:
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.com/apt/ubuntu "$(lsb_release -sc)"/mongodb-enterprise/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Well I just did this in a more "handmade way" perhaps...
Downloaded the application from here: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.24.tgz
(it is the, let's call vanila version from the mongodb page)
Uncompressed it on /opt:
tar zxf mongodb-linux-x86_64-3.4.24.tgz -C /opt/
Symlink for shorter name:
ln -s /opt/mongodb-linux-x86_64-3.4.24 /opt/mongo
Created the user for mongo:
useradd -r mongod
then added the systemctl command:
echo "[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongod
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/mongod.service
Reloaded systemctl:
systemctl daemon-reload
Then created the /etc/mongod.conf with the following content:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /opt/mongo/database/
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongod.log
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
#processManagement:
#security:
#operationProfiling:
#replication:
# replSetName: "mongodb-keys-replica-set"
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
then start the service:
systemctl start mongod
Adjust the configurations and directory path as needed.
It works, is a somehow handmade solution for a legacy version for that ubuntu version. Won't update with apt-get or related... but just works as it should.
If in local, for testing purposes, maybe it's not a bad idea go with a docker image... but just a suggestion, not the answer to your question.
The above answer is correct however don't forget to:
create directories and files, change owner
mkdir /opt/mongo/database
touch /var/log/mongod.log
chown mongod:mongod /var/log/mongod.log
chown -R mongod:mongod /opt/mongodb-linux-x86_64-3.4.24
chown mongod:mongod /opt/mongo
execute as root this part, link to mongo was wrong and should be as below:
echo "[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongod
ExecStart=/opt/mongo/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/mongod.service
There is no easy way for this it seems because the official documentation itself says that for version 3.4, the only supported ubuntu versions are 16.04 and 14.04 (https://docs.mongodb.com/v3.4/tutorial/install-mongodb-on-ubuntu/).
I tried following the above steps by ignivs but encountered this error everytime:
Failed to start mongod.service: Unit mongod.service not found.

mongod doesn't stop (docker debian:wheezy)

I have the following Dockerfile:
FROM debian:wheezy
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 main" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update
RUN apt-get install -y mongodb-org
Then I build the image:
docker build -t my/image .
and try to start and stop the server:
$ docker run -it my/image
root#35ba8193f979:/# service mongod start
[ ok ] Starting database: mongod.
root#35ba8193f979:/# service mongod stop
[FAIL] Stopping database: mongod failed!
As you can see, mongod fails to stop. I can verify this by running ps and grepping for the mongod process; it's still there.
Here's the logs:
root#fce8d9638ce4:/# cat /var/log/mongodb/mongod.log
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] MongoDB starting : pid=19 port=27017 dbpath=/var/lib/mongodb 64-bit host=fce8d9638ce4
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] db version v3.2.9
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] modules: none
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] build environment:
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] distmod: debian71
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] distarch: x86_64
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-09-20T05:01:02.893+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-09-20T05:01:03.087+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2016-09-20T05:01:03.087+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-09-20T05:01:03.156+0000 I NETWORK [initandlisten] waiting for connections on port 27017
I've googled for a solution already; most of the posts I find are very old, or don't describe the same problem as mine. Any help is greatly appreciated.
There appears to be an issue with service mongod stop since internally it calls a command which looks similar to:
start-stop-daemon --stop --pidfile /var/run/mongod.pid --user mongodb --exec /usr/bin/mongod
but the start-stop-daemon command somehow cannot find the executable /usr/bin/mongod, so it failed to stop the process. You can see the service script in /etc/init.d/mongod.
The solution that I found to be working is to call it without --exec directly from the command line:
start-stop-daemon --stop --pidfile /var/run/mongod.pid
and that seems to be able to stop the service properly.
I believe this issue is not limited to MongoDB, since I found multiple references about services not able to be stopped.

MongoDB 3.2.9 fails to start as a service on CentOS

I am trying to start mongod as a service on CentOS:
mongod --version
db version v3.2.9
git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
CentOS Linux release 7.2.1511 (Core)
/etc/selinux/config:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
mongod.conf:
systemLog:
destination: file
path: "/mnt/log/mongod.log"
logAppend: true
storage:
dbPath: "/mnt/data"
engine: wiredTiger
journal:
enabled: true
processManagement:
fork: true
pidFilePath: "/var/run/mongodb/mongod.pid"
net:
# bindIp: 127.0.0.1
port: 27017
replication:
replSetName: XXXX
security:
keyFile: "/usr/mongodb/mongodb-keyfile"
The issue states:
Starting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[FAILED]
journalctl -xe
...
Sep 20 13:10:55 ip-10-0-231-19.localdomain systemd[1]: Unit mongod.service entered failed state.
Sep 20 13:10:55 ip-10-0-231-19.localdomain systemd[1]: mongod.service failed.
Sep 20 13:10:55 ip-10-0-231-19.localdomain polkitd[9717]: Unregistered Authentication Agent for unix-process:26567:1630816 (system bus name :1.27, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Sep 20 13:11:04 ip-10-0-231-19.localdomain sudo[26587]: centos : TTY=pts/1 ; PWD=/home/centos ; USER=root ; COMMAND=/bin/vi /etc/mongod.conf
The server starts using:
sudo mongod -f /etc/mongod.conf
I know that there was a bug opened regarding similar issue but the fix might be available in 3.2.7 already and besides it was related to the scenario when SELINUX=enforcing...
Please support.
Recently encountered a similar problem, but on FC26; here, the problem could be traced back to SELINUX and specifically the permissions on the custom dbPath directory.
After trying many things, I found that the following sequence helped resolve my problem:
MONGODB_DATADIR=/mnt/data
sudo chown -R mongodb:mongodb $MONGODB_DATADIR
sudo chmod -R 700 $MONGODB_DATADIR
SELinux settings:
sudo semanage port -a -t mongod_port_t -p tcp 27017
sudo semanage fcontext -a -t mongod_var_lib_t ${MONGODB_DATADIR}
sudo semanage fcontext -a -t mongod_var_lib_t ${MONGODB_DATADIR}/mongod.lock
sudo restorecon -v ${MONGODB_DATADIR}
You probably also have to add mongod_log_t to the custom log file location, /mnt/log/mongod.log, I did not modify that one on my end.
Actually, for me the fix was:
sudo chown -R mongod:mongod $MONGODB_DATADIR

Unable to run mongod: Fatal Assertion 28562

Newbie here learning node.js and mongodb. I am currently trying to install mongodb on my Mac and faced the following issue when i try to run mongod on terminal.
2016-01-31T12:08:39.791+0800 I CONTROL [initandlisten] MongoDB starting : pid=13733 port=27017 dbpath=/data/db 64-bit host=Joshuas-MBP
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] db version v3.2.1
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] allocator: system
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] modules: none
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] build environment:
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] distarch: x86_64
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] target_arch: x86_64
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] options: {}
2016-01-31T12:08:39.794+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-01-31T12:08:47.249+0800 E STORAGE [initandlisten] WiredTiger (22) [1454213327:242370][13733:0x7fff72b68000], WT_SESSION.create: 'table:_mdb_catalog' cannot be used until all column groups are created: Invalid argument
2016-01-31T12:08:47.259+0800 I - [initandlisten] Fatal Assertion 28562
2016-01-31T12:08:47.259+0800 I - [initandlisten]
***aborting after fassert() failure
I have basically performed the following operations on terminal to install mongodb after looking through the docs and online tutorials:
joshuatan ~ $ brew update
joshuatan ~ $ brew install mongodb
joshuatan ~ $ sudo mkdir -p /data/db
joshuatan ~ $ whoami
joshuatan
joshuatan ~ $ sudo chown joshuatan /data/db
joshuatan ~ $ mongod
I have been searching around in google/stackoverflow but am not able to find any posts which have encountered a similar error.
Am i missing something? Would really appreciate any help/guidance...Thanks
The only thing that worked for me was (which was mac os)
rm -rf /tmp/mongodb-27017.soccd; cd /data/db; rm -rf *;
then just mongod to start it up
If you are on Catalina, like me, what seems to work is to create a properly placed data/db on System/Volumes/Data/data/db, with
sudo mkdir -p /System/Volumes/Data/data/db
sudo chown -R `id -un` /System/Volumes/Data/data/db
And, then, add that path to mongod.conf (located on /usr/local/etc/mongod.conf), replacing dbPath there:
...
storage:
dbPath: /System/Volumes/Data/data/db
...
Then, restart it. If you are using brew, do:
brew services restart mongodb-community
Source: https://zellwk.com/blog/install-mongodb/

Mongodb not able to start in Ubuntu 15.04

I have installed MongoDB 3.0.6 in Ubuntu 15.04 using the following commands.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
In the end in the installation process I got this:
Job for mongod.service failed. See "systemctl status mongod.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mongod, action "start" failed.
dpkg: error processing package mongodb-org-server (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up mongodb-org-mongos (3.0.6) ...
Setting up mongodb-org-tools (3.0.6) ...
dpkg: dependency problems prevent configuration of mongodb-org:
mongodb-org depends on mongodb-org-server; however:
Package mongodb-org-server is not configured yet.
dpkg: error processing package mongodb-org (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for systemd (219-7ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
mongodb-org-server
mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)
After that when I start the server using the below command I get an error and the server is not started.
sudo service mongod start
And the error is
Job for mongod.service failed. See "systemctl status mongod.service" and "journalctl -xe" for details.
Now when I run:
sudo systemctl status mongod.service
I get the following:
mongod.service - LSB: An object/document-oriented database
Loaded: loaded (/etc/init.d/mongod)
Active: failed (Result: exit-code) since Thu 2015-10-08 13:46:08 IST; 22s ago
Docs: man:systemd-sysv-generator(8)
Process: 6604 ExecStart=/etc/init.d/mongod start (code=exited, status=1/FAILURE)
Oct 08 13:46:07 gariya-GA-A55M systemd[1]: Starting LSB: An object/document-oriented database...
Oct 08 13:46:07 gariya-GA-A55M mongod[6604]: * Starting database mongod
Oct 08 13:46:08 gariya-GA-A55M mongod[6604]: ...fail!
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: mongod.service: control process exited, code=exited status=1
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: Failed to start LSB: An object/document-oriented database.
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: Unit mongod.service entered failed state.
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: mongod.service failed.
Someone please help, I am new to Ubuntu and MongoDB and I am not getting what is the problem.
There is a log file: /var/log/mongodb/mongod.log
In the log I've found the following:
Failed to unlink socket file /tmp/mongodb-27017.sock errno: Operation not permitted
Most probably this was from previous MongoDB version. I deleted the file (rm -rf /tmp/mongodb-27017.sock) and finished the installation:
apt-get install mongodb-org
Now it works. :-)
Recently i ended up with same issue and i tried all the possible solutions explained up here. But it didn't worked out for me. I was getting the below error.
# sudo service mongod restart
Restarting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details. [FAILED]
Eventually i figured out the solution which worked for me.
I went to /run/mongodb folder and deleted the file called mongod.pid. Then tried to restart the mongo using # sudo service mongod restart and it's worked!
My log said:
[initandlisten] Found an invalid index { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version"
so:
$cd /var/lib
$sudo rm -rf ./mongodb
$sudo mkdir mongodb
$sudo chown -R mongodb.mongodb mongodb/
$sudo service mongod restart
and then all worked fine.
sudo nano /etc/systemd/system/mongodb.service
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
sudo systemctl start mongodb
sudo systemctl status mongodb
sudo systemctl enable mongodb
Is job!
The first thing you should check is a mongodb log file located at /var/log/mongodb/mongod.log
Look for the line with status E containing words like 'failed', 'fatal', etc.
Make sure that the /data/db directory exists
Make sure your user have write privileges in that directory:
$ sudo chown id -u /data/db
Execute mongod
If you still have problems and if the file /data/db/mongod.lock exists, remove it and execute mongod --repair.
I removed the mongodb lock file-
sudo /data/db/mongod.lock
Then restarted the mongodb
sudo service mongod restart
This solved the issue.
I was having the same issue, after searching I got the answer that, when I executed
sudo service mongod restart
I changed the permissions from user mongodb to root of the database folder, so the service was not able to read the data.
So to solve I just reverted the permissions back to the user mongodb
sudo chown -R mongodb:mongodb /path-to-db-folder
sudo service mongod restart