mongodb cant start centos 7 - mongodb

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.

Related

How to make mongodb listen on specific IP in Azure VM with Ubuntu 18.04?

I got the MongoDB (4.0.10) running on Azure VM with Ubuntu 18.04 using default localhost. Now, I want to add my IP address to bindIp in /etc/mongod.conf so that I can access the db from my machine. Based on document (also from this example), I just need to append it to bindIp line after a comma.
net:
port: 27017
bindIp: 127.0.0.1,70.123.39.234
ipv6: true
(Note, I added ipv6 based on my reading of the document, but it doesn't seem to have any effect).
However, it doesn't work for me because service fails to start. I got something like this:
$ sudo service mongod restart
$ sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-06-10 15:59:35 UTC; 2s ago
Docs: https://docs.mongodb.org/manual
Process: 8140 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=48)
Main PID: 8140 (code=exited, status=48)
Jun 10 15:59:35 mllinux systemd[1]: Started MongoDB Database Server.
Jun 10 15:59:35 mllinux systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Jun 10 15:59:35 mllinux systemd[1]: mongod.service: Failed with result 'exit-code'.
I tried many ways like
bindIp: 127.0.0.1, 70.123.39.234
or
bindIp: "127.0.0.1,70.123.39.234"
or
bindIp: "127.0.0.1, 70.123.39.234"
I got the same error.
However if I use space instead of comma like
bindIp: 127.0.0.1 70.123.39.234
or
bindIp: "127.0.0.1 70.123.39.234"
Service seems to start ok because
$ sudo service mongod restart
$ sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-06-10 16:37:39 UTC; 3s ago
Docs: https://docs.mongodb.org/manual
Main PID: 14629 (mongod)
CGroup: /system.slice/mongod.service
└─14629 /usr/bin/mongod --auth --config /etc/mongod.conf
Jun 10 16:37:39 mllinux systemd[1]: Started MongoDB Database Server.
However, I still cannot connect to it from my laptop.
For testing, if I set
bindIp: 0.0.0.0
or
bindIpAll: true
Then, I can connect to it from my laptop.
What did I do wrong?
UPDATE: Appending db log
2019-06-10T02:52:27.682+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2019-06-10T02:52:27.684+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] MongoDB starting : pid=3757 port=27017 dbpath=/var/lib/mongodb 64-bit host=mllinux
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] db version v4.0.10
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] modules: none
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] build environment:
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] distarch: x86_64
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,70.123.39.234", port: 27017 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, security: { authorizatio$2019-06-10T02:52:27.697+0000 E STORAGE [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] now exiting
2019-06-10T02:52:27.697+0000 I CONTROL [initandlisten] shutting down with code:48
2019-06-10T02:53:53.313+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2019-06-10T02:53:53.315+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] MongoDB starting : pid=3934 port=27017 dbpath=/var/lib/mongodb 64-bit host=mllinux
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] db version v4.0.10
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] modules: none
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] build environment:
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] distarch: x86_64
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-06-10T02:53:53.324+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1 70.123.39.234", port: 27017 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, security: { authorizatio$2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten]
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-06-10T02:53:53.325+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1448M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=jou$2019-06-10T02:53:54.146+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:146511][3934:0x7fe345319a40], txn-recover: Main recovery loop: starting at 2/6656 to 3/256
2019-06-10T02:53:54.249+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:249632][3934:0x7fe345319a40], txn-recover: Recovering log 2 through 3
2019-06-10T02:53:54.317+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:317186][3934:0x7fe345319a40], txn-recover: Recovering log 3 through 3
2019-06-10T02:53:54.366+0000 I STORAGE [initandlisten] WiredTiger message [1560135234:366900][3934:0x7fe345319a40], txn-recover: Set global recovery timestamp: 0
2019-06-10T02:53:54.485+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten]
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-06-10T02:53:54.504+0000 I CONTROL [initandlisten]
2019-06-10T02:53:54.515+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2019-06-10T02:53:54.517+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2019-06-10T02:56:27.392+0000 I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2019-06-10T02:56:27.392+0000 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...
2019-06-10T02:56:27.392+0000 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2019-06-10T02:56:27.395+0000 I CONTROL [signalProcessingThread] Shutting down free monitoring
2019-06-10T02:56:27.395+0000 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture
2019-06-10T02:56:27.397+0000 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down
2019-06-10T02:56:27.397+0000 I STORAGE [signalProcessingThread] Shutting down session sweeper thread
2019-06-10T02:56:27.397+0000 I STORAGE [signalProcessingThread] Finished shutting down session sweeper thread
2019-06-10T02:56:27.558+0000 I STORAGE [signalProcessingThread] shutdown: removing fs lock...
2019-06-10T02:56:27.558+0000 I CONTROL [signalProcessingThread] now exiting
2019-06-10T02:56:27.558+0000 I CONTROL [signalProcessingThread] shutting down with code:0
You cannot use bindip to limit access from the outside to the mongodb. bindip selects the desired server listen IPs, not the client IPs.
If you only want to be able to connect to the server from your IP address, you should use the Network Security Group feature of Azure. It is more secure than handling it via the software installed on the VM, since traffic does not even reach the VM.
For your issue, you should know what does the three IPs mean and then you will know what you need to do as you wish.
First one: 127.0.0.1
This IP is just for the test inside the machine, it cannot access outside. It's just a loop IP.
Second one: 0.0.0.0
Then this IP is set, then you can access outside and also can access inside. It means the localhost for all the application in this machine, no matter inside or outside.
Third one: private IP
This is the IP assigned in your private network, not the public IP. For example, it means the IP 192.168.1.100 in the document you provide. And for the Azure VM, it means the private IP assigned from the subnet. But it only works when you access this IP.
So, in your question, if you want to access both outside and inside. Then you can set the bind IP in the simplest way:
0.0.0.0
private IP
Note: do not forget to expose the port in the NSG associated with your Azure VM. If you do not have a special requirement, I will suggest you bind the IP 0.0.0.0, it's the best way.

Unable to run MongoDB server when using multiple IP addresses in bindIp configuration Option in Mongod version 3.6.5

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.

Change directory of mongodb server data directory

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

Mongo database critical issue

We've got an emergency situation regarding a production website which had just been released. We just got hit by a heavy DDoS-attack and servers got overloaded by requests. Once the attack had stopped, we've restarted the server with the database and we noticed that the 'WiredTiger.wt' file had just disappeared and that Mongo no longer works. I'm wondering what could we do to restore the database and have Mongo running back, taking into account that the 'WiredTiger.wt' file is missing ?
We've got an instance which has it's MONGO_URL set to another instance where we have the database (here's where the DDoS-attack happened).
Here are some logs that you could check:
When I try on the database server to connect "mongo NAME_OF_DATABASE":
MongoDB shell version: 3.2.11
connecting to: NAME_OF_DATABASE
Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
When I check the logs "mongo log /var/log/mongodb/mongod.log":
2017-04-04T11:05:18.252+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2017-04-04T11:05:18.255+0000 I CONTROL [initandlisten] MongoDB starting : pid=2716 port=27017 dbpath=/var/lib/mongodb 64-bit host=ip-xxx-xxx-xxx-xxx
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] db version v3.2.11
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] git version: 009580ad490190ba33d1c6253ebd8d91808923e4
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] modules: none
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] build environment:
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] distarch: x86_64
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-04-04T11:05:18.256+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27017 }, security: { authorization: "enabled" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-04-04T11:05:18.279+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2017-04-04T11:05:18.279+0000 I - [initandlisten] Fatal Assertion 28578
2017-04-04T11:05:18.279+0000 I - [initandlisten]
When I run "sudo service mongodb status":
mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2017-04-04 11:51:06 UTC; 8s ago
Process: 1384 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=14)
Main PID: 1384 (code=exited, status=14)
Apr 04 11:51:06 ip-172-31-42-103 systemd[1]: Started High-performance, schema-free document-oriented database.
Apr 04 11:51:06 ip-172-31-42-103 systemd[1]: mongodb.service: Main process exited, code=exited, status=14/n/a
Apr 04 11:51:06 ip-172-31-42-103 systemd[1]: mongodb.service: Unit entered failed state.
Apr 04 11:51:06 ip-172-31-42-103 systemd[1]: mongodb.service: Failed with result 'exit-code'.
Thank you!

MongoDB centos7 unable to run with a non standard port as a service

I installed mongodb on a fresh centos 7
I run sudo service mongod start without any problem
When I change the port in /etc/mongod.conf and I restart the mongod service I get the following error
From /var/log/mongodb/mongod.log
2014-11-11T07:38:29.495+0000 [initandlisten] MongoDB starting : pid=12401 port=27022 dbpath=/var/lib/mongo 64-bit host=awscm001
2014-11-11T07:38:29.495+0000 [initandlisten] db version v2.6.5
2014-11-11T07:38:29.495+0000 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-11T07:38:29.495+0000 [initandlisten] build info: Linux build8.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
2014-11-11T07:38:29.495+0000 [initandlisten] allocator: tcmalloc
2014-11-11T07:38:29.495+0000 [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27021 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2014-11-11T07:38:29.497+0000 [initandlisten] journal dir=/var/lib/mongo/journal
2014-11-11T07:38:29.497+0000 [initandlisten] recover : no journal files present, no recovery needed
2014-11-11T07:38:29.679+0000 [initandlisten] ERROR: listen(): bind() failed errno:13 Permission denied for socket: 0.0.0.0:27022
2014-11-11T07:38:29.680+0000 [initandlisten] now exiting
2014-11-11T07:38:29.680+0000 [initandlisten] dbexit:
2014-11-11T07:38:29.680+0000 [initandlisten] shutdown: going to close listening sockets...
2014-11-11T07:38:29.680+0000 [initandlisten] shutdown: going to flush diaglog...
I am able though to run with a different port with the following command
sudo mongod -f /etc/mongod.conf
When I run as a service user mongod runs mongodb
When I run from command line root runs mongodb
How can run the mongodb service with a different port?
By the way I succeeded on centos 6.5
Thanks
for those people having problem like me.. my fix is allow mongodb custom port on semanage
semanage port --list | grep mongo
mongod_port_t tcp 27017-27019, 28017-28019
as you can see, only 27017-27019, 28017-28019 is allowed.
in order to add a custom port for mongodb
semanage port -a -t mongod_port_t -p tcp 21010
you now have added the custom port
semanage port --list | grep mongo
mongod_port_t tcp 21010, 27017-27019, 28017-28019
make sure to restart mongodb