memcached安装部署

1、编译安装libevent:
wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
tar zxvf libevent-1.4.9-stable.tar.gz
cd libevent-1.4.9-stable/
./configure –prefix=/usr
make && make install
cd ../

2、编译安装Memcached:
wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
tar zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6/
./configure –with-libevent=/usr
make && make install
cd ../
安装完成后会把memcached放到 /usr/local/bin/memcached

3、启动memcached
# /usr/local/bin/memcached -d -m 256 -u root -l 192.168.100.186 -p 11211 -c 256 -P /tmp/memcached.pid //启动memcached 启动参数说明:

启动参数说明:
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB

-M return error on memory exhausted (rather than removing items)
-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
-l 是监听的服务器IP地址,默认为所有网卡。
-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口
-c 选项是最大运行的并发连接数,默认是1024
-P 是设置保存Memcache的pid文件

-f <factor> chunk size growth factor (default: 1.25)

-I Override the size of each slab page. Adjusts max item size(1.4.2版本新增)

4、远程登录测试:telnet ip 11211
stats

5、安装memagent
安装magent到/usr/local/下
cd /usr/local
mkdir magent
cd magent/
wget http://memagent.googlecode.com/files/magent-0.5.tar.gz
tar zxvf magent-0.5.tar.gz
/sbin/ldconfig
sed -i “s/LIBS = -levent/LIBS = -levent -lm/g” Makefile
make

若出现错误:
gcc -lrt -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c
magent.c: In function ‘writev_list’:
magent.c:729: error: ‘SSIZE_MAX’ undeclared (first use in this function)
magent.c:729: error: (Each undeclared identifier is reported only once
magent.c:729: error: for each function it appears in.)
make: *** [magent.o] Error 1

解决办法:
vi ketama.h
在开头加入:
#ifndef SSIZE_MAX

# define SSIZE_MAX 32767

#endif

启动magent: magent -u root -n 51200 -l 10.170.227.244 -p 12000 -s 10.0.0.10:11211 -s 10.0.0.11:11211 -b 10.0.0.12:11213

添加环境变量:
vi /etc/profile
最后一行添加:export PATH=”/usr/local/magent:$PATH”
source /etc/profile

线上环境启动memcached:
memcached -d -p 11212 -u memcached -m 64 -l 10.170.227.244 -c 65530 -P /var/run/memcached/memcached3.pid

memcached -d -p 11211 -u memcached -m 64 -l 10.173.154.109 -c 65530 -P /var/run/memcached/memcached.pid

重启memcached:cat /var/run/memcached/memcached.pid
kill -9 pid
重启memagent:netstat -antup|grep 11211
kill -9 pid

发表评论

邮箱地址不会被公开。