MongoDB: installed MongoDB on windows as a service to use on WAMP doesnt use the conf file? - windows

I have installed MongoDB: mongodb-win32-x86_64-2012plus-4.2.5 as a service so I can use it with WAMP.
I am following this: http://blog.tejaspmehta.com/setup-mongodb-with-wamp/
Funny thing is: mongod is starting up looking for its default data position which is /data/db. Of which I dont have bc I installed it as a service. But I have specified in my install as a service to use the configuration file
My configuration file is this so far:
systemLog:
destination: file
path: "C:/wamp64/bin/mongodb/mongodb-win32-x86_64-2012plus-4.2.5/logs/mongodb.log"
logAppend: true
timeStampFormat: iso8601-local
net:
bindIp: 127.0.0.1
port: 27017
storage:
dbPath: "C:/wamp64/bin/mongodb/mongodb-win32-x86_64-2012plus-4.2.5/data/db"
directoryPerDB: true
When I manually created the data/db/ directory, the mongod runs fine.
When I delete the data/db/ directory the mongod shutsdown from the following error:
...
options: {}
exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
...
seems like the config file isnt working.

Related

Access a remote mongodb server

I have a ubuntu remote machine which I access using ssh and I have installed mongodb on it, and I wish to access it remotely using the uri of the mongodb which is
mongodb://<machine_ip_address>:27017/<database_name>
I have also tried to change the /etc/mongod.conf and the edited file is this:
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
journal:
enabled: true
processManagement:
fork: true
net:
bindIp: 127.0.0.1,my_ip
port: 27017
setParameter:
enableLocalhostAuthBypass: false
Is there a way I can give my local machine access to the remote server db by entering the uri of the remote server mongodb in my spring boot application?

How to run Mongodb as a service with authentication on a windows machine

remark: I am using win10.
My goal is when windows boot mongodb as a service with authentication start( you can not enter the database without authenticate) but I can not manage to do it on a windows machine ( in linux it worked)
I write here the steps I tried:
dowlnload MongoDB
change conf from default to the following
# mongod.conf
http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: C:\MongoDB\Server\4.0\data
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: C:\MongoDB\Server\4.0\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
security:
authorization: enabled
setParameter:
enableLocalhostAuthBypass: false
create a Admin user in the Admin collection.
db.createUser(
{
user: "....",
pwd: "...",
roles:
[
{ role: "root", db: "admin" }
]
}
)
Made it a service:
sc.exe create MongoDB
binPath=“\”C:\MongoDB\Server\4.0\bin\mongod.exe\”
–service
config=\”C:\MongoDB\Server\4.0\bin\mongod.cfg\”” DisplayName= “MongoDB” start= “auto”
getting feedback Successful.
but when i restart the computer, mongod is not starting and if i dont specify mongod --auth i can still enter without a authentication
How can I run Mongod as service with authentication? what am i doing wrong?
When i am trying to activate the service manually I get the following error
Error photo
The issue with the security tag. I have the same issue when I wanted to start the service in Windows 10. I copy the command from Windows service properties and then run on the command prompt.
The prompt shows me the error:
Unrecognized category : security
I found the solution and it is to write the security tag with options properly.
YAML need some specific input I guess. Here it is the solution.
security:
authorization: enabled
I had the same issue.
In your mongodb.cfg, use 2 spaces (instead of TAB) to indent authorization: enabled

How can I install two different versions of MongoDB and use them parallelly on Windows? [duplicate]

I am working with Mongo DB and I am a newbie to it. I am about to install it on a server specifically for Mongo.
I would like to create 2 instances of it - 1 to support a QA environment, the other to support a Staging Environment.
I am more familiar with SQL Server where I can create multiple instances.
Is it possible to do the same with Mongo DB and if so, how?
The aforementioned answer is not a recommended way to run multiple instances (especially when the servers might be running at the same time) as it will lead to usage of the same config parameters like for example logpath and pidfilepath which in most cases is not what you want.
Please, consider creating dedicated mongod configuration files like mongod-QA.conf and mongod-STAGE.conf. In these files you may want to provide dbpath, logpath folders, bind_ip, port and pidfilepath specific to each mongod instance and that will not affect each other.
After these steps you are good to trigger two instances as follows
mongod --config <path-to>/mongod-QA.conf
mongod --config <path-to>/mongod-STAGE.conf
You can find more details on mongodb docs page
You just need to create another folder(ex: mongodb2) dbpath for the second instance, and run it in a different port(ex: 27018)
mongod --dbpath /usr/local/var/mongodb2 --port 27018
Here is how I start 4 mongod's on the same pc to emulate production environment in development environment.
To start mongod you should use separate config for each mongod. Take 4 configs and start mongods using them:
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-primary1.cfg
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary1.cfg --rest
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary2.cfg
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary3.cfg
Configs look like this:
mongod-primary1.cfg file contents
systemLog:
destination: file
path: c:\net2\primary1-pc\data\log\mongod.log
storage:
dbPath: c:\net2\primary1-pc\data\db
net:
port: 27018
replication:
replSetName: repl1
mongod-secondary1.cfg file contents
systemLog:
destination: file
path: c:\net2\secondary1-pc\data\log\mongod.log
storage:
dbPath: c:\net2\secondary1-pc\data\db
net:
port: 27019
replication:
replSetName: repl1
mongod-secondary2.cfg file contents
systemLog:
destination: file
path: c:\net2\secondary2-pc\data\log\mongod.log
storage:
dbPath: c:\net2\secondary2-pc\data\db
net:
port: 27020
replication:
replSetName: repl1
mongod-secondary3.cfg file contents
systemLog:
destination: file
path: c:\net2\secondary3-pc\data\log\mongod.log
storage:
dbPath: c:\net2\secondary3-pc\data\db
net:
port: 27021
replication:
replSetName: repl1
It's possible - you would give each one its own port to listen on, and its own --dbpath directory to put its files in, but I wouldn't recommend this because they will both be competing for the same resources - RAM, i/o bandwidth, etc.
If you have multiple disks on this server you can place their data files on separate devices but you're still risking your QA instance reducing availability of the production instances, possibly at the worst possible time.
I would put QA instance on a random machine that's doing something unimportant before I would colocate it with my production instance.

Does Mongodb bindIp option accept dns name instead of ip with a port foward?

I have a structure like this:
I want to enable B to accept connection from A.
How can i configure it? I have this configuration in mongodb:
systemLog:
destination: file
path: C:\Program Files\MongoDB\Server\3.2\logs\mongod.log
storage:
dbPath: D:\db
net:
bindIp: 127.0.0.1,192.168.1.100, <can i mydomain1.com here??>
security:
authorization: enabled
keyFile: C:\Program Files\MongoDB\Server\3.2\keyfile-rs0.key
replication:
replSetName: rs0
My firewalls are enabled in both of servers and router.
I think that's a bind name problem!
Somebody have a solution?
I've solved this issue adding a rule in router mydomain1.com to get access from out side the net in a public port!

Windows 8.1 MongoDB 27017 errno: 10061 "Connection couldnt be made Target machine actively refuses it"

Full list of error:
C:\Program Files\MongoDB\Server\3.0\bin>mongo.exe
MongoDB shell version: 3.0.6
connecting to: test
2015-10-25T11:26:55.350+0200 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2015-10-25T11:26:55.353+0200 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
Service is running fine:
C:\Program Files\mongodb\Server\3.0\bin\mongod.exe --service --config D:\Documents\Work\mongodb\mongod.cfg
I saw already solutions here but nothing helped
netstat.exe -0 and netstat.exe -any dosen't show 27017 port as used by some App or process.
I have this mongod.cfg file
systemLog:
destination: file
path: D:\Documents\Work\mongodb\log\mongod.log
storage:
dbPath: D:\Documents\Work\mongodb\db
net:
bindIp: 127.0.0.1
port: 28018
But MongoDB still connects to same 27017 port
What i have missed?
The client does not know that you want to connect to a server on a non-default port.
Connect using the --port parameter:
mongo.exe --port 28018
Or just let the server listen on the default port.
Execute the following steps:
Go to control panel
Click program and features
Select mongodb
Right click
Repair it
Open your shell(cmd)
Type _ "C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe"
Enter
Done

Resources