Monday, January 29, 2018

Run MongoDB Server using Config file – Linux

Run MongoDB Server using Config file – Binary Installation

  • When doing a binary installation of MongoDB, there won’t be any config files configured automatically when this happens in .rpm or yum installer. 
  • So in this case, we need to configure config files manually. Here am gonna show an example, how to run mongo server using config file for the binary installation done in the previous post.


Ex config file: 


We have to mention the port_no, db_path and log_path in the config file as mentioned above,

For this example, am gonna save this config file to the path,

/home/ec2-user/mongod.conf

# vi mongod.conf

net:
  port: 27019
operationProfiling: {}
processManagement:
  pidFilePath: /var/run/mongodb/mongod.pid
  fork: "true"
storage:
  dbPath: /home/ec2-user/mongo_data
systemLog:
  destination: file
  logAppend: true
  logRotate: rename
  path: /home/ec2-user/mongo_log/mongod.log

# :wq

Here in the config file, we are using –

Port : 27019
dbPath: /home/ec2-user/mongo_data
logpath: /home/ec2-user/mongo_log/mongod.log

To start the server,

If environmental variable is set then,

# mongod -f /home/ec2-user/mongod.conf

else,

# <bin path>/mongod -f /home/ec2-user/mongod.conf


As we had set the environmental variable,


The server has started, as we forked the process – it’s not showing the logs like where the port is listening an al. ( fork: "true” )

To check the process,

# ps aux | grep mongo


To start the Client,

Just type in mongo and port no in the same command line and don’t need to open another, as we forked the process. ( we need to mention the port no, as we have changed the default port no to 27019)

# mongo --port 27019


Done…

1 comment:

  1. hi .. can we run mongodb service as mongod user. and avoid using root

    ReplyDelete