4

I can start MongoDB as $sudo service mongod start. When I start without sudo it gives me this error:

/etc/init.d/mongod: line 58: ulimit: open files: cannot modify limit: Operation not permitted
/etc/init.d/mongod: line 60: ulimit: max user processes: cannot modify limit: Operation not permitted
Starting mongod: runuser: may not be used by non-root users

1) Now, I've changed ownership to the non root user on all mongo directores I could find i.e. /var/lib/mongo, var/log/mongodb, data/db, var/run/mongodb

$sudo chown -R nonRootUser:nonRootUser [directory]

2) I've deleted mongod.lock files

3) I've run --repair too

It still gives me the same error.

I also tried

$mongod --fork --logpath /var/log/mongodb.log

about to fork child process, waiting until server is ready for connections.
forked process: 18566
ERROR: child process failed, exited with error number 1

mongod.log file says this:

2016-03-17T15:03:49.053+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
2016-03-17T15:03:54.144+0000 I CONTROL  [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends

It's Amazon Linux. I am able to start it like this $mongod, but I want to run it as daemon so it runs continuously.

The nonRootUser is a new user I created in addition to ec2-user. Maybe there are some config issues relating to running daemon processes if you're not ec2-user?

UPDATE: Changed ownership on everything to ec2-user, still getting exactly the same errors as before.

3

You mention that you used the rpm installer for installing MongoDB on the Amazon Linux AMI. When you do this, the mongod user is created on the system and all of the appropriate files are created and owned by the mongod user. When starting MongoDB installed by the rpm, the command must either be run by root or run using sudo. This is because the init script must execute a change user command so the mongod process can be forked as a child of the mongod user.

Failure to use root or sudo to start the service results in the errors you quoted above.

/etc/init.d/mongod: line 58: ulimit: open files: cannot modify limit: Operation not permitted
/etc/init.d/mongod: line 60: ulimit: max user processes: cannot modify limit: Operation not permitted
Starting mongod: runuser: may not be used by non-root users

So, in order to run as a service, you must use sudo or root. There is no simple way around this except granting the mongod user a shell, assigning it a password, logging in as that user, then running the service. This will still result in errors attempting to modify the ulimits and is generally not recommended.

To start MongoDB without running it as a service, since you used the rpm, the mongod binary should be in your path, so the following should work

mongod --dbpath /path/to/data --logpath /path/to/mongod.log --fork

Note that doing this will run it as the currently logged in user, that means all of the data files as well as mongod.log must be writable by that user. Ideally, these files should be owned by that user.

2

After changing permissions on directories and files don't forget to log out and log back in.

I can't still run it as

$ service mongod start

it can only be run as root.

But alternatively you can run it as daemon like this:

 $ mongod --fork --logpath to/logpath

Just to be on the safe side I created data/log directory for logpath. And yes you can create other users in addition to ec2-user on Amazon Linux and they can also run mongodb

1

Another alternative is to use the tarball instead of an installer:

  1. download from https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz (use wget)

  2. extract (tar xaf mongodb-linux...tgz) and move to other directory optionally

  3. create data dir (mkdir ~/data)

  4. start as mongod --dbpath ~/data --fork

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.