Rails + Dalli memcache gem: DalliError: No server available

24,625

Solution 1

I had the same problem. First I installed memcached as a gem gem install memcached and got the error "DalliError: No server available"

Then I installed memcached by doing sudo apt-get install memcached. It works fine now.

Solution 2

If you're a Homebrew user:

brew install memcached

Check if the service is running:

brew services list

If not, start it:

brew services start memcached

Solution 3

Use 127.0.0.1 instead of localhost should solve your (and mine) issue.

config.cache_store = :dalli_store, '127.0.0.1:11211', { namespace: 'production' }

Solution 4

It was because someone changed the /etc/hosts file to point 127.0.1.1 to localhost instead of 127.0.0.1. After changing that, memcached worked.

Solution 5

The accepted answer will probably solve the issue for 95% of people who are seeing this error, but in my case I found the issue to be far more fundamental:

From the server, I was unable to ping 127.0.0.1. This meant Dalli could not connect to the memcache server, which by default runs on 127.0.0.1:11211.

There are a number of things that could cause this issue, but the most likely is simply a missing network interface. If you run ifconfig, you should see something like this in the output:

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:15686 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15686 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:23730314 (23.7 MB)  TX bytes:23730314 (23.7 MB)

If this is missing, ensure your /etc/network/interfaces file contains the following local interface definition:

auto lo
iface lo inet loopback

And then restart the networking service:

sudo /etc/init.d/networking restart
Share:
24,625
bigpotato
Author by

bigpotato

Updated on June 11, 2020

Comments

  • bigpotato
    bigpotato about 4 years

    Hi I'm having trouble setting up my Rails project on my server because apache keeps complaining

    DalliError: No server available.

    I installed memcached on my ubuntu machine, but it still doesn't work. My rails project also has config.cache_store = :dalli_store, 'localhost:11211', { :namespace => "production" } in environments/production.rb. How would I debug this?

    My log shows before each request:

    localhost:11211 failed (count: 6)
    DalliError: No server available
    

    telnet to 11211:

        root@s2:/usr/local/www/production/current/log# telnet localhost 11211
        Trying 127.0.1.1...
        telnet: Unable to connect to remote host: Connection refused
    
    • PinnyM
      PinnyM almost 11 years
      What are you running to start memcached?
  • 3limin4t0r
    3limin4t0r over 3 years
    Make sure the service is also enabled. sudo systemctl enable memcached (start on boot) sudo systemctl start memcached (start now) If you are unsure if the service is running use systemctl status memcached
  • 3limin4t0r
    3limin4t0r over 3 years
    Had the same issue. This happens if Ruby interprets "localhost" as "::1" (IPv6 address). See: github.com/petergoldstein/dalli/issues/130#issuecomment-2531‌​438