MongoDB in Linux Mint 19 - mongodb

I am trying to use mongoDB in Linux mint 19. But I am getting below error.
What is the solution ?

You're starting the mongo shell client, which by default tries to connect to a mongod server running on localhost and listening on port 27017. However, there is no server listening there so the mongo shell notes that and exits.
You'll need to investigate why there was no mongod server listening there:
The MongoDB Server package isn't installed
You're specifying a non-default port in e.g. /etc/mongod.conf
The mongod process/service is not running
...
First verify that the Server package is installed:
sudo dpkg -l | grep -i ".*mongodb.*server"
Then check the status of the mongod service and go from there. That will tell you if it's running, what port it's listening on, what config file is used, etc.
sudo systemctl status mongod
If it's not running then try to start it:
sudo systemctl start mongod
If it's still not running then look at the log messages:
sudo journalctl -u mongod.service

Related

Postgres.app port in use

I am trying to start the server and getting an error
Port 5432 is already in use
I have brew uninstall postgress
which postgres
gives me nothing.
Activity monitor has 14 postgres processes which I cannot kill.
Force quit kill the process and restarts it with another pid.
The same with
sudo kill -9 PID
it kills the process and restarts it with another PID.
If you are running into this problem on OSX, do the following:
Find out what is running on that port:
$ lsof -n -i4TCP:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python2.7 28687 afdasdfasd 3u IPv4 0x2f18e1284963d3e3 0t0 TCP 127.0.0.1:54970->127.0.0.1:postgresql (CLOSE_WAIT)
Kill it
$ kill -9 28687
Restart postgresapp
Have you checked for a launch daemon? It controls the Postgres process when Postgres is installed with Homebrew, and it automatically restarts Postgres after it is killed. Try
sudo launchctl list
or
sudo launchctl list | fgrep postg
to find the name of the daemon. You can stop the daemon with sudo launchctl stop <name> where name depends on the result of the first command.
Askubuntu provided an answer that worked for me:
sudo pkill -u postgres
Source: Nicely stop all postgres processes
$ brew services stop postgresql
This will kill all processes and let you start the server.
You can get the list of ports using:
sudo launchctl list
Then enter the application name, and using this command to get the port nunber:
sudo launchctl list | fgrep postg
In my case, the port is 83. Now use:
kill 83
then
sudo kill 5432
Run those commands
To check what is running on port 5432 - $ sudo lsof -i :5432
To kill Postgres - $ sudo pkill -u postgres
Use this:
brew services stop postgresql
Good luck!

Laravel 5 and MongoDB connection

No suitable servers found (serverselectiontryonce set): [Failed connecting to '127.0.0.1:27107': Connection refused]
I install "jenssegers/mongodb": "^3.0" using composer, but am getting error, i can't connect mongodb.
I got this error when I had mistaken the IP of my machine. I was in VM and used 127.0.0.1, when I needed to use 10.0.2.2, IP of my host machine. Wasted an hour for this. Maybe it saves someone's time...
According to MongoDB documentation
mongod is the primary daemon process for the MongoDB system
According to above mentioned description ,it seems that mongod process is not running on your server and 27017 is default port for mongod instance
Please try executing following command to verify if mongod process is running on server
pgrep mongod
It will return process ID if mongod process is running on server otherwise nothing.
Issue following command in shell to start mongod process
mongod --noauth --dbpath /var/lib/mongodb
I had this error.
I had to restart mongodb to make this work.
I used the command below
sudo service mongod restart

Mongo Shell couldn't connect to the local server

I'm starting MongoDB using the following command:
sumeet#sumeet-acer:~$ sudo service mongod start
I get a reply as:
mongod start/running, process 7209
sumeet#sumeet-acer:~$
But when I try to enter MongoDB shell by typing mongo I get the following error:
sumeet#sumeet-acer:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Fri Jun 12 14:01:59 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
By default, mongod and mongos use the 27017 port. Without any option, the client will try to connect to a server running on localhost and listening at that port.
A few general advices here:
check if the mongod server is really running (ps -edf | grep mongod);
check if it uses the default port (look in the config file1, or use nmap localhost -p0-65535 or netstat | grep 27017);
if mongod is not running, check in the log2 for clues about what goes wrong.
1 /etc/mongodb.conf (on Debian-like systems at least)
2 /var/log/mongodb (on Debian-like systems at least)
The default IP and Port for MongoDB is 127.0.0.1 & 27017.
If you are using config file for specifying settings than re-verify IP & Port mentioned in it.
If you are going with default option than mongod should function as expected.
try mongo 127.0.0.1:27017
this worked for me
For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock
and after that running the repair command
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
courtesy: https://stackoverflow.com/a/13700262/4907105

ubuntu sudo service mongod status shows failed but mongo is working

I started a replica set with three servers with default port and used a different data directory. But when i did sudo service mongod stop. it said failed. so i went into mongo shell and did a shutdown and mongo shell stopped working. now when i did sudo service mongod start it said failed but i was able to go to mongo shell and the reolica set was working. I checked sudo service mongod status it said failed.
sudo service mongod status
[FAIL] Checking status of database: mongod apparently not running failed!
i edited mongod.config to have a replica set name , commented out bind_ip, used keyfile for auth

How to stop and restart memcached server?

How to stop and restart memcached server 1.4.5 in linux OS from command line?
Using root, try something like this:
/etc/init.d/memcached restart
Log in as root or do
su -
Then:
service memcached restart
If that doesn't work, then:
/etc/init.d/memcached restart
It all depends on which Linux distro (or other OS) you're using.
If you're using homebrew:
brew services restart memcached
sudo service memcached stop
sudo service memcached start
sudo service memcached restart
if linux
if install by apt-get
service memcached stop
service memcached restart
if install by source code
Usage: /etc/init.d/memcached {start|stop|restart|force-reload|status}
can also simply kill $pid to stop
sudo /etc/init.d/memcached restart
As root on CentOS 7:
systemctl start memcached
systemctl stop memcached
systemctl restart memcached
To tell the service to start at reboot (ex chkconfig):
systemctl enable memcached
To tell the service to not start at reboot:
systemctl disable memcached
To shutdown memcache daemon:
sudo service memcached stop
To start memcached daemon:
sudo service memcached start
Restart memcached server:
sudo service memcached restart
You can see if Memcache is currently runing:
sudo ps -e | grep memcached
And you can check the TCP or UDP ports if something (e.g. Memcache) is listening to it:
netstat -ap | grep TheChosenPort#
netstat -ap | grep 11211
For some Linuxes you need to change your commands like:
sudo /etc/init.d/memcached start
sudo /etc/init.d/memcached restart
sudo /etc/init.d/memcached stop
If you want to be allowed to shutdown the memcached server you can give it that option before start it :
memcached -A &
With this option when you connect to memcached server for example:
telnet localhost 11211
then you can use shutdown command to shutdown the server. You can also shutdown the memcached server when it is run as a process, first find the process PID using:
pidof memcached
then use:
kill PID command
This worked for me:
brew services stop memcached
If you have an older version of memcached and need a script to wrap memcached as a service, here it is:
Memcached Service Script
For me, I installed it on a Mac via Homebrew and it is not set up as a service. To run the memcached server, I simply execute memcached -d. This will establish Memcached server on the default port, 11211.
> memcached -d
> telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
version
VERSION 1.4.20