memcached官网:https://memcached.org/
安装memcached
[root@localhost src]# tar -xf memcached-1.6.33.tar.gz
[root@localhost src]# cd memcached-1.6.33
[root@localhost memcached-1.6.33]# ./configure --prefix=/program/memcached-1.6 --enable-sasl
[root@localhost memcached-1.6.33]# make
[root@localhost memcached-1.6.33]# make install
修改文件属主
[root@localhost ~]# groupadd memcached && useradd -s /sbin/nologin -g memcached -M memcached
[root@localhost ~]# chown -R memcached:memcached /program/memcached-1.6/
将memcached加入系统服务方便管理
[root@localhost ~]# touch /etc/init.d/memcached-1.6 && chmod +x /etc/init.d/memcached-1.6 && vim /etc/init.d/memcached-1.6
#!/bin/sh
#
# chkconfig: - 91 35
# description: Memcached Service
########## 以下变量请根据实际情况更改 ##########
serviceName="memcached-1.6"
binMemcached="/program/memcached-1.6/bin/memcached"
pidFIle="/program/_pid/memcached-1.6.pid"
startCommand="${binMemcached} -d -m 100 -u memcached -p 11211 -c 256 -P ${pidFIle}"
start() {
echo $"正在启动 $serviceName : [确定]"
# 启动Memcached服务命令
${startCommand}
}
stop() {
echo $"正在停止 $serviceName : [确定]"
if [ -f ${pidFIle} ]; then
# 获取进程ID,根据进程ID停止服务
pid=`cat ${pidFIle}`
# KILL掉进程
kill -15 ${pid}
# 删除进程文件
rm -rf ${pidFIle}
fi
}
restart() {
stop
sleep 3s
start
}
status() {
# 检查进程文件是否存在
if [ -f ${pidFIle} ]; then
# 有可能存在进程文件存在但进程不存在的异常,故需要进一步检查
pid=`cat ${pidFIle}`
result=`ps --no-heading ${pid} | wc -l`
if [ $result -eq 1 ]; then
echo $"运行状态 $serviceName(PID为${pid}) : [启动]"
else
echo -e $"运行状态 $serviceName : [\033[31m停止\033[0m]"
fi
else
echo -e $"运行状态 $serviceName : [\033[31m停止\033[0m]"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"用法: service ${serviceName} {start|stop|restart|status}"
exit 2
esac
exit $?
[root@localhost ~]#
memcached服务管理命令汇总
[root@localhost ~]# chkconfig --add memcached-1.6
[root@localhost ~]# chkconfig memcached-1.6 on
[root@localhost ~]# chkconfig memcached-1.6 off
[root@localhost ~]# service memcached-1.6 status
[root@localhost ~]# service memcached-1.6 start
[root@localhost ~]# service memcached-1.6 stop
[root@localhost ~]# service memcached-1.6 restart