为什么Memcache不能自动启动?

我在CentOS服务器上安装了memcache,并在php中安装了相应的库:

在这里输入图像说明

尽pipe安装了他们两个,我结束了使用Memcache

$memcache = new Memcache; 

由于我想在重启服务器之后自动运行memcache服务,我这样做了:

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

然后我检查:

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

使用几分钟后:

 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 

一切运行良好几个星期。 之后,我决定检查服务状态,出于某种原因,memcache根本没有运行。 我不得不把它放回去(我在那几个星期的某个时候重启了服务器):

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

为什么重启后memcache不能自动启动? 那不就是chkconfig memcached on的作用吗? 为什么它可能停止工作?

你应该检查当你尝试运行时会发生什么(日志等)

 service memcached start 

在停止手动启动的实例之后。 如果这不能帮助检查boot.log,并且下次启动系统时,请尽早检查日志。


> memcached 0:closures1:closures2:closures3:closures4:closures5:closures6:closures

Memcached没有configuration为自动启动,它被设置为closures所有运行级别。

你应该尝试再次开启。

为什么Memcache不能自动启动?

我没有“为什么”的确切答案,但是我已经为这个问题提供了一个解决scheme,如下所述。

步骤1)创build一个名为的可执行文件

 /usr/local/bin/memcached 

并把下面的内容放在那个文件中;

 #!/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. 

第2步)将该脚本放在/ etc / crontab中

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

这就是我所做的。 该脚本将每分钟执行一次,并检查是否有正在运行的memcached实例。

希望这个帮助。