How can I stop redis-server?

前端 未结 26 1576
清歌不尽
清歌不尽 2020-12-07 06:51

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 followin

相关标签:
26条回答
  • 2020-12-07 07:08

    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
    
    0 讨论(0)
  • 2020-12-07 07:08

    To stop redis server

    sudo service redis-server stop
    

    and check the status of it using

    sudo service redis-server status
    
    0 讨论(0)
  • 2020-12-07 07:09

    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.

    0 讨论(0)
  • 2020-12-07 07:10

    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
    
    0 讨论(0)
  • 2020-12-07 07:10

    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.

    0 讨论(0)
  • 2020-12-07 07:11

    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 
    
    0 讨论(0)
提交回复
热议问题