1

I installed memcache in my CentOS server, and the respective libraries for php as well:

enter image description here

Despite having installed both of them, I ended using Memcache

$memcache = new Memcache;

Since I wanted the memcache service to run automatically after rebooting the server, I did this:

memcached -d -u nobody -m 512 -p 11211 127.0.0.1
chkconfig memcached on

Then I checked:

chkconfig --list | grep memcache
> memcached 0:off   1:off   2:on    3:on    4:on    5:on    6:off

After a few minutes of use:

echo stats | nc 127.0.0.1 11211

STAT pid 30412
STAT uptime 1616
STAT time 1424280050
STAT version 1.4.15
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.053991
STAT rusage_system 0.152976
STAT curr_connections 42
STAT total_connections 144
STAT connection_structures 43
STAT reserved_fds 20
STAT cmd_get 639
STAT cmd_set 360
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 262
STAT get_misses 377
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 147954
STAT bytes_written 455620
STAT limit_maxbytes 536870912
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT bytes 138385
STAT curr_items 359
STAT total_items 360
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 1
END

Everything ran fine for a few weeks. After that time I decided to check the service status, and for some reason, memcache was not running at all. I had to put it back on (i did reboot the server at some point in those weeks):

memcached -d -u nobody -m 512 -p 11211 127.0.0.1

Why didn't memcache start automatically after the reboot? Isn't that what chkconfig memcached on is for? Why could it have stopped working?

1

You should check what happens (logs etc) when you try to run

service memcached start

after stopping the manually started instance. If that doesn't help check the boot.log and next time you start the sytem check the logs as early as possible.


> memcached 0:off 1:off 2:off 3:off 4:off 5:off 6:off

Memcached is not configured to auto start, it is set to off for all run-levels.

You should try to set it on again.

  • sorry, that was not the result of chkconfig --list | grep memcache, i just updated with the current result. – Carlos Santos Feb 18 '15 at 17:31
0

Why is Memcache not starting automatically?

I don't have the exact answer of 'why', but I have a solution for that issue as listed and described below;

Step 1) Create an executable file named

/usr/local/bin/memcached

and put below contents in that file;

#!/bin/sh

echo Checking for memcached instance...
result=$(pidof memcached)
echo "$result"
if [ -z "$result" ]; then
  echo memcached is not running. Attempt to start it...
  /usr/bin/memcached -u memcached -p 11211 -m 1024 -c 1024 -l localhost -d &
else
  echo memcached is already running. Do nothing.
fi

echo End of script.

Step 2) Put that script in /etc/crontab

* * * * root /usr/local/bin/memcached

That's all what I did. That script will be executed every minute and check for any running memcached instance.

Hope this help.

  • Maybe you should check out the service command sometime. – chicks May 30 '17 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.