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
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.
I am trying to use multiple IP addresses in the bindIp configuration option and after saving the configuration changes, the mongodb server won't start. The same thing is working in MongoDB version 3.4
Here is the configuration settings:
# network interfaces
net:
port: 36784
bindIp: 127.0.0.1,10.0.0.226
Here 10.0.0.226 is the private IP address of the EC2 instance.
The same type of configuration was working in earliers versions of MongoDB more specifically in v3.4
If I use bindIp to 0.0.0.0, then of course it allows remote connections to all the IP addresses.
Once i restart the server, i am getting the following error:
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2018-06-25 05:36:45 UTC; 15s ago
Docs: https://docs.mongodb.org/manual
Process: 1570 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=48)
Main PID: 1570 (code=exited, status=48)
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: Stopped High-performance, schema-free document-oriented database.
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: Started High-performance, schema-free document-oriented database.
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: mongod.service: Unit entered failed state.
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: mongod.service: Failed with result 'exit-code'.
Here is the logs files content:
2018-06-25T05:07:38.842+0000 I CONTROL [initandlisten] now exiting
2018-06-25T05:07:38.842+0000 I CONTROL [initandlisten] shutting down with code:48
2018-06-25T05:13:43.192+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] MongoDB starting : pid=1390 port=36784 dbpath=/var/lib/mongodb 64-bit host=ip-10-0-1-69
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] db version v3.6.5
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] allocator: tcmalloc
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] modules: none
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] build environment:
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] distarch: x86_64
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] target_arch: x86_64
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,10.0.0.226", port: 36784 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2018-06-25T05:13:43.201+0000 E STORAGE [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] now exiting
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] shutting down with code:48
I have gone through the official docs and could not find any deprecation notices.
what might be the issue?
Thank you
When I understand this line from the log correctly
2018-06-25T05:13:43.201+0000 I CONTROL [initandlisten] MongoDB starting : pid=1390 port=36784 dbpath=/var/lib/mongodb 64-bit host=ip-10-0-1-69
the host's ip is 10.0.1.69 and not 10.0.0.226. That would explain the error.
I installed mongodb on Centos 7 and all works fine.
But if I reboot the system, mongodb can't start anymore. If I uninstall and install again, works fine. But after reboot, cant start anymore.
When I try systemctl status mongod.service shows:
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Dom 2016-11-27 09:49:36 BRT; 12min ago
Docs: https://docs.mongodb.org/manual
Process: 1471 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=1/FAILURE)
Main PID: 1471 (code=exited, status=1/FAILURE)
Nov 27 09:49:19 localhost.localdomain systemd[1]: Started High-performance, schema-free document-oriented database.
Nov 27 09:49:19 localhost.localdomain systemd[1]: Starting High-performance, schema-free document-oriented database...
Nov 27 09:49:36 localhost.localdomain mongod[1471]: about to fork child process, waiting until server is ready for connections.
Nov 27 09:49:36 localhost.localdomain mongod[1471]: forked process: 2828
Nov 27 09:49:36 localhost.localdomain mongod[1471]: ERROR: child process failed, exited with error number 1
Nov 27 09:49:36 localhost.localdomain systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
Nov 27 09:49:36 localhost.localdomain systemd[1]: Unit mongod.service entered failed state.
Nov 27 09:49:36 localhost.localdomain systemd[1]: mongod.service failed.
I already tried:
*chcon -R -t mongod_var_lib_t /var/lib/mongo
*SElinux=disable
*chmod 7777 /var/lib/mongo
and nothing.
I remember when this error appeared before I format my pc, I needed to put permission on systemd with a simple command. But I cant find anymore.
here is the official bug report
https://jira.mongodb.org/browse/SERVER-27241
in
/usr/lib/systemd/system/mongod.service
update the systemd service with the following, till they fix it officially
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=--quiet -f /etc/mongod.conf"
PermissionsStartOnly=true
ExecStartPre=/usr/bin/mkdir /var/run/mongodb
ExecStartPre=/usr/bin/chown -R mongod:mongod /var/run/mongodb
ExecStart=/usr/bin/mongod $OPTIONS run
PIDFile=/var/run/mongodb/mongod.pid
I remove and reinstall Mongodb 3.4
The server started with: sudo systemctl start mongod.service, and started ok.
Here's the /var/log/mongodb/mongod.log
2016-11-27T13:23:03.600-0300 I CONTROL [main] ***** SERVER RESTARTED
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] MongoDB
starting : pid=8247 port=27017 dbpath=/var/lib/mongo 64-bit
host=localhost.localdomain
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] db version
v3.4.0-rc5
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] git version:
7df8fe1099135d137516f1670d2a0091ace63ca0
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] OpenSSL
version: OpenSSL 1.0.1e-fips 11 Feb 2013
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] allocator:
tcmalloc
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] modules: none
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] build
environment:
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] distmod:
rhel70
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] distarch:
x86_64
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten]
target_arch: x86_64
2016-11-27T13:23:03.612-0300 I CONTROL [initandlisten] options: {
command: [ "run" ], config: "/etc/mongod.conf", net: { bindIp:
"127.0.0.1", port: 27017 }, processManagement: { fork: true,
pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath:
"/var/lib/mongo", journal: { enabled: true } }, systemLog: {
destination: "file", logAppend: true, path:
"/var/log/mongodb/mongod.log", quiet: true } }
2016-11-27T13:23:03.971-0300 I - [initandlisten] Detected data
files in /var/lib/mongo created by the 'wiredTiger' storage engine,
so setting the active storage engine to 'wiredTiger'.
2016-11-27T13:23:03.971-0300 I STORAGE [initandlisten]
wiredtiger_open config:
create,cache_size=1329M,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-11-27T13:23:05.036-0300 I CONTROL [initandlisten]
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten] ** WARNING:
Access control is not enabled for the database.
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten] **
Read and write access to data and configuration is unrestricted.
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten]
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten]
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten] ** WARNING:
/sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten] ** We
suggest setting it to 'never'
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten]
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten] ** WARNING:
/sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten] ** We
suggest setting it to 'never'
2016-11-27T13:23:05.036-0300 I CONTROL [initandlisten]
2016-11-27T13:23:05.061-0300 I FTDC [initandlisten] Initializing
full-time diagnostic data capture with directory '/var/lib/monenter
code herego/diagnostic.data'
2016-11-27T13:23:05.061-0300 I NETWORK [thread1] waiting for
connections on port 27017
When i reboot the sytem, Mongodb wont start again.
Heres the log:
logAppend: true path: /var/log/mongodb/mongod.log
*# Where and how to store data.
2016-11-27T13:30:27.927-0300 I CONTROL [main] ***** SERVER RESTARTED
2016-11-27T13:30:28.279-0300 I CONTROL [main] ERROR: Cannot write pid
file to /var/run/mongodb/mongod.pid: No such file or directory
Here is my /etc/mongod.conf
storage:
dbPath: /var/lib/mongo
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
*# network interfaces net: port: 27017 bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
*# security:
*# operationProfiling:
*# replication:
*# sharding:
*## Enterprise-Only Options
*# auditLog:
*# snmp:
I also ran into that on CentOS 7 and mongodb 3.4. Here's how I solved it:
Edit /etc/mongod.conf file and change fork to false and pidFilePath to the same as dbPath (which for me is /var/lib/mongo):
/etc/mongod.conf:
storage:
dbPath: /var/lib/mongo
processManagement:
fork: false # fork and run in background
pidFilePath: /var/lib/mongo/mongod.pid # location of pidfile
net:
port: 27017
bindIp: 0.0.0.0
Don't forget to set firewall rules and reload:
firewall-cmd --zone=public --permanent --add-port=27017/tcp; firewall-cmd --reload
Follow log file and restart:
tail -f /var/log/mongodb/mongod.log &
systemctl restart mongod; systemctl status mongod
You should see in last line of log file:
NETWORK [thread1] waiting for connections on port 27017
It worked for me, I rebooted the system and I could connect to mongo straight away.
Previously mongodb was located at /var/lib/mongod. I've moved this to /home/mongod, and updated the /etc/mongod.conf file to point to this location. The permissions of the folder look correct:
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:37 admin
-rw-------. 1 mongod mongod 67108864 Aug 6 11:49 admin.0
-rw-------. 1 mongod mongod 16777216 Aug 6 11:49 admin.ns
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:40 journal
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:37 local
-rw-------. 1 mongod mongod 67108864 Aug 6 11:49 local.0
-rw-------. 1 mongod mongod 16777216 Aug 6 11:49 local.ns
-rwxr-xr-x. 1 mongod mongod 0 Aug 6 11:50 mongod.lock
-rwxrwxr-x. 1 mongod mongod 0 Aug 6 10:12 mongod.lock.bak
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:37 sphere
-rw-------. 1 mongod mongod 67108864 Aug 6 11:50 sphere.0
-rw-------. 1 mongod mongod 134217728 Aug 6 11:49 sphere.1
-rw-------. 1 mongod mongod 268435456 Aug 6 11:49 sphere.2
-rw-------. 1 mongod mongod 536870912 Aug 6 11:49 sphere.3
-rw-------. 1 mongod mongod 1073741824 Aug 6 11:50 sphere.4
-rw-------. 1 mongod mongod 2146435072 Aug 6 11:50 sphere.5
-rw-------. 1 mongod mongod 16777216 Aug 6 11:50 sphere.ns
drwxr-xr-x. 2 mongod mongod 6 Aug 6 11:50 _tmp
and when I run from the command line it works:
[user#localhost home]$ sudo -u mongod mongod --dbpath /home/mongod
[sudo] password for user:
2015-08-06T12:04:35.761+0100 [initandlisten] MongoDB starting : pid=10235 port=27017 dbpath=/home/mongod 64-bit host=localhost.localdomain
2015-08-06T12:04:35.762+0100 [initandlisten] db version v2.6.10
2015-08-06T12:04:35.762+0100 [initandlisten] git version: 5901dbfb49d16eaef6f2c2c50fba534d23ac7f6c
2015-08-06T12:04:35.762+0100 [initandlisten] build info: Linux build18.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-08-06T12:04:35.762+0100 [initandlisten] allocator: tcmalloc
2015-08-06T12:04:35.762+0100 [initandlisten] options: { storage: { dbPath: "/home/mongod" } }
2015-08-06T12:04:35.772+0100 [initandlisten] journal dir=/home/mongod/journal
2015-08-06T12:04:35.773+0100 [initandlisten] recover : no journal files present, no recovery needed
2015-08-06T12:04:36.865+0100 [initandlisten] waiting for connections on port 27017
However running the using systemctl fails:
sudo service mongod restart
Restarting mongod (via systemctl): Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.
[FAILED]
The /etc/mongod.conf file is as follows
logpath=/var/log/mongodb/mongod.log
logappend=true
# fork and run in background
fork=true
#port=27017
dbpath=/home/mongod
# location of pidfile
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1
The output in /var/log/mongod/mongod.log is as follows:
2015-08-06T12:08:35.402+0100 ***** SERVER RESTARTED *****
2015-08-06T12:08:35.407+0100 [initandlisten] MongoDB starting : pid=10370 port=27017 dbpath=/home/mongod 64-bit host=localhost.localdomain
2015-08-06T12:08:35.407+0100 [initandlisten] db version v2.6.10
2015-08-06T12:08:35.407+0100 [initandlisten] git version: 5901dbfb49d16eaef6f2c2c50fba534d23ac7f6c
2015-08-06T12:08:35.407+0100 [initandlisten] build info: Linux build18.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-08-06T12:08:35.407+0100 [initandlisten] allocator: tcmalloc
2015-08-06T12:08:35.407+0100 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/home/mongod" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-08-06T12:08:35.407+0100 [initandlisten] exception in initAndListen std::exception: boost::filesystem::status: Permission denied: "/home/mongod/local.ns", terminating
2015-08-06T12:08:35.407+0100 [initandlisten] dbexit:
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: going to close listening sockets...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: going to flush diaglog...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: going to close sockets...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: waiting for fs preallocator...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: lock for final commit...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: final commit...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: closing all files...
2015-08-06T12:08:35.407+0100 [initandlisten] closeAllFiles() finished
2015-08-06T12:08:35.407+0100 [initandlisten] dbexit: really exiting now
I've tried deleting the lock file /home/mongod/mongod.lock and running a repair with sudo -u mongod mongod --dbpath /home/mongod --repair but the error still persists. This is causing major headaches!!
So it turns out the problem was SElinux, and the solution is the same as this question.
It was permission related and is due to the SELinux security context which is set to enforced by default on CentOS.
sudo ausearch -m avc -ts today | audit2allow
On my machine I had some mongo related audits as follows:
#============= mongod_t ==============
allow mongod_t home_root_t:file getattr;
allow mongod_t user_home_dir_t:dir search;
allow mongod_t var_lib_t:lnk_file read;
allow mongod_t default_t:file getattr;
To fix the above, you do the following:
sudo chcon -Rv --type=mongod_var_lib_t /path_to_your_mongo
Where /path_to_your_mongo is where your mongod data files are located (in my case /home/mongod but often /var/lib/mongo or /data/db.
I've just installed MongoDB via Homebrew, and I'm trying to get it up and running. I've launched it using mongodin the command line, and now I'm trying to get into the shell by using the command mongo once it is running. However, nothing happens when I run the command. Here is a paste of my log:
Fri Sep 6 16:54:02.458 [initandlisten] MongoDB starting : pid=17731 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=lsadmin’s-MacBook-Pro
Fri Sep 6 16:54:02.458 [initandlisten]
Fri Sep 6 16:54:02.458 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Fri Sep 6 16:54:02.458 [initandlisten] db version v2.4.6
Fri Sep 6 16:54:02.458 [initandlisten] git version: nogitversion
Fri Sep 6 16:54:02.458 [initandlisten] build info: Darwin minimountain.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/ RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Fri Sep 6 16:54:02.458 [initandlisten] allocator: tcmalloc
Fri Sep 6 16:54:02.458 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log" }
Fri Sep 6 16:54:02.458 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Fri Sep 6 16:54:02.459 [initandlisten] recover : no journal files present, no recovery needed
Fri Sep 6 16:54:02.543 [websvr] admin web console waiting for connections on port 28017
Fri Sep 6 16:54:02.543 [initandlisten] waiting for connections on port 27017
Fri Sep 6 16:55:02.552 [PeriodicTask::Runner] task: WriteBackManager::cleaner took: 14ms
And this is a paste of my config file:
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 127.0.0.1
And a paste of command line:
-> mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
mongo
Running a second shell and then running ./mongo in /usr/local/cellar/mongodb/2.4.6/ allowed me access to the shell.
Obvious solution, but documentation makes it seem like you can run it from the mongod prompt.