Linux
Memcached 調試/伺服器日誌監控 Memcached 伺服器?
我有基於 Memcached 變數的聊天引擎,將它們放入數組並通過 jquery 在另一端讀取它們,
這在 95% 的情況下都可以正常工作,但是當伺服器負載很高的 memcached(假設它是 memcached)時,崩潰和瀏覽器就會卡住。
我不認為它的 jquery 問題,因為這僅在伺服器負載非常高時發生。
我需要一種方法來監視 memcached 伺服器或以某種方式將日誌文件寫入失敗/錯誤出現的位置…
關於我如何做到這一點的任何想法?或者知道為什麼 memcached 伺服器會失敗?我按如下方式執行 memcached
$GLOBALS['MemCached'] = FALSE; $GLOBALS['MemCached'] = new Memcache; $GLOBALS['MemCached']->pconnect('localhost', 11211);
我的 memcached 配置如下
#! /bin/sh # # chkconfig: - 55 45 # description: The memcached daemon is a network memory cache service. # processname: memcached # config: /etc/sysconfig/memcached # pidfile: /var/run/memcached/memcached.pid # Standard LSB functions #. /lib/lsb/init-functions # Source function library. . /etc/init.d/functions PORT=11211 USER=memcached MAXCONN=1024 CACHESIZE=128 OPTIONS="" if [ -f /etc/sysconfig/memcached ];then . /etc/sysconfig/memcached fi # Check that networking is up. . /etc/sysconfig/network if [ "$NETWORKING" = "no" ] then exit 0 fi RETVAL=0 prog="memcached" pidfile=${PIDFILE-/var/run/memcached/memcached.pid} lockfile=${LOCKFILE-/var/lock/subsys/memcached} start () { echo -n $"Starting $prog: " # Ensure that /var/run/memcached has proper permissions if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then chown $USER /var/run/memcached fi daemon --pidfile ${pidfile} memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch ${lockfile} } stop () { echo -n $"Stopping $prog: " killproc -p ${pidfile} /usr/bin/memcached RETVAL=$? echo if [ $RETVAL -eq 0 ] ; then rm -f ${lockfile} ${pidfile} fi } restart () { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} memcached RETVAL=$? ;; restart|reload|force-reload) restart ;; condrestart|try-restart) [ -f ${lockfile} ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart}" RETVAL=2 ;; esac exit $RETVAL
在 中定義一個附加變數
/etc/sysconfig/memcached
:PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" LOGFILE="/var/log/memcached.log" OPTIONS=""
編輯
start()
init 腳本中的函式,如下所示:start () { #echo -n $"Starting $prog: " # insure that /var/run/memcached has proper permissions if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then chown $USER /var/run/memcached fi #daemon --pidfile /var/run/memcached/memcached.pid memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS -vv > $LOGFILE 2>&1 $prog -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS -vv > $LOGFILE 2>&1 RETVAL=$? #echo [ $RETVAL -eq 0 ] && action $"Starting $prog: " /bin/true && touch /var/lock/subsys/memcached }
然後重新啟動 memcached,你會在下面看到類似的內容
/var/log/memcached.log
:slab class 40: chunk size 616944 perslab 1 slab class 41: chunk size 771184 perslab 1 slab class 42: chunk size 1048576 perslab 1 <26 server listening (auto-negotiate) <27 server listening (auto-negotiate) <28 send buffer was 129024, now 268435456 <29 send buffer was 129024, now 268435456 <28 server listening (udp) <29 server listening (udp)
不要忘記配置 logrotate。