前一次已经安装过memcached,没有做记录,太久没有操作了也没有记录有点生疏,做一下笔记,已背后用。
- 下载文件
下载memcached服务端,http://www.danga.com/memcached/download.bml
下载依赖文件libevent,http://www.monkey.org/~provos/libevent/
下载依赖文件libevent,http://www.monkey.org/~provos/libevent/
- 安装软件
1、安装libevent
tar -xzvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local/libevent
make
make install2、安装memcached
tar -xzvf memcached-1.4.20.tar.gz
cd memcached-1.4.20
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make
make install
- 启动memcached
cd /usr/local/memcached
./memcached -d -m 1024 -u root -l 218.5.76.101 -p 11211 -c 256 -P /tmp/memcached.pid
- 停止memcached
cat /tmp/chenxinhan/memcached.pid
kill 查询的序号
- 设定memcached自启动
1、从memcached安装包的拷贝启动脚本
cp /home/memcached-1.4.20/scripts/memcached.sysv /etc/init.d/memcached
2、修改memcached
#! /bin/sh # # chkconfig: - 55 45 # description: The memcached daemon is a network memory cache service. # processname: memcached # config: /etc/sysconfig/memcached # Source function library. . /etc/rc.d/init.d/functions
PORT=11211 USER=nobody MAXCONN=1024 CACHESIZE=1024 OPTIONS="" if [ -f /etc/sysconfig/memcached ];then . /etc/sysconfig/memcached fi # Check that networking is up. if [ "$NETWORKING" = "no" ] then exit 0 fi RETVAL=0 prog="memcached" start () { echo -n $"Starting $prog: " # insure that /usr/local/memcached has proper permissions chown $USER /usr/local/memcached /usr/local/memcached/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /tmp/memcached.pid $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached } stop () { echo -n $"Stopping $prog: " killproc memcached RETVAL=$? echo if [ $RETVAL -eq 0 ] ; then rm -f /var/lock/subsys/memcached rm -f /tmp/memcached.pid fi
3、将memcached设定为系统服务
chkconfig --add memcached
chkconfig memcached on
service memcached start
- 更换memcached监听端口
memcached的默认监听端口为11211,如果想更换监听端口直接修改/etc/init.d/memcached文件中的自启动端口
修改端口参数PORT=21211
开放iptables
vi /etc/sysconfig/iptables添加该端口的防火墙规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21211 -j ACCEPT重启iptables
service iptables restart