Run mongo normally without configuration file

Hi,
I am currently running mongod 4.4 in CentOs 7. I first installed mongod and run with command
systemctl start monogd. After that to test replica set cluster I run mongod instance with config file with the command “mongod -f /etc/mongod.conf”. Now when I try to kill the running process and start mongd with the first option i.e. simply mongo and not with mongod -f /etc/mongod.conf, I am unable to do so.
How do I run mongo the mongo without config file?
Thanks

Why would you want to do so? There are enough options that you need a configuration file to reasonably start the system.

1 Like

And when you use systemctl to start mongod it’s being started with a configuration file.
So if it used to start that way and no longer does so, you must have changed something.
Or you’re not really stopping mongod when you think you have it stopped.

1 Like

for testing purposes before moving to a config file, you can pass almost all settings as parameters to mongod, including a test config file:
mongod — MongoDB Manual

you can use the same data folder (and other files) or create a new test folder for everything you need, and then you are good to go. do not use fork option if you want the server to stop when you close the terminal (or ctrl+C) else you have to repeat the sequence of killing from terminal or shutting down by logging into the server. to create multiple instances for the replica set, either use multiple terminals, or use the fork parameter but then do not forget to kill/shutdown them every time you need to refresh. (else you will have hard time to find out why it won’t start, and got frustrated when you realize the ports are in use by those forgotten forked instances).

PS: and you need to also remember to have the correct port when you run mongo shell, else you will have hard time to find out why your activity in the shell did not recorded in the database before realizing the activity was on the wrong instance

2 Likes

You should not do that. There are proper ways to terminate mongod. In there, pay particular attention to the sentence:

Never use kill -9 (i.e. SIGKILL ) to terminate a mongod instance.

You probably now have file permissions or ownership issues that you will have to clean-up manually.

Share the output of running the command

mongod

Alternatively, you may shared the content of the log file.

After that we might be able to find out what you have to clean.

2 Likes

Alright, I missed that part. systemctl runs mongod with its own user and group permission. this means “default” paths and files used in the config file are all set unreachable to other users in the system other than root. trying to start the server just by a single mongod command, if you are not root, or don’t use sudo, or don’t switch user to mongod, then your server will fail to start because of the permissions on those default resources.

for basic operations, you need to set --port, --dbpath and --logpath , and they should be different for each member of a replica set. create a test folder in your home and create the remaining paths in it.

2 Likes

Thank you all for your response. The problem is solved and I am running my replica set with config option and init script

For the benefit of all users of this forum, could you please share what was the underlying issue and how it was solve. This way others that stumble on a similar issue might be able to use your insight.

3 Likes

Actually there seems to be no problem at all. I just wanted my mongod to auto initiate whenever the server reboots or restarts. I am setting replica set cluster in my local environment using config file so whenever I reboot the system I had to manually start my mongod manually. Now using init script I am able to auto initiate mongod instance after the init script