Created mongod replication Set but fail to connect - mongodb

I have created mongoDB replication set using this command:
F:\data>mongod --replSet set1 --dbpath 1 --port 27101
--oplogSize 50 --logpath log.1 --logappend --fork
It does not recognize --fork and it is not there in --help as well (I guess) so I have excluded it and got following output. I think there is nothing wrong so far.
all output going to: log.1
Then when I try to use mongo console using this command
F:\data>mongo --port 27101
It returns
MongoDB shell version: 2.2.2
connecting to: 127.0.0.1:27101/test
Thu Feb 14 01:36:33 Error: couldn't connect to server 127.0.0.1:27101 src/mongo/
shell/mongo.js:93
exception: connect failed
Now what can be done to make it work?

Actually I in the parameter I had this data path --dbpath 1 so I need to have a directory named '1' in my current directory but I had created it in data directory by misunderstanding.
Thankyou #Alptigin Jalayr and others who has lead me to the correct direction.

Related

Docker run returning exit code 100 or 51

When I try to run my mongoDB image called database with sudo docker run -p 27017:27017 I get exitCode 100. I looked at some info online and found this about exitCode 100: Returned by mongod when the process throws an uncaught exception. I've had this issue before and was able to fix it with docker system prune --force but when i do it now I get the same exitCode.
I have tried building the image again but when I do that I either get the same exitCode or exitCode 51, of which I can't find any info online.
Any idea how I can fix this?
EDIT: I am working on an Ubuntu server vm and it has worked before.
Content of my Dockerfile:
From mongo:latest
COPY usertoevoegen.js /docker-entrypoint-initdb.d/
RUN mongod --fork --logpath /var/log/mongodb.log --dbpath /data/db
Content of usertoevoegen.js:
db=db.getSiblingDB('admin');
db.createUser({user: "admin",pwd: "admin123",roles: [{ role: "root", db: "admin" }]});
db.createCollection("gebruiker");
db.gebruiker.insert([{"naam" : "Toon"}]);
Apparently I didn't have enough storage left on my server which caused the error.

Configure a Replica Set in local and on a cloud-server

I'm trying to configure a Replica Set with 2 members in local e 1 member on a cloud-server.
I started the two instance from local in this way:
mongod --port 27117 --dbpath mongodb/rs0-0 --logpath mongodb/rs0-0/mongo.log --replSet rs0 --fork
mongod --port 27118 --dbpath mongodb/rs0-1 --logpath mongodb/rs0-1/mongo.log --replSet rs0 --fork
and then I started the instance on my cloud-server (after opened the port):
mongod --port 27119 --dbpath mongoRS/rs0-2 --logpath mongoRS/rs0-2/mongo.log --replSet rs0 --fork
So, I started the server to configure the Replica Set:
mongo --port 27117
rsconf = {
_id: "rs0",
members: [{
_id: 0,
host: "localhost:27117"
}]
}
rs.initiate( rsconf )
rs.add("localhost:27118")
Until now all was correct. But when I tryed to add the server-instance a error occurred:
rs.add("myServer.it:27119")
"errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 2 out of 3",
So I'm thinking that I cannot set this configuration or what?
While trying to add different member in a replSet, you should avoid using localhost(specially when your servers are located at different environments).
Please try below options:
Remove existing replSet member: rs.remove("localhost:27118")
Try to add the server back with host ip(Local Server IP): rs.add("your_server_IP:27118")
Add the cloud server with Public IP: rs.add("Cloud_server_public_IP:27119")
Also ensure 27117,27118 and 27119 ports are opened from both Localhost and Cloud server.
Thanks,
Deep

Can't start mongoDB as a service

I'd like to run mongoDB as a service. The instance shall be configured as a single-node replicaset to be able to connect a elasticSearch instance to it with a the connector.
So I extended the mongod.conf:
...
replication:
replSetName: "singleNodeRepl"
...
I tried different ways to start now the mongod, but nothing works.
When I try to start the service by $ service mongod start, following error is thrown:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.106" (uid=1225 pid=26018 comm="start mongod ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
When I execute this command as sudo (whats not best-practise, right?), its "running" and following message is shown:
mongod start/running, process 26034
But process 26034 doesn't exist and ps aux | grep mongo also shows nothing?!
Next try: Run it as a normal application
mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl
Here following exception is shown:
2016-04-08T14:31:35.192+0200 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-04-08T14:31:35.192+0200 I CONTROL [initandlisten] dbexit: rc: 100
Everything is fine when I run ~$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl, but thats not my target: Its not running as a service and its running as root.
The mongod-logfile often keeps untouched. But the last lines are curious:
2016-04-08T14:24:56.242+0200 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-04-08T14:24:56.242+0200 I - [initandlisten] Fatal Assertion 28578
2016-04-08T14:24:56.242+0200 I - [initandlisten]
***aborting after fassert() failure
A mongodb-27017.sock existed, but deleting (what was suggested anywhere) didn't help.
Based on the erros above if tried serveral solutions, but nothing helps.
I think it's a very simple mistake...but which one?
[edit:]
I discovered, that I perhaps should have specified the config-location. So the (working but bad) command looks like:
$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl --config /etc/mongod.conf
This brings following error:
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
Thats an old thing, which was the solution for this problem and suddenly doesn't work anymore!?
I've had issues stopping and starting mongod as a service. Turns out there was an issue with the upsart script.
I found this discussion which seemed to fix it.
The suggested solution was pretty much: (copy pasting now)
vim /etc/init.d/mongod
look for stop() function (and start() function for good measure) and remove quotes around $PIDFILE in the following line.
killproc -p $PIDFILE -d 300 /usr/bin/mongod
Do this:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
Let me know if this doesn't work!

unable to connect to mongodb on localhost

I have installed MongoDB:
user#user-workshop:~$ sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 7980
user#user-workshop:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Mon Mar 3 21:43:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
user#user-workshop:~$
but as you can see, I'm unable to connect to it. What can I do about it?
Try running these commands:
rm /data/db/mongod.lock
mongod --dbpath /data/db --repair
mongod --dbpath /data/db
For more details read: mongodb manual

Error 109 when stopping Mongo DB running as a service (1.6.1)

I'm running Mongo DB as windows service and every second time I stop the service it reports "Error 109: The pipe has been ended". Here is the command line being used to run the service
"C:\Temp\mongodb\bin\mongod" --service --serviceUser --servicePassword --dbpath C:\temp\db --rest --logpath C:\temp\db\log\mongo.log --logappend --directoryperdb
This bug was fixed for version 2.1.0 ( https://jira.mongodb.org/browse/SERVER-2833 ) and then resurfaced ( https://jira.mongodb.org/browse/SERVER-6771 ). Hopefully it will be fixed again for version 2.2.0.