I just updated my mac to Catalina 10.15.2 and I can't running MongoDB.
When I send the command mongo I receive this message
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
and the only way to make Mongo work is to restart the Mac.
If I check the process with the command ps I don't see the process already on and the port 27017 is available.
I already tried to run the follow command:
brew tap mongodb/brew
brew reinstall mongodb-community
brew services restart mongodb-community
and if I run the follow command:
ps aux | grep -v grep | grep mongod
no results.
I tried to run mongod before mongo as well and the result is:
2019-12-18T12:17:45.916+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] MongoDB starting : pid=9375 port=27017 dbpath=/data/db 64-bit host=Marcos-MacBook-Pro.local
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] db version v4.2.1
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] allocator: system
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] modules: none
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] build environment:
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] distarch: x86_64
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] target_arch: x86_64
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] options: {}
2019-12-18T12:17:45.920+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
2019-12-18T12:17:45.920+0100 F - [initandlisten] Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 693
2019-12-18T12:17:45.920+0100 F - [initandlisten]
***aborting after fassert() failure
Someone can help me please? I appreciate it
An alternative way to fix this Catalina Mac OS root & mongodb connection issue, do the following:
Install Homebrew, if you have it, reinstall it again
run the following commands in the terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew untap mongodb/brew && brew tap mongodb/brew
brew install mongodb-community#4.2
The issue is mongo cannot find /db/data because there is no directory, so you have to create one:
cd ~ (this should take you to your Users folder)
from the Users folder make your own db/data folder by running the follow commands:
mkdir db & cd inside db folder
inside the db folder run: mkdir data & cd inside data folder
run this command: mongod --dbpath ~/data/db
(inside the Users/data/db/ folder you just created)
Now open a new terminal tab &
run: cd ~ (brings you back to Users) -> now run : cd .. & cd .. again (do this twice)
(now you should be in the folder before Users)
(now find tmp folder) cd into the /tmp folder
delete the sock file (this is giving you connection issues)
delete it by running: rm -rf mongodb-27017.sock
now run command: mongo (this should work now)
inside mongo shell run command: db.verion()
if you see a version, your connection works.
From now on to run mongodb database & connection you will have to have two separate tabs open at all times whenever you want to work on your projects
Example:
in one terminal tab run command -> mongod --dbpath ~/data/db
(this starts the connection)
in the other terminal tab run command: mongo
(this starts the shell)
These both have to be running..
Side Note:
you no longer need to start
the connection by running
brew services start mongo-community anymore.
remember mongod --dbpath ~/data/db is basically -> mongod command now.. The Mac OS Catalina Update created root permission problems, that is why mongod command alone never worked before.
Hope this helped you. Goodluck.
Faced a similar issue with macOS Big Sur. After trying all the approaches mentioned above including
updating homebrew
reinstalling MongoDB, MongoDB community and setting up a /System/Volumes/Data/data/dbfolder
This command worked for me mongod --dbpath=/System/Volumes/Data/data/db
reference: https://medium.com/codespace69/mongodb-troubleshooting-errors-for-beginners-and-macos-catalina-31befd99f6c8
This error is caused due to ownership issues.
Here we are changing the ownership to 'mongodb' user.
Command 1: deletes the /tmp/mongodb-27017.sock file
$sudo rm -rf /tmp/mongodb-27017.sock
Command 2: starts mongod service
$sudo service mongod start
Command 3: shows the file with its ownership details
ls -lsah /tmp/mongodb-27017.sock
output
0 srwx------ 1 mongodb mongodb 0 Aug 24 04:01 /tmp/mongodb-27017.sock
Got the same issue after upgrading to Catalina. Tried lots of ways to solve the issue, what eventually helped was reinstalling brew, and then following steps listed on official mongodb site.
So:
Uninstall brew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)
Install it again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Follow steps to install and run monbo service:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
I am experiencing the following problem using mongodb.
This is the error, when I check the status:
Screenshot of the error (mongodb.service, status 14)
Screenshot of code in the mongod.config file
Screenshot of the log file
I have tried uninstalling mongodb following every step from the website and install everything again and when I check the status I still get the same error. I have posted the screenshot of the error.
I am using MacBook pro if this matters.
Would really appreciate, if someone can help me fix this.
By changing the owner to monogdb user of
/var/lib/mongodb and /tmp/mongodb-27017.lock has worked for me.
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
It seems from the log you have a unclean shutdown before. Or, it could also indicates that mongod is already running.
First, make sure mongod is not running already
ps aux | grep mongod
If it's not, remove the file:
rm /tmp/mongodb-27017.sock
Then try systemctl start mongod to start MongoDB again.
After rebooting in the command line,it fixed to problem,don’t know why after stopping mongo and uninstalling and installing it didn’t fix the problem, but after reboot everything is working fine.
This worked for me on Ubuntu 18.04
Go to the TMP directory: cd /tmp
Check if you have the mongodb sock file: ls *.sock
Change the user:group permission: chown mongodb:mongodb <YOUR_SOCK>
Start MongoDB: sudo service mongod start
Check the MongoDB status: sudo service mongod status
If this does not work you can try
sudo reboot
Please see here : https://medium.com/#gabrielpires/mongodb-ubuntu-16-04-code-exited-status-14-aws-lightsail-problem-417ffc78cb11
I had a similar issue and even though the permissions were all okay, the service failed to start. I had a look at the mongodb log
sudo tail -40 /var/log/mongodb/mongod.log
It said that the database was shutdown unexpectedly and needed to be repaired. I ran
sudo mongod --repair --config /etc/mongod.conf
This fixed the database, but now changed the permissions. You will need to do the chown steps again.
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
Start the mongod service. It would be up & running now.
Same happended with CentOS Stream 8
the user for mongodb service is mongo and group is also mongo
sudo chown mongod:mongod /tmp/mongodb-27017.sock
Resolved, after checking the logfile, showing mongodb-27017.sock failed to start.
I have a similar issue. Was a SELinux blocking the normal execution.
So, I did:
# ausearch -c 'mongod' --raw | audit2allow -M my-mongod
# semodule -X 300 -i my-mongod.pp
and then:
$ sudo systemctl start mongod
and check:
sudo systemctl status mongod
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
I am using mongodb 3.6.3 on a centos 7 aws ec2 instance.
2 Questions (only one needs to be answered):
Why is the --logpath preventing the mongod command if done manually through the cli with sudo mongod --storageEngine etc
Why is sudo service mongod status showing the failure that it is?
When I run the below command, (since currently, sudo service mongod start isn't working but the below works) it fails when I specify the --logpath but will run without it. Unfortunately, when I run it without it, all of my logs end up in the / which is absolutely the wrong location.
sudo mongod --storageEngine wiredTiger --dbpath /data --bind_ip 127.0.0.1,apiIP --logpath /var/log/mongodb/mongod.log --auth --fork
Below is what happens when I try to run that above line as is.
I CONTROL [main] log file "/var/log/mongodb/mongod.log" exists; moved to "/var/log/mongodb/mongod.log.2018-03-16T15-16-01".
From what I can tell, it is conflicting with the currently existent
Just for reference, sudo service mongod status returns:
mongod.service - mongodb database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2018-03-16 15:11:53 UTC; 9min ago
Process: 26620 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=2)
Main PID: 26620 (code=exited, status=2)
Mar 16 15:11:53 ip-* systemd[1]: Started mongodb database.
Mar 16 15:11:53 ip-* systemd[1]: Starting mongodb database...
Mar 16 15:11:53 ip-* mongod[26620]: F CONTROL [main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"
Mar 16 15:11:53 ip-* systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
Mar 16 15:11:53 ip-* systemd[1]: Unit mongod.service entered failed state.
Mar 16 15:11:53 ip-* systemd[1]: mongod.service failed.
/etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /data
# logpath: /log/mongod.log
journal:
enabled: true
engine: wiredTiger
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
# fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1, apiIP
Thanks to #AlexBlex for noticing the spacing issue in the yaml file.
With that sorted, the status error has this line
Unrecognized option: storage.wiredTiger
cd /var/log
sudo mkdir -m 777 mongodb
sudo service mongod start
sudo service mongod status
Hopefully, that's will do!
sudo systemctl enable mongod
sudo systemctl restart mongod
sudo journalctl -u mongod.service
Hopefully, that will do!
Reference: https://stackoverflow.com/a/51286526/122441
I recently uninstalled postgresql from my computer. I tried to install it again but I faced some problems. I tried to fully uninstall it again like this:
I found al the packages related to postgres:
$ dpkg -l | grep postgres
Them I removed all the packages and related folders :
$ sudo apt-get --purge remove postgresql postgresql-9.3 postgresql-client-9.3 postgresql-client-common postgresql-common postgresql-contrib-9.3
$ sudo rm -rf /var/lib/postgresql/
$ sudo rm -rf /var/log/postgresql/
$ sudo rm -rf /etc/postgresql/
I've tried to install it again, but after the installation I can't access postgres user.
$ sudo apt-get install postgresql postgresql-contrib
$ sudo -i -u postgres
sudo: unable to change directory to /home/postgres: No such file or directory
If I access root I can access postgres but this is what happens:
$ sudo su -
$ su - postgres
No directory, logging in with HOME=/
postgres#rafael-pc:/$ psql
psql (9.3.9)
Type "help" for help.
postgres=# \q
could not save history to file "/home/postgres/.psql_history": No such file or directory
I have no idea what is happening. I've tried to uninstall it many times but I always have some kind of error when I install it back.
Just a guess here, but it sure looks to me like the problem is that there isn't a /home/postgres directory. I'm not sure what may have happened in your uninstall process to remove that, but it looks like that's the cause of the error in both of the steps you list.
Can you try this (or some approximation of these steps, which create that directory and make sure it's owned by the postgres user)?
# sudo mkdir /home/postgres
# sudo chown postgres /home/postgres
I apparently have a redis-server instance running because when I try to start a new server by entering redis-server, I'm greeted with the following:
Opening port: bind: Address already in use
I can't figure out how to stop this server and start a new one.
Is there any command I can append to redis-server when I'm typing in the CLI?
My OS is Ubuntu 10.04.
Either connect to node instance and use shutdown command or if you are on ubuntu you can try to restart redis server through init.d:
/etc/init.d/redis-server restart
or stop/start it:
/etc/init.d/redis-server stop
/etc/init.d/redis-server start
On Mac
redis-cli shutdown
A cleaner, more reliable way is to go into redis-cli and then type shutdown
In redis-cli, type help #server and you will see this near the bottom of the list:
SHUTDOWN - summary: Synchronously save the dataset to disk and then
shut down the server since: 0.07
And if you have a redis-server instance running in a terminal, you'll see this:
User requested shutdown...
[6716] 02 Aug 15:48:44 * Saving the final RDB snapshot before exiting.
[6716] 02 Aug 15:48:44 * DB saved on disk
[6716] 02 Aug 15:48:44 # Redis is now ready to exit, bye bye...
redis-cli shutdown is most effective. The accepted answer does not work for me (OSX Lion). Thanks, #JesseBuesking.
For OSX, I created the following aliases for starting and stopping redis (installed with Homebrew):
alias redstart='redis-server /usr/local/etc/redis/6379.conf'
alias redstop='redis-cli -h 127.0.0.1 -p 6379 shutdown'
This has worked great for local development!
Homebrew now has homebrew-services that can be used to start, stop and restart services. homebrew-services
brew services is automatically installed when run.
brew services start|run redis
brew services stop redis
brew services restart redis
If you use run, then it will not start it at login (nor boot). start will start the redis service and add it at login and boot.
stop the redis server type in terminal with root user
sudo service redis-server stop
the message will be display after stop the redis-server
Stopping redis-server: redis-server.
if you want to start the redis-server type
sudo service redis-server start
if you want to restart the server type
sudo service redis-server restart
Type SHUTDOWN in the CLI
or
if your don't care about your data in memory, you may also type SHUTDOWN NOSAVE to force shutdown the server.
Try killall redis-server. You may also use ps aux to find the name and pid of your server, and then kill it with kill -9 here_pid_number.
Option 1: go to redis installation directory and navigate to src , in my case :
/opt/redis3/src/redis-cli -p 6379 shutdown
where 6379 is the default port.
Option 2: find redis process and kill
ps aux | grep redis-server
t6b3fg 22292 0.0 0.0 106360 1588 pts/0 S+ 01:19 0:00 /bin/sh /sbin/service redis start
t6b3fg 22299 0.0 0.0 11340 1200 pts/0 S+ 01:19 0:00 /bin/sh /etc/init.d/redis start
And Then initiate kill:
kill -9 22292
kill -9 22299
I'm using Centos 6.7 , x86_64
hope it helps
I would suggest to disable Redis-server, which prevents auto start while computer restarts and very useful to use docker like tools etc.
Step 1: Stop the redis-server
sudo service redis-server stop
Step 2: Disable the redis-server
sudo systemctl disable redis-server
if you need redis, you can start it as:
sudo service redis-server start
Another way could be:
ps -ef | grep -i 'redis-server'
kill -9 PID owned by redis
Works on *NIX & OSX
MacOSX - It Worked :)
Step 1 : Find the previously Running Redis Server
ps auxx | grep redis-server
Step 2 : Kill the specific process by finding PID (Process ID) - Redis Sever
kill -9 PID
if you did make install (e.g ubuntu) while installing redis then you can do:
redis-cli shutdown
as pointed by #yojimbo87 :)
systemd, ubuntu 16.04:
$ sudo systemctl is-active redis-server
active
$ sudo systemctl is-enabled redis-server
enabled
$ sudo systemctl disable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable redis-server
Removed /etc/systemd/system/redis.service.
$ sudo systemctl stop redis-server
Usually this problem arises after I shut down my computer ( or leaving running ) an irregular way.. I believe the port gets stuck open, while the process stops but continues to be bound to the previous port.
9/10 times the fix can be:
$ ps aux | grep redis
-> MyUser 2976 0.0 0.0 2459704 320 ?? S Wed01PM 0:29.94 redis-server *:6379
$ kill 2976
$ redis-server
Good to go.
Another way could be :
brew services stop redis
If you know on what port it would be running(by default it would be 6379), you can use below command to get the pid of the process using that port and then can execute kill command for the same pid.
sudo lsof -i : <port> | awk '{print $2}'
the above command will give you pid.
kill <pid>;
This would shutdown your server.
Following worked for me on MAC
ps aux | grep 'redis-server' | awk '{print $2}' | xargs sudo kill -9
If you know on which port(default:6379) your redis server is running you can go with option 1 or you can check your redis process and you can kill with option 2
option 1:Kill process on port:
check : sudo lsof -t -i:6379
kill : sudo kill `sudo lsof -t -i:6379`
option 2:
Find the previously Running Redis Server:
ps auxx | grep redis-server
Kill the specific process by finding PID (Process ID) - Redis Sever
kill -9 PID
Now start your redis server with
redis-server /path/to/redis.conf
In my case it was:
/etc/init.d/redismaster stop
/etc/init.d/redismaster start
To find out what is your service name, you can run:
sudo updatedb
locate redis
And it will show you every Redis files in your system.
If you are running redis in a docker container, none of the present answers will help. You have to stop redis container. Otherwise, redis process will keep respawning.
$ docker ps
CONTAINER ID IMAGE PORTS
e1c008ab04a2 bitnami/redis:4.0.8-r0 0.0.0.0:6379->6379/tcp
$ docker stop e1c008ab04a2
e1c008ab04a2
To stop redis server
sudo service redis-server stop
and check the status of it using
sudo service redis-server status
If Redis is installed via snap:
sudo snap stop redis.server
I don't know specifically for redis, but for servers in general:
What OS or distribution? Often there will be a stop or /etc/init.d/... command that will be able to look up the existing pid in a pid file.
You can look up what process is already bound to the port with sudo netstat -nlpt (linux options; other netstat flavors will vary) and signal it to stop. I would not use kill -9 on a running server unless there really is no other signal or method to shut it down.
The commands below works for me on Ubuntu Server
$ service /etc/init.d/redis_6379 stop
$ service /etc/init.d/redis_6379 start
$ service /etc/init.d/redis_6379 restart
Redis has configuration parameter pidfile (e.g. /etc/redis.conf - check redis source code), for example:
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
pidfile /var/run/redis.pid
If it is set or could be set, instead of searching for process id (pid) by using ps + grep something like this could be used:
kill $(cat /var/run/redis.pid)
If required one can make redis stop script like this (adapted default redis 5.0 init.d script in redis source code):
PIDFILE=/var/run/redis.pid
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
kill $PID
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
On MacOSX,
This is what worked for me
/etc/init.d/redis restart
/etc/init.d/redis stop
/etc/init.d/redis start
One thing to check if the redis commands are not working for you is if your redis-server.pid is actually being created. You specify the location of where this file is in
/etc/systemd/system/redis.service
and it should have a section that looks something like this:
[Service]
Type=forking
User=redis
Group=redis
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
Check the location and permissions of the PIDFile directory (in my case, '/run/redis'). I was trying to restart the service logged in as deploy but the directory permissions were listed as
drwxrwsr-x 2 redis redis 40 Jul 20 17:37 redis
If you need a refresher on linux permissions, check this out. But the problem was I was executing the restart as my deploy user which the permissions above are r-x, not allowing my user to write to the PIDFile directory.
Once I realized that, I logged in using root, reran the restart command on the redis (service redis restart) and everything worked. That was a headache but hopefully this saves someone a little time.
To gracefully shutdown specific instances with passwords and not resorting to brute-force kill commands, use:
redis-cli -p <port> -a <pass> shutdown
root#machine:~# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 105 0.1 0.0 60552 10772 ? Ssl 23:27 0:02 redis-server 127.0.0.1:10002
root 111 0.1 0.0 60552 10900 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10003
root 117 0.1 0.0 60552 10872 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10004
root#machine:~# redis-cli -p 10002 -a mypassword shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
root#machine:~# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 111 0.1 0.0 60552 10900 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10003
root 117 0.1 0.0 60552 10872 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10004
root#machine:~#
Having a ton of instances warrants writing a batch script to loop through them all for a master shutdown.
The service name of redis is redis-server, so you can disable and stop redis with this command:
sudo systemctl disable redis-server
sudo systemctl stop redis-server
You can try this code:
sudo kill -9 $(ps aux | grep 'redis' | awk '{print $2}')