memcached安装与启动脚本

Memcached是由Danga Interactive开发的,高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。

一、软件版本
    libevent 稳定版
wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz

    memcached 稳定版
wget  http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz

二、软件安装
    Libevent安装
[root@jw-test01 software]# tar zxvf libevent-1.4.14b-stable.tar.gz
[root@jw-test01 software]# cd libevent-1.4.14b-stable
[root@jw-test01 libevent]# ./configure --prefix=/usr/local/libevent/
[root@jw-test01 libevent]# make
[root@jw-test01 libevent]# make install

  Memcached安装
[root@jw-test01 software]# tar -zxvf memcached-1.4.5.tar.gz
[root@jw-test01 software]# cd memcached-1.4.5
[root@jw-test01 memcached]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@jw-test01 memcached]# make
[root@jw-test01 memcached]# make install

三、编写Memcached启动脚本
#!/bin/bash
# author:kuangl
# date:2013-05-30
# description: Starts and stops the Memcached services.
# pidfile: /tmp/memcached1.pid
# config:  /usr/local/memcached
# chkconfig: - 55 45
# source function library
. /etc/rc.d/init.d/functions
memcached="/usr/local/memcached/bin/memcached"
[ -e $memcached ] || exit 1
start()
{
echo "Starting memcached:"
daemon $memcached -d -m 1000 -u root -l 127.0.0.1 -p 11211 -c 1500 -P /tmp/memcached1.pid
}
stop()
{
echo "Shutting down memcached"
killproc memcached
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

四、将脚本复制到init.d目录下
[root@jw-test01 scripts]# cp memcached.sh /etc/init.d/memcached

五、将memcached加入系统启项
[root@jw-test01 scripts]# chkconfig  --add memcached
[root@jw-test01 scripts]# chkconfig --level 35 memcached on

六、启动memcached
[root@jw-test01 scripts]# service memcached restart
Shutting down memcached      [确定]
Starting memcached:          [确定]
[root@jw-test01 scripts]# ps -ef |grep memcached
root    27616    1  0 22:18 ?        00:00:00 /usr/local/memcached/bin/memcached -d -m 1000 -u root -l 127.0.0.1 -p 11211 -c 1500 -P /tmp/memcached1.pid

七、Memcached常用参数

参数 说明
-p <num> 设置端口号(默认不设置为: 11211)
-U <num> UDP监听端口(默认: 11211, 0 时关闭)
-l <ip_addr> 绑定地址(默认:所有都允许,无论内外网或者本机更换IP,有安全隐患,若设置为127.0.0.1就只能本机访问)
-d 独立进程运行
-u <username> 绑定使用指定用于运行进程<username>
-m <num> 允许最大内存用量,单位M (默认: 64 MB)
-P <file>
posted @ 2016-04-06 16:07  W&L  阅读(216)  评论(0编辑  收藏  举报