I'm having issues connecting to my mongo shell. I can connect successfully when I remove all directives from my IPTables. CentOS 6.5, mongod is running. Here is the error I'm getting:
[samir#core ~]$ mongo 127.0.0.1:27017
MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:27017/test
Wed Mar 12 00:42:12.193 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
I also tried to start with just mongo.
Mongod is running:
[samir#core ~]$ sudo service mongod start
Starting mongod: about to fork child process, waiting until server is ready for connections.
forked process: 2104
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting
[ OK ]
The mongo log does not give any pointed either:
***** SERVER RESTARTED *****
Wed Mar 12 00:44:30.634 [initandlisten] MongoDB starting : pid=2104 port=27017 dbpath=/var/lib/mongo 64-bit host=core.datafit.io
Wed Mar 12 00:44:30.634 [initandlisten] db version v2.4.9
Wed Mar 12 00:44:30.634 [initandlisten] git version: 52fe0d21959e32a5bdbecdc62057db386e4e029c
Wed Mar 12 00:44:30.634 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed Mar 12 00:44:30.634 [initandlisten] allocator: tcmalloc
Wed Mar 12 00:44:30.634 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" }
Wed Mar 12 00:44:30.639 [initandlisten] journal dir=/var/lib/mongo/journal
Wed Mar 12 00:44:30.640 [initandlisten] recover : no journal files present, no recovery needed
Wed Mar 12 00:44:30.725 [FileAllocator] allocating new datafile /var/lib/mongo/local.ns, filling with zeroes...
Wed Mar 12 00:44:30.725 [FileAllocator] creating directory /var/lib/mongo/_tmp
Wed Mar 12 00:44:30.738 [FileAllocator] done allocating datafile /var/lib/mongo/local.ns, size: 16MB, took 0.011 secs
Wed Mar 12 00:44:30.738 [FileAllocator] allocating new datafile /var/lib/mongo/local.0, filling with zeroes...
Wed Mar 12 00:44:30.753 [FileAllocator] done allocating datafile /var/lib/mongo/local.0, size: 64MB, took 0.014 secs
Wed Mar 12 00:44:30.755 [initandlisten] waiting for connections on port 27017
Wed Mar 12 00:44:30.756 [websvr] admin web console waiting for connections on port 28017
My IPTables looks like this:
Chain INPUT (policy DROP 49 packets, 3315 bytes)
pkts bytes target prot opt in out source destination
1665 130K ACCEPT all -- eth0 any anywhere anywhere state RELATED,ESTABLISHED
2 128 ACCEPT tcp -- any any anywhere anywhere tcp dpt:ssh
0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:http
0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:https
18 1080 ACCEPT tcp -- any any anywhere anywhere tcp dpt:27017
0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:28017
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 987 packets, 156K bytes)
pkts bytes target prot opt in out source destination
If I set the INPUT directive to ACCEPT, mongo shell works:
[samir#core db]$ sudo mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
>
Netstat -pln | rep 27017:
[samir#core db]$ sudo netstat -pln | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 2178/mongod
unix 2 [ ACC ] STREAM LISTENING 12125 2178/mongod /tmp/mongodb-27017.sock
Something must be wrong with my iptables input policies. Any ideas?
You migth want to try, substituting the line
iptables -A INPUT -s 127.0.0.1 -j ACCEPT
With
iptables -A INPUT -i lo -j ACCEPT
Related
i'm trying to create a docker image run Mongodb on my Raspberry Pi 3+ with Raspbian buster. But when i build image and run container, mongodb doesn't auto start, so i add command RUN service mongod start then build image. Mongodb seems to be installed, i checked by service --status-all and mongodb listed but not started. Error come when docker try to start mongodb serive: The command '/bin/sh -c service mongod start' return a non-zero code: 1.
This is myDockerfile:
FROM cretzel/rpi-mongodb
WORKDIR /usr/src/mongodb
RUN chmod +x /var/lib/mongodb
RUN service mongod start
EXPOSE 27017
CMD ["mongod"]
I tried to fix this and be told that it doesn't have permission, so i add RUN chmod +x /var/lib/mongodb to my dockerfile but it don't work.
Can someone help?
---------------- Update from #Adiii's answer -----------------------------------
My new dockerfile:
FROM cretzel/rpi-mongodb
WORKDIR /usr/src/mongodb
COPY ./entrypoint.sh .
RUN chmod +x ./entrypoint.sh
VOLUME ./database /data/db
EXPOSE 27017
CMD ["mongod"]
entrypoint.sh
#!/bin/bash
service mongod start
exec "$#"
The change solved my error but mongodb service still cannot start. This is log file:
Starting database: mongodb failed!
db level locking enabled: 1
mongod --help for help and startup options
Mon Nov 11 16:31:15
Mon Nov 11 16:31:15 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Mon Nov 11 16:31:15
warning: some regex utf8 things will not work. pcre build doesn't have --enable-unicode-properties
Mon Nov 11 16:31:15 [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db/ 32-bit host=38271f34412b
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] ** NOTE: This is a development version (2.1.1-pre-) of MongoDB.
Mon Nov 11 16:31:15 [initandlisten] ** Not recommended for production.
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Mon Nov 11 16:31:15 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Mon Nov 11 16:31:15 [initandlisten] ** with --journal, the limit is lower
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] db version v2.1.1-pre-, pdfile version 4.5
Mon Nov 11 16:31:15 [initandlisten] git version: 47fbbdceb21fc2b791d22db7f01792500647daa9
Mon Nov 11 16:31:15 [initandlisten] build info: Linux raspberrypi 3.2.27+ #102 PREEMPT Sat Sep 1 01:00:50 BST 2012 armv6l BOOST_LIB_VERSION=1_49
Mon Nov 11 16:31:15 [initandlisten] options: {}
Mon Nov 11 16:31:15 [initandlisten] waiting for connections on port 27017
Mon Nov 11 16:31:15 [websvr] admin web console waiting for connections on port 28017
Mon Nov 11 16:32:15 [clientcursormon] mem (MB) res:20 virt:83 mapped:0
I don't understand Docker so much, it don't show any error. Please help!
You should not start the process at RUN command, each run command run at a separate shell and RUN is for installation and configuration not to start the process. To start the process in the container you need to start the process at entrypoint or CMD.
also, the container needs a process to run in foreground so service will not work in case of the container. so
EXPOSE 27017
CMD ["mongod"]
This is enough to start the mongo process, if the container is up and running it's mean mongod process is running, you do not need to check the status using service --status-all. as soon as MongoDB process dies container will die automatically.
Will suggest to use offical mongo docker image.
Running Fedora-27, I am trying to change the default directory of mongodb to a subdirectory of my home directory.
sudo dnf install mongodb-server
The version
[idf#localhost mongodb]$ mongod --version
db version v3.4.6
git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
OpenSSL version: OpenSSL 1.1.0g-fips 2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
[idf#localhost mongodb]$
I added myself to the mongodb group
[idf#localhost mongodb]$ sudo usermod -g mongodb idf
usermod: no changes
[idf#localhost mongodb]$
Without changing anything else, I change the file /etc/mongodb.conf so that dbPath points to the directory I created:
[idf#localhost mongodb]$ more /etc/mongod.conf
##
## For list of options visit:
## https://docs.mongodb.org/manual/reference/configuration-options/
##
# systemLog Options - How to do logging
systemLog:
# The default log message verbosity level for components (0-5)
verbosity: 0
# The destination to which MongoDB sends all log output (file|syslog, if not specifed to STDOUT)
destination: file
# Log file to send write to instead of stdout - has to be a file, not directory
path: /var/log/mongodb/mongod.log
# Append to logpath instead of over-writing (false by default)
logAppend: true
# Set the log rotation behavior (rename|reopen, rename by default)
logRotate: reopen
# processManagement Options - How the process runs
processManagement:
# Fork server process (false by default)
fork: true
# Full path to pidfile (if not set, no pidfile is created)
pidFilePath: /var/run/mongodb/mongod.pid
# net Options - Network interfaces settings
net:
# Specify port number (27017 by default)
port: 27017
# Comma separated list of ip addresses to listen on (all local ips by default)
bindIp: 127.0.0.1,::1
# Enable IPv6 support (disabled by default)
ipv6: true
unixDomainSocket:
# Enable/disable listening on the UNIX domain socket (true by default)
enabled: true
# Alternative directory for UNIX domain sockets (defaults to /tmp)
pathPrefix: /var/run/mongodb
#ssl:
# Set the SSL operation mode (disabled|allowSSL|preferSSL|requireSSL)
#mode: <string>
# PEM file for ssl
#PEMKeyFile: <string>
# Certificate Authority file for SSL
#CAFile: <string>
# storage Options - How and Where to store data
storage:
# Directory for datafiles (defaults to /data/db/)
#dbPath: /var/lib/mongodb
dbPath: /home/idf/mongodb
#journal:
# Enable/Disable journaling (journaling is on by default for 64 bit)
#enabled: true
# The storage engine for the mongod database (mmapv1|wiredTiger, wiredTiger by default
# - works for 64 bit only)
# Also possible to use unstable engines: devnull|ephemeralForTest
engine: wiredTiger
#mmapv1:
# Enable or disable the preallocation of data files (true by default)
#preallocDataFiles: <boolean>
# Use a smaller default file size (false by default)
#smallFiles: <boolean>
#wiredTiger:
#engineConfig:
# The maximum size of the cache that WiredTiger will use for all data
# (max(60% of RAM - 1GB, 1GB) by default)
#cacheSizeGB: 5
# The type of compression to use to compress WiredTiger journal data
# (none|snappy|zlib, snappy by default)
#journalCompressor: <string>
#collectionConfig:
# The default type of compression to use to compress collection data
# (none|snappy|zlib, snappy by default)
#blockCompressor: <string>
# secutiry Options - Authorization and other security settings
#security:
# Private key for cluster authentication
#keyFile: <string>
# Run with/without security (enabled|disabled, disabled by default)
#authorization
# setParameter Options - Set MongoDB server parameters
# setParameter:
# opratrionProfiling Options - Profiling settings
#operationProfiling:
# replication Options - ReplSet settings
#replication:
# sharding Options - Shard settings
#sharding:
I copy the contents of /var/lib/mongodb to my home directory and change the owner.
[idf#localhost mongodb]$ pwd
/home/idf/mongodb
[idf#localhost mongodb]$
Proof:
[idf#localhost mongodb]$ ls -la
total 252
drwxr-xr-x. 4 mongodb root 4096 Dec 22 19:27 .
drwx------. 44 idf idf 4096 Dec 22 19:27 ..
-rw-r--r--. 1 mongodb mongodb 32768 Dec 22 19:27 collection-0--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 collection-2--6927808756336873775.wt
drwxr-xr-x. 2 mongodb mongodb 4096 Dec 22 19:27 diagnostic.data
-rw-r--r--. 1 mongodb mongodb 32768 Dec 22 19:27 index-1--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 index-3--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 index-4--6927808756336873775.wt
drwxr-xr-x. 2 mongodb mongodb 4096 Dec 22 19:27 journal
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 _mdb_catalog.wt
-rw-r--r--. 1 mongodb mongodb 0 Dec 22 19:27 mongod.lock
-rw-r--r--. 1 mongodb mongodb 36864 Dec 22 19:27 sizeStorer.wt
-rw-r--r--. 1 mongodb mongodb 95 Dec 22 19:27 storage.bson
-rw-r--r--. 1 mongodb mongodb 49 Dec 22 19:27 WiredTiger
-rw-r--r--. 1 mongodb mongodb 4096 Dec 22 19:27 WiredTigerLAS.wt
-rw-r--r--. 1 mongodb mongodb 21 Dec 22 19:27 WiredTiger.lock
-rw-r--r--. 1 mongodb mongodb 993 Dec 22 19:27 WiredTiger.turtle
-rw-r--r--. 1 mongodb mongodb 53248 Dec 22 19:27 WiredTiger.wt
[idf#localhost mongodb]$ sudo systemctl start mongod
While I can start mongodb if the mongodb.conf file dbpath entry points to /var/lib, if I change dbpath to the directory that I duplicated on my home directory I get an error:
[idf#localhost mongodb]$ sudo systemctl start mongod
[sudo] password for idf:
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.
[idf#localhost mongodb]$
status gives more information, but I don't know what it means:
[idf#localhost mongodb]$ sudo systemctl status mongod
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2017-12-22 20:21:33 EST; 5s ago
Process: 9081 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=100)
Dec 22 20:21:33 localhost.localdomain systemd[1]: Starting High-performance, schema-free document-oriented database...
Dec 22 20:21:33 localhost.localdomain mongod[9081]: about to fork child process, waiting until server is ready for connections.
Dec 22 20:21:33 localhost.localdomain mongod[9081]: forked process: 9083
Dec 22 20:21:33 localhost.localdomain mongod[9081]: ERROR: child process failed, exited with error number 100
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Control process exited, code=exited status=100
Dec 22 20:21:33 localhost.localdomain systemd[1]: Failed to start High-performance, schema-free document-oriented database.
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Unit entered failed state.
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Failed with result 'exit-code'.
[idf#localhost mongodb]$
The log file give interesting information [the line Unable to determine status of lock file in the data directory], but I don't know how to resolve it to, since I duplicated the permissions and ownership from /var/lib/mongod directory:
2017-12-22T20:30:16.716-0500 I CONTROL [main] ***** SERVER RESTARTED *****
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] MongoDB starting : pid=9483 port=27017 dbpath=/home/idf/mongodb 64-bit host=localhost.localdomain
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] db version v3.4.6
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g-fips 2 Nov 2017
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] allocator: tcmalloc
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] modules: none
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] build environment:
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] distarch: x86_64
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] target_arch: x86_64
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] options: { command: [ "run" ], config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,::1", ipv6: true, port: 27017, unixDomainSocket: { enabled: true, pathPrefix: "/var/run/mongodb" } }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/home/idf/mongodb", engine: "wiredTiger" }, systemLog: { destination: "file", logAppend: true, logRotate: "reopen", path: "/var/log/mongodb/mongod.log", verbosity: 0 } }
2017-12-22T20:30:16.722-0500 I STORAGE [initandlisten] exception in initAndListen: 28596 Unable to determine status of lock file in the data directory /home/idf/mongodb: boost::filesystem::status: Permission denied: "/home/idf/mongodb/mongod.lock", terminating
2017-12-22T20:30:16.722-0500 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-12-22T20:30:16.722-0500 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] now exiting
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] shutting down with code:100
EDIT 1
If I run mongod "by hand" [not using service ...], it works in my data directory. Bizarre...
[idf#localhost mongodb]$ sudo mongod --dbpath /home/idf/mongodb/
Can you check how SELinux is configured on your system?
sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
If SELinux is in enforcing mode, enable access to the relevant port:
sudo semanage port -a -t mongod_port_t -p tcp 27017
Try to set it to permissive:
setenforce permissive
this will survive until the next reboot, to make it permanent, edit /etc/selinux/config
if Mongo server run on port 65500.
Now on which port, I can access simple HTTP rest ?
Let a case,
MongoDB provides a simple http interface listing information of interest to administrators. This interface may be accessed at the port with numeric value 1000 more than the configured mongod port.
if MongoDB runs on localhost with port number 65500.
Then which port does Mongo rest interface run?
Port no. 66500 is not possible value for port
Port numbers are only 16 bits, so mongod will fail to even start on that port (greater than 65535)
> mongod --port 65555 --dbpath .
Sat Mar 29 13:00:31.488 bad --port number
Sat Mar 29 13:00:31.488 dbexit:
Sat Mar 29 13:00:31.488 shutdown: going to close listening sockets...
If you really mean an allowed port that would just make the web port go above 65536, it will wrap around to 0 (which would mean 65535+1000 would wrap to 999, or your new sample port 65500 would wrap to 964);
Sat Mar 29 13:01:53.448 [initandlisten] waiting for connections on port 65500
Sat Mar 29 13:01:53.448 [websvr] ERROR: listen(): bind() failed errno:13
Permission denied for socket: 0.0.0.0:964
I installed MondoDB on my Ubuntu 13.04 and tried to run its daemon by typing in either mongod or sudo mongod, but I encountered the following message:
mongod --help for help and startup options
Thu Jun 27 05:11:02 [initandlisten] MongoDB starting : pid=11685 port=27017 dbpath=/data/db/ 64-bit host=myhost
Thu Jun 27 05:11:02 [initandlisten] db version v2.2.4, pdfile version 4.5
Thu Jun 27 05:11:02 [initandlisten] git version: nogitversion
Thu Jun 27 05:11:02 [initandlisten] build info: Linux batsu 3.2.0-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49
Thu Jun 27 05:11:02 [initandlisten] options: {}
Thu Jun 27 05:11:02 [initandlisten] journal dir=/data/db/journal
Thu Jun 27 05:11:02 [initandlisten] recover : no journal files present, no recovery needed
Thu Jun 27 05:11:02 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Thu Jun 27 05:11:02 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:28017
Thu Jun 27 05:11:02 [websvr] ERROR: addr already in use
Thu Jun 27 05:11:02 [initandlisten] ERROR: addr already in use
Thu Jun 27 05:11:02 [initandlisten] now exiting
Thu Jun 27 05:11:02 dbexit:
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to close listening sockets...
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to flush diaglog...
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to close sockets...
Thu Jun 27 05:11:02 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jun 27 05:11:02 [initandlisten] shutdown: lock for final commit...
Thu Jun 27 05:11:02 [initandlisten] shutdown: final commit...
Thu Jun 27 05:11:02 [initandlisten] shutdown: closing all files...
Thu Jun 27 05:11:02 [initandlisten] closeAllFiles() finished
Thu Jun 27 05:11:02 [initandlisten] journalCleanup...
Thu Jun 27 05:11:02 [initandlisten] removeJournalFiles
Thu Jun 27 05:11:02 [initandlisten] shutdown: removing fs lock...
Thu Jun 27 05:11:02 dbexit: really exiting now
However, when I tried to run MongoDB by typing mongo even without running its daemon, it seems that I can use MongoDB successfully. I don't start any daemon and also I have only one window in my terminal, so it would be impossible to run both daemon and main mongo program at the same time...
So the question is, why I can use MongoDB without starting any daemon process? When I use MongoDB on OS X, I always have to run daemon before using MongoDB. For your information I installed Ubuntu 13.04 via Parallels 8 on my OS X 10.8 and installed MongoDB by going with the same route as an official document explains.
Or since I use MongoDB on my OS X at port 27017, I don't have to run daemon on Virtual Ubuntu? (though I don't run daemon on OS X right now...)
When you installed mongo, it should already have run the server for you.
This is confirmed by both the fact that it says "addr already in use" (which means something is running on the mongod port) and the fact that you can use it successfully.
You can also test this by running ps wuax | grep mongo and looking for mongod in the resulting list - this list all the processes running on your computer, and then removes from this list anything that doesn't mention mongo. You may also see a line which has "grep" in it - this is the command you are currently running, which you can ignore.
When I run this on my computer, it shows:
mongodb 22394 9.1 1.0 109244 33592 ? Dsl 08:29 0:01 /usr/bin/mongod --config /etc/mongodb.conf
1001 22423 0.0 0.0 9436 904 pts/3 S+ 08:29 0:00 grep --color=auto mongo
Mongod service is running, try to stop it and init mongod with sudo command
sudo service mongodb stop
sudo mongod
Start mongod Processes
By default, MongoDB stores data in the /data/db directory. On Windows, MongoDB stores data in C:\data\db. On all platforms, MongoDB listens for connections from clients on port 27017.
To start MongoDB using all defaults, issue the following command at the system shell:
mongod
Stop mongod Processes
In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files.
To ensure a clean shutdown, always shutdown mongod instances using one of the following methods:
Use shutdownServer()
Shut down the mongod from the mongo shell using the db.shutdownServer() method as follows:
use admin
db.shutdownServer()
Calling the same method from a init script accomplishes the same result.
For systems with authorization enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.
Use --shutdown
From the Linux command line, shut down the mongod using the --shutdown option in the following command:
mongod --shutdown
I'm new to MongoDB, and I'm trying to run mongod. If I type in mongo, I can run the shell (and then I exit nicely with ^C), but when I try typing mongod, I get this:
mongod --help for help and startup options
Sat Nov 24 13:42:34 [initandlisten] MongoDB starting : pid=99910 port=27017 dbpath=/data/db/ 64-bit host=Macbook-err.local
Sat Nov 24 13:42:34 [initandlisten]
Sat Nov 24 13:42:34 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Sat Nov 24 13:42:34 [initandlisten] db version v2.2.1, pdfile version 4.5
Sat Nov 24 13:42:34 [initandlisten] git version: nogitversion
Sat Nov 24 13:42:34 [initandlisten] build info: Darwin 172-26-13-128.dynapool.nyu.edu 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Sat Nov 24 13:42:34 [initandlisten] options: {}
Sat Nov 24 13:42:34 [initandlisten] journal dir=/data/db/journal
Sat Nov 24 13:42:34 [initandlisten] recover : no journal files present, no recovery needed
Sat Nov 24 13:42:34 [websvr] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:28017
Sat Nov 24 13:42:34 [websvr] ERROR: addr already in use
Sat Nov 24 13:42:34 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
Sat Nov 24 13:42:34 [initandlisten] ERROR: addr already in use
Sat Nov 24 13:42:34 [initandlisten] now exiting
Sat Nov 24 13:42:34 dbexit:
Sat Nov 24 13:42:34 [initandlisten] shutdown: going to close listening sockets...
Sat Nov 24 13:42:34 [initandlisten] shutdown: going to flush diaglog...
Sat Nov 24 13:42:34 [initandlisten] shutdown: going to close sockets...
Sat Nov 24 13:42:34 [initandlisten] shutdown: waiting for fs preallocator...
Sat Nov 24 13:42:34 [initandlisten] shutdown: lock for final commit...
Sat Nov 24 13:42:34 [initandlisten] shutdown: final commit...
Sat Nov 24 13:42:34 [initandlisten] shutdown: closing all files...
Sat Nov 24 13:42:34 [initandlisten] closeAllFiles() finished
Sat Nov 24 13:42:34 [initandlisten] journalCleanup...
Sat Nov 24 13:42:34 [initandlisten] removeJournalFiles
Sat Nov 24 13:42:34 [initandlisten] shutdown: removing fs lock...
Sat Nov 24 13:42:34 dbexit: really exiting now
This seems to be a common problem around here, and I've tried:
deleting the mongod.lock file rm /data/db/mongod.lock
repair: mongod --repair
killing processes: killall -15 mongod and killall -9 mongod
I tried changing permissions: sudo chmod 0755 /data/db and sudo chown $USER /data/db
My permissions seem correct:
drwxr-xr-x 4 slaffont wheel 136 Nov 24 13:28 /data/db/
I've run out of ideas. Has anyone else had this problem? What should I do? :(
From your main comments, it seems you installed MongoDB via macports (given the /opt install location). What I believe might be happening is that the recipe for macports installed MongoDB as a launchd service.
Check this location for a mongodb related plist file: /Library/LaunchDaemons
If you find it, that means your system will automatically keep this service running. If you only want to run the mongod manually, then remove this plist and reboot. Or you can try this command:
launchctl unload /Library/LaunchDaemons/path.to.mongo.plist
Otherwise, run another instance of mongod on a different port.
sudo rm /var/lib/mongodb/mongod.lock
sudo chown -R mongodb:mongodb /var/lib/mongodb/
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
or instead of the last one try : sudo mongod
"Address already in use for socket: 0.0.0.0:28017"
It looks like mongo is already running or another process is using port 27017
In this case, type the following command
ps wuax | grep mongo
You should see something that looks like this
User 31936 0.5 0.4 2719784 35624 ?? S 7:34pm 0:09.98 mongod
User 31945 0.0 0.0 2423368 184 s000 R+ 8:24pm 0:00.00 grep mongo
Now enter the kill command for the mongod instance (31936 in this case):
kill 31936
It looks like something is already bound to port 27017, making it seem like another mongod is running (that was not killed on the killall). Does the output of ps aux or lsof -i :27017 show any mongod processes running?
If this proves completely fruitless, you can always pass the --port <portnum> option to the mongod process via the command line, telling it to listen on a different port (use the same option for the mongo shell to tell it to connect on a different port than 27017.
As #shelman said, you already have something using that port, however your command to understand if something is running is wrong, try:
sudo netstat -lpn |grep :27017
I have noticed as well:
Sat Nov 24 13:42:34 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
This is more of an warning but still one you should heed. I answered a question with some one who had this problem recently: Mongod runs, but Mongo returns an error that should help.
Since this seems to be a common question:
As someone who just had/solved this problem, what you're probably running into is this. When you first install Mongo (say, via apt-get), the Mongod process automatically starts running. For example:
terekhov / $ sudo apt-get install mongodb-10gen
--Snip Install Process--
Done. mongodb
start/running, process 4467 Processing triggers for ureadahead ...
terekhov / $ service mongodb start start: Job is already running: mongodb
So, if you don't need a forked daemon etc, then just type mongo to start the command shell; it will automatically search for a MongoDB daemon on port 27017. Happily, that's where ours is.
You can start/stop/restart the mongod process with this command: sudo service mongodb stop