作者:手机用户2502931823 | 来源:互联网 | 2023-08-17 09:13
一、通常:启动Memcache的服务器端的命令为:#usrlocalbinmemcached-d-m10-uroot-l127.0.0.1-p11211-c256-Ptmp
一、
通常:启动Memcache的服务器端的命令为:
# /usr/local/bin/memcached -d -m 10 -u root -l
127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在
/tmp/memcached.pid,
想开机自动启动的话,只需在/etc/rc.d/rc.local中加入一行,上面命令
有人用以下命令:
/usr/local/memcached/bin/memcached
-d -m 20 -p 11211 -u apache
上面有些东西可以参考一下:即,ip不指定时,默认是本机,用户,最好选择是:apache 或
deamon
这样,也就是属于哪个用户的服务,由哪个用户启动。
二、
脚本方式
#!/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 -u daemon -d -m 1024 -l 127.0.0.1 -p 11211
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
#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
start()
{
echo -n $"Starting memcached: "
daemon /usr/local/bin/memcached -u daemon -d -m 4096 -l 10.10.10.220 -p 58728
echo
}
stop()
{
echo -n $"Shutting down memcached: "
killproc memcached
echo
}
[ -f /usr/local/bin/memcached ] || exit 0
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart}"
exit 1
esac
exit 0
[root@crm ~]# chkconfig --add memcached
[root@crm ~]#
chkconfig --level 235 memcached on
[root@crm ~]#
chkconfig --list | grep
mem
memcached 0:off
1:off 2:on 3:on 4:off
5:on 6:off
接下来,可以用以下命令启动与停止 memcached
/etc/rc.d/init.d/memcached
start
/etc/rc.d/init.d/memcached
stop
/etc/rc.d/init.d/memcached restart
如:
[root@crm ~]#
/etc/rc.d/init.d/memcached restart
Shutting down memcached: [
OK ]
Starting memcached: [ OK
]
同时,还可以用:
service memcached start
这样的命令操作
然后,可以用ps命令查看进程信息。
[root@crm ~]# ps aux | grep mem
daemon
23781 0.0 0.2 13892 9860 ? Ss 16:51:00 /.../memcached -u
daemon -d -m 1024 -l 172.16.0.106 -p 11211
以上两个脚本前一个脚本中,对网络进行检查。其它都是针对服务启动与停止的命令提示设置。
有人说,复杂的脚本并不好懂,自己也不会写,却想要更完善的,怎么办?
那就到网上找高手的。最好的捷径就是到对应的RPM包中去找。(如果直接用RPM包安装,这些事情都不用做了)
当然,memcached多数情况下都是编译安装,因为,很多时候都是找不到对应的版本。
脚本中
# chkconfig: - 55 45 运行级别这一列参数用的是 -,这样,是不在脚本中写死,可以通过 chkconfig --level
235 memcached on 灵活设置。
最后就是,目前仍不了解
.
/etc/sysconfig/network
#[ ${NETWORKING} = "no" ] && exit 0
#[ -r
/etc/sysconfig/dund ] || exit 0
#. /etc/sysconfig/dund
#[ -z "$DUNDARGS" ]
&& exit 0
这一段的详细含义。需要进一步学习!
memcache 开机启动,布布扣,bubuko.com