在单台服务器下开启多个memcached服务 如果有启动文件 那么 改变以下的 MCACHE_PIDFILE and MCACHE_PORT 就行
[root@s3-di init.d]# cat memcached
#!/bin/bash
# chkconfig: 2345 94 14
# description: Memcache Server
MCACHE_SBIN=/usr/bin/memcached
MCACHE_NAME="Memcached"
MCACHE_PIDFILE=/var/tmp/memcached_verycd.pid
MCACHE_MEMSIZE=128
MCACHE_PORT=11211
MCACHE_USER=www
MCACHE_IF=127.0.0.1
MCACHE_OPTS="-d -m $MCACHE_MEMSIZE -p $MCACHE_PORT -u $MCACHE_USER -l $MCACHE_IF -P $MCACHE_PIDFILE"
. /etc/rc.d/init.d/functions
if [ ! -f $MCACHE_SBIN ]
then
echo "$MCACHE_NAME startup: $MCACHE_SBIN not exists! "
exit
fi
clean_pidfile() {
cat /dev/null > $MCACHE_PIDFILE
chown ${MCACHE_USER}:${MCACHE_USER} $MCACHE_PIDFILE
}
start() {
clean_pidfile
$MCACHE_SBIN $MCACHE_OPTS
ret=$?
if [ $ret -eq 0 ]
then
action $"Starting $MCACHE_NAME: " /bin/true
else
action $"Starting $MCACHE_NAME: " /bin/false
fi
}
stop() {
MCACHE_PID=$(cat $MCACHE_PIDFILE)
kill -9 $MCACHE_PID
ret=$?
if [ $ret -eq 0 ]
then
action $"Stopping $MCACHE_NAME: " /bin/true
else
action $"Stopping $MCACHE_NAME: " /bin/false
fi
clean_pidfile
}
restart() {
stop
sleep 5
start
}
status() {
MCACHE_PID=$(cat $MCACHE_PIDFILE)
PID_NUMS=$(echo $MCACHE_PID | wc -w)
if (( PID_NUMS != 0 ))
then
echo "$MCACHE_NAME (pid $MCACHE_PID) is running..."
else
echo "$MCACHE_NAME is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
或者http://hi.baidu.com/huigenius/blog/item/9afde5cffd528033b600c8c1.html