How to enable HTTP server for Mongodb database - mongodb

As per my understanding when we run mongod.exe in windows , in addition to starting database server , it also sets up a basic HTTP server on port 1000 higher than the main port(in my case its default 27017)
But when I enter http://localhost:28017/ in browser, nothing gets displayed.
what needs to modified/configured to enable HTTP server?

first run it
mongod --httpinterface
then access it via http
http://localhost:28017/

Related

Enabling authorization in mongod.cfg makes server crash

I am trying to enable mongodb authorization on my local machine (windows 10) I do this by adding the following settings in my mongod.cfg file.
#security:
authorization: "enabled"
When I do this and try to restart mongodb server as service on windows, it crashes with this messages, windows could not start mongodb server.
I tried to start mongodb service through terminal, with following command.
net start Mongodb.
this also gives and error, with message access is denied.
NOTE: without adding authorization configuration in monogd.cfg file, server works fine.
It must be this (without hashtag and with spaces) :
security:
authorization: enabled

Zabbix-agent on HAProxy discover load-balanced host doesn't show up on Zabbix Server

I have been following this tutorial for a moment but I don't know why it isn't working:
https://github.com/anapsix/zabbix-haproxy/blob/master/README.md
To make a long story short:
I have a Zabbix server on Amazon EC2 and I want to monitor a HAproxy server which is inside my network. The HAProxy Server has a Zabbix Agent working on it.
The tutorial explain how to setup a script for the zabbix-agent to explore what's behind it (what's the haproxy is load-balancing) and send it back to the Zabbix Server.
However everything is working fine but nothing shows up on the Zabbix server, no host are discovered despite the zabbix agent and server are communicating.
1 - I did place the userparameter_haproxy.conf into /etc/zabbix/zabbix_agentd.d/ and
set it in the zabbix_agend.conf file.
2 - I did place the haproxy_discovery.sh into /usr/local/bin/ and gave it the +x rights
3 - I did import haproxy_zbx_template.xml
4 - Configure HAProxy control socket: I assume there is my mistake.
5- The scripts are working because I get result when I execute this commands:
zabbix_agentd -t haproxy.list.discovery[FRONTEND]
zabbix_agentd -t haproxy.list.discovery[BACKEND]
zabbix_agentd -t haproxy.list.discovery[SERVERS]
6 - I added the host with HAproxy on it to the right template
7 - I can wait forever nothing is showing up, no new hosts.
I think the step 4 is where I am doing wrong. In the tutorial they say:
Configure HAProxy to listen on /var/run/haproxy/info.sock or set
custom socket path in checks (set {$HAPROXY_SOCK} template macro to
your custom socket path) or update userparameter_haproxy.conf and
haproxy_discovery.sh with your socket path
I did make the haproxy.cfg file listen to the file /var/lib/haproxy/stats
and set a custom socket path in the template macro.
Additionnal info:
Version of Zabbix: 3.4
Zabbix Server: RHEL 7.4
Zabbix Agent: Centos 7.2
No errors when I restart zabbix-agent
No errors in haproxy.log
UPDATE: I did add Zabbix to the root group.
Now, in Zabbix server logs I can see this message:
changed: Value "which: no nc in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
2" of type "string" is not suitable for value type "Numeric (unsigned)"
And I'm lost again.
UPDATE: I was missing netcat, I installed it on the zabbix server and client.
UPDATE: It's working
According to your update, I guess netcat (nc) is not installed on your system.
Install it and try again

Start Mongodb server in two modes parallely

I have installed mongo db in my local system, i am aware that at any point in time we can start the mongo using mongod service.
in normal mode which will run on port 27017
in rest API mode where we can query to collections and db's which normally runs on mongo port + 1000
i want to start both mode together, any help would be appreciated.
Thanks
Amit
You should add modify your mongod config file to enable http.
add following config line, see https://docs.mongodb.org/manual/reference/configuration-options/
net:
http:
enabled: true
or add parameter in the command line
mongod --httpinterface
You can start multiple instances of mongod. You just have to make sure that they're using different ports and different dbpaths.
To run two separate instances of mongod
mongod
This will start a mongod instance on port 27017 and use dbpath /data/db
Start another command prompt and type in
mongod --port 27018 --dbpath /data/db2
Just make sure that you have a folder named db2 inside your data folder in your c drive. That's where it stores the data.
Additionally, if you're on Node.js, the MongoDB Node.js driver provides a server method where you can start a mongod instance programatically.
var mongo = require("mongodb");
var server = new mongo.Server('localhost', 27017, { auto_reconnect : true} );
This will create a server in what you are calling the Rest API mode.
And then you can simply start mongod from command prompt specifying some other port and dbpath.
I'm not sure which we can start two instance of mondo or not!. but try this:
Run one of then through service mongod start and second one directly by running binary file (e.g. /usr/bin/mondodb). (also you can run both of them directly from CLI.)
In second mode, you most give appropriate parameter for mondo (e.g. path for config file). If you don't know how to give/pass parameters to mondo's binary file, see man mongodb or go and read /etc/init.d/mongod (in Debian based distributions), it give you useful information)
Unfortunately I don't have an installed mongoDB on my machine, so I can't give you exact commands.

What are the practical differences between mongo and mongod?

Just finished installing mongodb, however, I have not been able to make complete sense of the difference between mongo vs mongod commands. Yes, I do understand that
mongod is the primary daemon process for the MongoDB system
and that
mongo is an interactive JavaScript shell interface to MongoDB
but what does that mean practically? I presume every time I want to use mongodb, I need to run mongod first. But then why am I able to run mongo without having started mongod first? Does mongo run mongod in the background automatically? Secondly, if I run mongod it eventually ends with something like
waiting for connections on port 27017
but then I can't type anything after that. Again, I presume that mongodb has been started in the background so I can safely close the terminal. But if I close the terminal by mistake (on a mac), how can I get that back up on the terminal? Also, how can I terminate the service for it to stop listening to the port?
So as you can I see, I have a bunch of simple questions... but most are related to the practical uses of when and when not to mongo or mongod. I can't seem to find anything online that will help me explain these in the practical sense.
As with most database software, Mongo is split into a server and client. The server is the main database component which stores and manages data. Clients come in various flavours and connect to the server to insert or query data.
mongod is the server portion. You start it, it runs, end of story.
mongo is a default command line client. You start it, you connect to a server, you enter commands, you quit it.
You have to run mongod first, otherwise you have no database to interact with. Simply running mongod on a command line will make it the frontmost running application, and it does not offer any interactivity. So yes, you'll just see something like "Waiting for connections...", and nothing more. You typically don't run mongod like that on the command line. You most typically create an init.d script or launchd file or however you manage your daemons, and have the system start it automatically at system boot time.
If you want to launch mongod as a one-off thing without having it permanently running on your systems, put it in the background:
$ mongod &
The & puts it in the background and you can continue to use your command line. You can see it and kill it like this:
~ deceze$ mongod &
[1] 1065
~ deceze$ jobs
[1]+ Running mongod &
~ deceze$ kill %1
[1]+ Done mongod
Once your server is running, start mongo, connect to the server, and interact with it. If you try to run mongo without a running server, it should complain that it's not able to connect:
~ deceze$ mongo
MongoDB shell version: 3.0.2
connecting to: test
2015-08-13T09:36:13.518+0200 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-08-13T09:36:13.521+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
If your mongo shell does connect to something, you might unknowingly have another instance of mongod running on your system.
With mongodyou are starting the server on your machine. As you stated correctly, mongo is your client, your user interface, if you want to. Per default it connects to your local instance of MongoDB. If you start your client without a server instance running, you would have to 'tell' it, where it should connect to (e.g. a remote instance):
http://docs.mongodb.org/manual/reference/program/mongo/

How to get MONGO_URL from command line Meteor Up deployment?

I am currently deploying to Digital Ocean using Meteor Up. If I don't specify a MONGO_URL in the mup.json, can I get the value from the command line while the website is running, i.e. I don't want to shutdown the site?
If I go to the app directory and run meteor mongo --url, I get the following error:
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application
locally. Start your application first. (This error will also occur if
you asked Meteor to use a different MongoDB server with $MONGO_URL when
you ran your application.)
If you're trying to connect to the database of an app you deployed
with 'meteor deploy', specify your site's name with this command.
Even if I run the app from the app directory, it will only give the localhost MONGO_URL. I need the MONGO_URL for the deployed app.
I have also taken a look at a similar question as suggested by some of the answers. I disagree that it is "impossible" to get the MONGO_URL without some other program running on the server. It's not as if we are defying the laws of physics here, folks. Fundamentally, there should be a way to access it. Just because no one has yet figured it out doesn't mean it is impossible.
meteor mongo --url should return the URL.
Try opening another shell in the app directory and running that command.
Meteor Up packages your app in production mode with meteor build so that it runs via node rather than the meteor command line interface. Among other things, this means meteor foo won't work on the remote server (at least not by default). So what you're really looking for is a way to access mongo itself remotely.
I recently set up mongo on an AWS EC2 instance and listed some lessons learned here: https://stackoverflow.com/a/28846703/2669596. Some details of how you do it are going to be different on Digital Ocean, but these are the main things you have to take care of once mongo itself is installed:
Public IP/DNS Address: This is probably fine already since you can deploy to the server.
Port Security Rules: You need to make sure port 27017 is open for TCP access, at least from your IP address. MongoDB also has an http interface you can set up; if you want to use that you'll need to open 28017 as well.
/etc/mongod.conf (file location may differ depending on Linux flavor):
Uncomment port=27017 to make sure you have the default port (I don't think this is actually necessary, but it made me feel better and it's good to know where to change the default port...).
Comment out bind_ip=127.0.0.1 in order to listen to external interfaces (e.g. remote connections).
Uncomment httpinterface=true if you want to use the http interface.
You may have to restart the mongod host via sudo service mongod restart. That's a problem if you can't have downtime, but I don't know of a way around that if you change the config file.
Create User: You need to create an admin and/or user to access the database remotely.
Once you've done all of that, you should be able to access the database from your local machine (assuming you have the mongo client installed locally) by running
mongo server.url.com:27017/mup-app-name -u username -p
where server.url.com is the URL or IP address of your remote server, mup-app-name is the appName parameter from your mup.json file, username is the user you created to access the database, and you'll be prompted for that user's password after you run the command (or you could put it after -p on the same line, depending on the password).
There may also be a way to do this by setting up nginx to reverse-proxy 127.0.0.1:27017 on your remote server, but I've never done it and that's just me speculating.