2
votes

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.

3
We need more information to debug this. Anything from the mongodb log file?jaxxstorm

3 Answers

2
votes

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
0
votes

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:

0
votes

I also ran into that on CentOS 7 and mongodb 3.4. Here's how I solved it:

  1. 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

  1. Don't forget to set firewall rules and reload:

firewall-cmd --zone=public --permanent --add-port=27017/tcp; firewall-cmd --reload

  1. Follow log file and restart:

tail -f /var/log/mongodb/mongod.log &

systemctl restart mongod; systemctl status mongod

  1. 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.