Memcached安装
Posted 有一天你会来
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Memcached安装相关的知识,希望对你有一定的参考价值。
解析: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安装
[[email protected] software]# tar zxvf libevent-1.4.14b-stable.tar.gz
[[email protected] software]# cd libevent-1.4.14b-stable
[[email protected] libevent]# ./configure --prefix=/usr/local/libevent/
[[email protected] libevent]# make
[[email protected] libevent]# make install
Memcached安装
[[email protected] software]# tar -zxvf memcached-1.4.5.tar.gz
[[email protected] software]# cd memcached-1.4.5
[[email protected] memcached]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[[email protected] memcached]# make
[[email protected] 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目录下
[[email protected] scripts]# cp memcached.sh /etc/init.d/memcached
五、将memcached加入系统启项
[[email protected] scripts]# chkconfig --add memcached
[[email protected] scripts]# chkconfig --level 35 memcached on
六、启动memcached
[[email protected] scripts]# service memcached restart
Shutting down memcached [确定]
Starting memcached: [确定]
[[email protected] 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> | 将PID写入文件<file>,这样可以使得后边进行快速进程终止, 需要与-d 一起使用 |
以上是关于Memcached安装的主要内容,如果未能解决你的问题,请参考以下文章