CentOS 5.x Linux with MongoDB 2.0.1 (tried main and legacy-static)
MongoDB is running:
root 31664 1.5 1.4 81848 11148 ? Sl 18:40 0:00 ./mongod -f mongo.conf -vvvvv --fork
Using a simple shell connect to get to the server fails:
[root#xxxx bin]# ./mongo
MongoDB shell version: 2.0.1
connecting to: test
Mon Oct 31 18:41:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
The web interface on port 28017 loads fine, as does using the MongoDB shell from a remote Linux host. Can also telnet to localhost:27017, which means no ports are blocked. There is no SELinux running on this machine as well. I have also tried explicitly specifying localhost:2017/db to no avail.
$ ./mongo remote-ip:27017
MongoDB shell version: 2.0.1
connecting to: remote-ip:27017/test
> show dbs
local 0.03125GB
>
Logs are completely mum on the subject:
.....
Mon Oct 31 18:40:34 [initandlisten] fd limit hard:1024 soft:1024 max conn: 819
Mon Oct 31 18:40:34 [initandlisten] waiting for connections on port 27017
Mon Oct 31 18:40:34 BackgroundJob starting: snapshot
Mon Oct 31 18:40:34 BackgroundJob starting: ClientCursorMonitor
Mon Oct 31 18:40:34 BackgroundJob starting: PeriodicTask::Runner
Mon Oct 31 18:40:34 [websvr] fd limit hard:1024 soft:1024 max conn: 819
Mon Oct 31 18:40:34 [websvr] admin web console waiting for connections on port 28017
Stracing the mongo shell client shows only one problematic call:
[pid 31708] connect(4, {sa_family=AF_INET, sin_port=htons(27017), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EBADF (Bad file descriptor)
Filesystem is clean, no ulimit restrictions (running as root for testing). I can see from the strace that the mongo client is trying to connect via TCP (AF_INET), but since it is local and MongoDB creates a file socket, is there a way to tell the client to connect through that instead? Or better yet, why would the client be throwing a EBADF?
EDIT: My basic Mongo conf:
dbpath=/root/mongodb-linux-i686-2.0.1/data
logpath=/root/mongodb-linux-i686-2.0.1/logs/mongo.log
slowms=15
rest=1
I think there is some default config what is missing in this version of mongoDb client. Try to run:
mongo 127.0.0.1:27017
It's strange, but then I've experienced the issue went away :) (so the simple command 'mongo' w/o any params started to work again for me)
[Ubuntu Linux 11.10 x64 / MongoDB 2.0.1]
You may want to check your config to see if the bind_ip is set
bind_ip: 127.0.0.1
If it is then this permits only local logins. Comment this out and restart mongo, this may help.
I had a similar problem, well actually the same (mongo process is running but can't connect to it).
What I did was went to my database path and removed mongod.lock, and then gave it another try (restarted mongo). After that it worked.
Hope it works for you too.
mongodb repair on ubuntu
I had same problem. In my case MongoDB server wasn't running.
Try to open this in your web browser:
http://localhost:28017
If you can't, this means that you have to start MongoDB server.
Run mongod in another terminal tab.
Then in your main tab run mongo which is is the shell that connects to your MongoDB server.
Delete /var/lib/mongodb/mongod.lock, then issue sudo service mongodb start, then mongo.
Open the file /etc/mongod.conf and add the ip of the machine from where you are connecting, to bind_ip
bind_ip = 127.0.0.1,your Remote Machine Ip Address Here
Ex:-
bind_ip = 127.0.0.1,192.168.1.5
Restart mongodb service:
sudo service mongod restart
Make sure mongodb port is opened in the firewall.
You can also comment the line, if you are not worried about security.
I had this problem as well. Is your MongoDB journaling?
I noticed the following "preallocate" entries in the log file.
Once I saw the last line "waiting for connections on port", I could connect.
Notice that this "faster" mode took 12 minutes to intialize.
William
Tue Apr 17 16:48:01 [initandlisten] MongoDB starting : pid=2248 port=27017 dbpath=E:\MongoData 64-bit host=ME
Tue Apr 17 16:48:01 [initandlisten] db version v2.0.0-rc0, pdfile version 4.5
Tue Apr 17 16:48:01 [initandlisten] git version: 8d4bf50111352cee5a4f1abf25b63442d6c45dc4
Tue Apr 17 16:48:01 [initandlisten] build info: windows (6, 1, 7601, 2, 'Service Pack 1') BOOST_LIB_VERSION=1_42
Tue Apr 17 16:48:01 [initandlisten] options: { bind_ip: "ip", dbpath: "E:\MongoData", directoryperdb: true, journal: true, logpath: "E:\MongoData\mongo.log", quiet: true, rest: true, service: true }
Tue Apr 17 16:48:01 [initandlisten] journal dir=E:/MongoData/journal
Tue Apr 17 16:48:01 [initandlisten] recover : no journal files present, no recovery needed
Tue Apr 17 16:48:02 [initandlisten] preallocateIsFaster=true 9.68
Tue Apr 17 16:48:04 [initandlisten] preallocateIsFaster=true 8.44
Tue Apr 17 16:48:06 [initandlisten] preallocateIsFaster=true 9.68
Tue Apr 17 16:48:06 [initandlisten] preallocateIsFaster check took 4.921 secs
Tue Apr 17 16:48:06 [initandlisten] preallocating a journal file E:/MongoData/journal/prealloc.0
Tue Apr 17 16:52:37 [initandlisten] preallocating a journal file E:/MongoData/journal/prealloc.1
Tue Apr 17 16:56:54 [initandlisten] preallocating a journal file E:/MongoData/journal/prealloc.2
Tue Apr 17 17:01:42 [initandlisten] waiting for connections on port 27017
Tue Apr 17 17:01:42 [websvr] admin web console waiting for connections on port 28017
By default, mongodb is configured to listen only to localhost. Excerpt from mongodb default config file :
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1
One needs to comment the bind_ip to listen from external entities.
You wont be able to add shards unless you start listening on non-local interfaces.
HTH,
Abhay Dandekar
This is actually not an error... What happens here is that Mongo relies on a daemon in order to run the local database server, so in order to "fire up" the mongo server in your shell, you have to start the mongo service first.
For Fedora Linux (wich is the Distro I use) You have to run these commands:
1 sudo service mongod start
2 mongo
And there you have it! the server is going to run. Now, If you want Mongo service
to Start when the system boots then you have to run:
sudo chkconfig --levels 235 mongod on
And that's all! If you do that, now in the shell you just have to type mongo in order
to start the server but that's pretty much it, the problem is you have to start the SERVICE first and then the SERVER :)
P.S. The commands I posted might work on other linux distros as well, not just in fedora... In case not maybe you have to tweak some words depending on the distro you're using ;)
Facing the same issue with the error described by Garrett above.
1. MongoDB Server with journaling enabled is running as seen using ps command
2. Mongo client or Mongoose driver are unable to connect to the database.
Solution :
1. Deleting the Mongo.lock file seems to bring life back to normal on the CentOS server.
2. We are fairly new in running MongoDB in production and have been seeing the same issue cropping up a couple of times a week.
3. We've setup a cron schedule to regularly cleanup the lock file and intimate the admin that an incident has occurred.
Searching for a bug fix to this issue or any other more permanent way to resolve it.
If your bind_ip is set to anything other than 127.0.0.1 then you'll need to add the ip explicitly even from the local machine. So simply use the same method that you're using on the remote box on the local box. At least that's what did it for me.
Not so much an answer but more of an FYI:I've just hit this and found this question as a result of searching. Here is the details of my experience:
Shell error
markdsievers#ip-xx-xx-xx-xx:~$ mongo
MongoDB shell version: 2.0.1
connecting to: test
Wed Dec 21 03:36:13 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
Wed Dec 21 03:36:13 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [1] server [127.0.0.1:27017]
Wed Dec 21 03:36:13 DBClientCursor::init call() failed
Wed Dec 21 03:36:13 Error: Error during mongo startup. :: caused by :: DBClientBase::findN: transport error: 127.0.0.1 query: { whatsmyuri: 1 } shell/mongo.js:84
exception: connect failed
Mongo logs reveal
Wed Dec 21 03:35:04 [initandlisten] connection accepted from 127.0.0.1:50273 #6612
Wed Dec 21 03:35:04 [initandlisten] connection refused because too many open connections: 819
This perhaps indicates the other answer (JaKi) was experiencing the same thing, where some connections were purged and access made possible again for the shell (other clients)
I don't see this having an accepted answer yet, so I'll just add my 2 cents.
I had the exact same issue just now. After a while I realized I've locked localhost out in my iptables rules. So, check your firewall.
On Ubuntu:
Wed Jan 27 10:21:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
Solution
look for if mongodb is running by following command:
ps -ef | grep mongo
If mongo is not running you get:
vimal 1806 1698 0 10:11 pts/0 00:00:00 grep --color=auto mongo
You are seeing that the mongo daemon is not there.
Then start it through configuration file(with root priev):
root#vimal:/data# mongod --config /etc/mongodb.conf &
[1] 2131
root#vimal:/data# all output going to: /var/log/mongodb/mongodb.log
you can see the other details:
root#vimal:~# more /etc/mongodb.conf
Open a new terminal to see the result of mongod --config /etc/mongodb.conf &
then type mongo. It should be running or grep
root#vimal:/data# ps -ef | grep mongo
root 3153 1 2 11:39 ? 00:00:23 mongod --config /etc/mongodb.conf
root 3772 3489 0 11:55 pts/1 00:00:00 grep --color=auto mongo
NOW
root#vimal:/data# mongo
MongoDB shell version: 2.0.4
connecting to: test
you get the mongoDB shell
This is not the end of story. I will post the repair method so that it starts automatically every time, most development machine shutdowns every day and the VM must have mongo started automatically at next boot.
After starting the mongod
$mongod --dbpath <db name>
to get shell
$mongo --shell
If your mongoDB server(remote server)'s version is greater then 4.0.3, then you will face this issue. Hence you should replace your current mongo-client shell with below mongo :
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Then you mongo client will be able to connect your remove mongodb
If you are getting the following message
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.84" (uid=1000 pid=3215 comm="start mongodb ") 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")
shriprasad#shriprasad-HP-430-Notebook-PC:/var/lib/mongodb$ mongo
You must be trying to start the mongodb service as user other than root. You must be root user. Thus log in as root and then run following command as follows:
sudo bash
followed by
service mongodb start
Related
I try to run a Linux docker container with some X11 clients.
The host is Mac, with xQuartz installed.
It is started using -v /tmp/.X11-unix:/tmp/.X11-unix
I see a /tmp/.X11-unix/X0 file in the container.
srwxrwxrwx 1 developer developer 0 Mar 28 05:26 X0
and in the host
srwxrwxrwx 1 username wheel 0 Mar 28 10:56 X0
The uid is the same, the gid is different for the above names.
When I start the X11 client, it says it cannot connect to the X server.
The error message:
Unable to init server: Could not connect: Connection refused
Eclipse: Cannot open display:
The value of the DISPLAY environment variable is :0.
I have tried to disable client authentication in XQuartz, but it did not help.
What could be the cause and the solution of the problem?
A workaround is
export DISPLAY=docker.for.mac.host.internal:0
I have an issue trying to setup an https on Google Cloud Platform using golang + let's encrypt
I already have a domain targeting the IP of the instance
Also I got a let's encrypt certificate and chain saved on /etc/letsencrypt/live/mydomain.com/
I already setup myapp to use the cert and configured to run as a service using myapp.service via systemctl
And after all this configurations I always get the next error message:
Feb 14 11:29:47 https https[1982]: 2019/02/14 11:29:47 listen tcp :443: bind: permission denied
Feb 14 11:29:47 https systemd[1]: https.service: Main process exited, code=exited, status=1/FAILURE
Feb 14 11:29:47 https systemd[1]: https.service: Unit entered failed state.
Feb 14 11:29:47 https systemd[1]: https.service: Failed with result 'exit-code'.
If you want to bind to a privileged port (ports less than 1024). You either need to be root or have the CAP_NET_BIND_SERVICE capability.
Ok, I just look for more info about CAP_NET_BIND_SERVICE and I found an answer of Scott Stensland inside this other post:
https://unix.stackexchange.com/questions/455221/setcap-not-found-in-debian-9/455234#455234
Now looks fixed ... thanks
But now I have a "open /etc/letsencrypt/live/mydomain.com/cert.pem: permission denied" error :\ (looking for other solutions in progress...)
Do a port redirect using iptables. Checkout this answer by flappysocks on
https://stackoverflow.com/a/1762807/1100242
I run two mongo databases on my dev machine. The first runs on the standard port and (apparently) runs at startup. The second I start up as part of my "kickoff the dev env" script. How can I get the output from the first database in bash? I'm talking about the output that looks like:
Wed Oct 30 16:28:27.035 [initandlisten] recover : no journal files present, no recovery needed
Wed Oct 30 16:28:27.215 [initandlisten] waiting for connections on port XX987
Wed Oct 30 16:28:27.216 [websvr] admin web console waiting for connections on port XX987
Wed Oct 30 16:28:34.054 [initandlisten] connection accepted from 127.0.0.1:53736 #1 (1 connection now open)
Wed Oct 30 16:28:34.060 [conn1] end connection 127.0.0.1:53736 (0 connections now open)
Wed Oct 30 16:28:34.061 [initandlisten] connection accepted from 127.0.0.1:53737 #2 (1 connection now open)
Is this called a listening socket? How can I connect to this output from bash?
It looks like you are showing the output of the mongodb log file. In order to separate the log messages of the different mongo processes you'll need to configure separate log file locations for both mongo processes. Then you can just:
tail -f /path/to/mongo_dev/logfile
You can change the log file location of a mongodb process by setting
logpath=/path/to/anyhwere.log
in it's config file. Then restart the mongodb process.
For example (I wonder if all these should be separate questions):
What would be the equivalent of mongod.exe in Linux?
What's the equivalent of mongodb.conf in Windows?
How do we make mongodb to launch when computer start in Windows?
For example, in mongodb windows, I have this file called mongod.exe running it run the mongod "service" or something and then it shows status of what's going on at mongodb.
For example this is what mongod.exe shows:
Fri Aug 31 16:08:13 [conn6232] end connection 127.0.0.1:19782
Fri Aug 31 16:08:13 [initandlisten] connection accepted from 127.0.0.1:19783 #
33
Fri Aug 31 16:08:13 [conn6233] end connection 127.0.0.1:19783
Fri Aug 31 16:08:13 [initandlisten] connection accepted from 127.0.0.1:19784 #
34
Fri Aug 31 16:08:13 [conn6234] end connection 127.0.0.1:19784
Fri Aug 31 16:08:13 [initandlisten] connection accepted from 127.0.0.1:19785 #
35
Fri Aug 31 16:08:13 [conn6235] end connection 127.0.0.1:19785
Fri Aug 31 16:08:13 [initandlisten] connection accepted from 127.0.0.1:19786 #
36
Fri Aug 31 16:08:13 [conn6236] end connection 127.0.0.1:19786
Fri Aug 31 16:08:13 [initandlisten] connection accepted from 127.0.0.1:19787 #
37
Fri Aug 31 16:08:13 [initandlisten] connection accepted from 127.0.0.1:19788 #
38
Fri Aug 31 16:08:13 [conn6238] end connection 127.0.0.1:19788
What would be the equivalent of mongod.exe in linux?
Also in Linux we have this thing called mongodb.conf where we set up, for example, where the data directory is. In windows, what's the equivalent of mongodb.conf in windows? In windows, if I want to change data directory I simply copy and move the whole mongod directory. I am not even sure whether that's the right way to do it.
Then in Linux, once I install mongodb it's automatically run everytime I restarted the server. In windows I have to run mongod.exe first. Hmm... How can I arrange that mongodb run automatically as a service in Windows?
What would be the equivalent of mongod.exe in Linux?
Answer: mongod (Linux does not use file extensions to denote executables)
What's the equivalent of mongodb.conf in Windows?
They are identical - this is just a text file on both systems, you can use the same one on both (after adjusting for file path differences etc.)
How do we make mongodb to launch when computer start in Windows?
You install it as a service, as outlined here:
http://www.mongodb.org/display/DOCS/Windows+Service
OpenSSH log in my system are spitting log in following format.
Aug 21 14:34:44 systemHostName sshd[1952]: Server listening on 0.0.0.0 port 22.
I need to get the year also, in the log time. something like following
2012 Aug 21 14:34:44 systemHostName sshd[1952]: Server listening on 0.0.0.0 port 22.
I tried to look into sshd_config and other web resources but could not find anything useful.
Anybody know, how to change openSSH log time format?
It is syslog, not sshd time format, depends on your syslog implementation, though I haven't seen anyone using the year there.