lonux中memcached设置开机自启:
1、创建自启的脚本
vim /etc/init.d/memcached
2、添加文件内容:
#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
#[ ${
NETWORKING} = "no" ] && exit 0
#[ -r /etc/sysconfig/dund ] || exit 0
#. /etc/sysconfig/dund
#[ -z "$DUNDARGS" ] && exit 0
start()
{
echo -n $"Starting memcached: "
daemon $MEMCACHED -d -m 2048 -u root -p 11211 -c 2048 –P /tmp/memcached.pid
echo
}
stop()
{
echo -n $"Shutting down memcached: "
killproc memcached
echo
}
MEMCACHED="/usr/local/memcached/bin/memcached"
[ -f $MEMCACHED ] || exit 1
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
3、加入服务:
chmod +x /etc/init.d/memcached
chkconfig --add /etc/init.d/memcached
chkconfig memcached on```
4、服务命令
service memcached start
service memcached stop
service memcached restart
参数说明:
-d 启动为守护进程
-m 分配给Memcached使用的内存数量,单位是MB,默认为64MB
-u 运行Memcached的用户,仅当作为root运行时
-l <ip_addr> 监听的服务器IP地址,默认为环境变量INDRR_ANY的值
-p 设置Memcached监听的端口,最好是1024以上的端口
-c 设置最大并发连接数,默认为1024
-P 设置保存Memcached的pid文件,与-d选择同时使用