fzaninotto / uptime

A remote monitoring application using Node.js, MongoDB, and Twitter Bootstrap.
http://fzaninotto.github.com/uptime/
MIT License
3.62k stars 703 forks source link

MongoDB connection always fail #320

Open lupetalo opened 9 years ago

lupetalo commented 9 years ago

I am first time user of MongoDB and Node, so i am sorry for maybe asking stupid questions.

  1. There should be noted somewhere in install that you need MongoDB
  2. on a fresh vps i installed nodejs v0.10.4 and mongodb (dont know how to see version, from tutorial on net). There is no firewall running i installed uptime as per readme and i always get
[root@m uptime]# node app
loading plugin ./plugins/console on app
loading plugin ./plugins/patternMatcher on app
loading plugin ./plugins/httpOptions on app
   info  - socket.io started
loading plugin ./plugins/patternMatcher on monitor
loading plugin ./plugins/httpOptions on monitor
Monitor origin started
Express server listening on host localhost, port 8082 in development mode
MongoDB error: auth failed
Make sure a mongoDB server is running and accessible by this application

i get no errors while installing. Than i created mongodb with robomongo gui, added user with read/write and change details in default.yaml config. error is same. Can you please explain install proces to users that are less tehnical about this, because if you do exactly like in video or in readme, you cant run this... Thanks

VarunBatraIT commented 9 years ago

Last I checked robomongo was behind the mongo schema version so here is what I did after deleting the existing user.

If your mongo log says that user information doesn't exist or similar error then

Create a user

mongo
db.createCollection('uptime')
use uptime
db.createUser({
    user: "some_name",
    pwd: "some_password",
    roles: ["readWrite", "dbAdmin"]
})

Make auth enabled:

vim /etc/mongod.conf

# Listen to local interface only. Comment out to listen on all interfaces. 
bind_ip = 0.0.0.0
# Turn on/off security.  Off is currently the default
#noauth = true
auth = true

after restart test auth

mongo -u admin -p --authenticationDatabase uptime

Now retest Hope it should work.

ayhoung commented 9 years ago

did you solve this? im getting the same problem in an os x environment. authentication works as i have tried from the command shell, but for some reason it keeps getting rejected from uptime

lupetalo commented 9 years ago

Nope....

ZachMoreno commented 9 years ago

+1

ayhoung commented 9 years ago

found the answer in a stackoverflow answer: mongo use admin db.system.users.remove({}) <== removing all users db.system.version.remove({}) <== removing current version db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })

re-add your user and it should work

gfornari commented 9 years ago

I had the same issue. If you don't have the authentication enabled, the solution is to configure your connection URI string without credentials in the config/default.yaml file.

With a local database, the connectionString parameter should resemble to

connectionString: mongodb://localhost:27017/uptime
Modna commented 9 years ago

gfornari, could you please elaborate? Is that instead of the solution posted by ayhoung?

gfornari commented 9 years ago

If it's correct, where mongoose create the connection, if the connectionString is not set, then a connection URI string is built, but in a way that force you to have an authentication system in your database. Setting the connectionString you actually work around the problem due to the priority that it has against the other parameters.

A possible solution at source code level is to build the connections URI string in a smarter way checking whether the user and the password are set or not.

About the solution posted by @ayhoung, I haven't tried it, but I would not manipulate the system collections.

Modna commented 9 years ago

Wonderful, and where do I set this connectionString?

gfornari commented 9 years ago

As I previously said, you can change it in the config/default.yaml file ;).

Of course, be aware of the environment with whom you run your app. As stated in the Readme, if you run your app in a production environment (e.g. running NODE_ENV=production node app), you should have a proper config/production.yaml file.

Modna commented 9 years ago

So I added connectionString:

 mongodb://localhost:27017/uptime

to the config/default.yaml file and I still get this output:

uptime@uptime:~/uptime$ nodejs app
loading plugin ./plugins/console on app
loading plugin ./plugins/patternMatcher on app
loading plugin ./plugins/httpOptions on app
   info  - socket.io started
loading plugin ./plugins/patternMatcher on monitor
loading plugin ./plugins/httpOptions on monitor
Monitor origin started
Express server listening on host localhost, port 8082 in development mode
MongoDB error: auth failed
Make sure a mongoDB server is running and accessible by this application

when I run:

service mondo status

I get

mongod start/running, process 817

I also ran a telnet to confirm mongo is on the proper port:

netstat -anp | grep mongo

returns

uptime@uptime:~/uptime$ sudo netstat -anp | grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN 

For reference, db.version() in the mongo shell returns:

> db.version()
3.0.6

and my nodejs version is:

 v0.10.25

Any ideas?

gfornari commented 9 years ago

Do you have the mongod authentication enabled?

Modna commented 9 years ago

So I did a complete reinstall of everything (including ubuntu server 14.04) and added the

connectionString: mongodb://localhost:27017/uptime

line to the config/default.yaml and still got:

up@uptime:~/uptime$ nodejs app
loading plugin ./plugins/console on app
loading plugin ./plugins/patternMatcher on app
loading plugin ./plugins/httpOptions on app
   info  - socket.io started
loading plugin ./plugins/patternMatcher on monitor
loading plugin ./plugins/httpOptions on monitor
Monitor origin started
Express server listening on host localhost, port 8082 in development mode
MongoDB error: auth failed
Make sure a mongoDB server is running and accessible by this application
drewbeer commented 9 years ago

also running into this on a fresh install, followed all the steps.

gfornari commented 9 years ago

I tried again with a fresh install with MongoDB v3.0.6 and Node.js v0.12.7. It works for me following my comment.

drewbeer commented 9 years ago

a fresh install of the uptime repo solved my problem.