memcached Boot Mode
Method One:
Append the start command to the/etc/rc.d/rc.local file
/usr/local/memcached/bin/memcached-u root-d-M 2048-l 192.168.137.99-p 11211-p/tmp/memcached.pid
You can also specify no IP, which is native by default, such as
/usr/local/memcached/bin/memcached-u deamon-d-M 2048-p 11211-p/tmp/memcached.pid
The user is preferably Apache or Deamon
Method Two:
#写服务脚本
View Source print?
1 |
vim /etc/init.d/memcached |
Paste the following code
View Source print?
03 |
# memcached: MemCached Daemon |
06 |
# description: MemCached Daemon |
08 |
# Source function library. |
10 |
. /etc/rc.d/init.d/functions |
11 |
. /etc/sysconfig/network |
13 |
#[ ${NETWORKING} = "no" ] && exit 0 |
14 |
#[ -r /etc/sysconfig/dund ] || exit 0 |
15 |
#. /etc/sysconfig/dund |
16 |
#[ -z "$DUNDARGS" ] && exit 0 |
18 |
MEMCACHED= "/usr/local/memcached/bin/memcached" |
19 |
SERVER_IP= "192.168.137.98" |
22 |
[ -f $MEMCACHED ] || exit 1 |
26 |
echo -n $ "Starting memcached: " |
27 |
daemon $MEMCACHED -u daemon -d -m 2048 -l $SERVER_IP -p $SERVER_PORT -P /tmp/memcached.pid |
32 |
echo -n $ "Shutting down memcached: " |
37 |
# See how we were called. |
51 |
echo $ "Usage: $0 {start|stop|restart}" |
#设置启动服务
View Source print?
1 |
chmod 755 /etc/init.d/memcached #增加执行权限 |
2 |
chkconfig --add memcached #添加memcached到服务项 |
3 |
chkconfig --level 2345 memcached on #设置开机启动 |
4 |
chkconfig --list memcached #查看是否设置成功 |
#服务管理命令
View Source print?
1 |
service memcached start # 启动memcached |
2 |
service memcached stop # 关闭memcached |
3 |
service memcached restart # 重启memcached |
memcached Start Parameter Description:
The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, default 64MB
-M return error on memory exhausted (rather than removing items)
-U is the user running memcache, and if it is currently root, you need to specify the user with this parameter.
-L is the server IP address of the listener, which defaults to all network cards.
-P is the port that sets the TCP listener for memcache, preferably a port above 1024
The-c option is the maximum number of concurrent connections that are running, by default 1024
-P is a PID file that is set to save Memcache
-F <factor> Chunk size growth factor (default:1.25)
-I Override the size of each slab page. Adjusts max item size (new 1.4.2 version)
You can also start multiple daemons, but the ports cannot be duplicated
-P Specify port number (default 11211)
-m Specifies maximum memory size (default 64MB, Max 2G)
-T thread count (default 4)
-L connected IP address, default is native
-D Start memcached Service (default = Start)
-D Restart Restart memcached service
-D Stop|shutdown Close the running memcached service
-d Uninstall Uninstall memcached service
-m maximum memory usage, in megabytes. Default 64MB
-M running out of memory and returning an error instead of deleting an item
-c Maximum number of simultaneous connections, default is 1024
-F Block size growth factor, default is 1.25
-N Minimum allocated space, key+value+flags default is 48
-H Display Help
Linux setup memcached boot up