cat /etc/redhat-release
CentOS release 6.7 (Final)
防火墙、selinux 关闭
192.168.12.30 安装libevent和memcached、magent
192.168.12.43 安装libevent和memcached、magent
192.168.12.42 安装libevent和memcached
软件下载地址:
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/memagent/magent-0.5.tar.gz
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/memcached/memcached-1.4.15.tar.gz
安装:
yum -y install gcc libevent-devel
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local/libevent
make
make install
ln -s /usr/lib64/libm.so /usr/local/lib64/libm.a
memcached安装:
tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make&&make install
cp /usr/local/memcached/bin/memcached /etc/rc.d/init.d/
/etc/init.d/memcached -d -m 512 -u root -l 192.168.12.30 -p 11211 -c 10000 -M -f 1.1 -P /tmp/memcached.pid
ps aux|grep memcached
root 15059 0.0 0.0 331032 1072 ? Ssl 16:37 0:00 //etc/init.d/memcached -d -m 512 -u root -l 192.168.12.30 -p 11211 -c 10000 -M -f 1.1 -P /tmp/memcached.pid
root 15068 0.0 0.0 103320 832 pts/1 R+ 16:37 0:00 grep memcached
-p <num> 设置端口号(默认不设置为: 11211)
-U <num> UDP监听端口 (默认: 11211, 0 时关闭)
-l <ip_addr> 绑定地址 (默认:所有都允许,无论内外网或者本机更换IP,有安全隐患,若设置为127.0.0.1就只能本机访问)
-d duli进程运行
-u <username> 绑定使用指定用于运行进程 <username>
-m <num> 允许最大内存用量,单位M (默认: 64 MB)
-P <file> 将PID写入文件<file>,这样可以使得后边进行快速进程终止, 需要与 -d 一起使用
magent安装:
mkdir magent
cd magent
tar zxvf magent-0.5.tar.gz
vi ketama.h (开头加入)
#ifndef SSIZE_MAX
# define SSIZE_MAX 32767
#endif
/sbin/ldconfig
sed -i "s#LIBS = -levent#LIBS = -levent -lm#g" Makefile
make
cp magent /etc/rc.d/init.d/
/etc/init.d/magent -u root -n 51200 -l192.168.12.30 -p 12000 -s 192.168.12.30:11211
ps -ef | grep magent
root 15070 1 0 16:47 ? 00:00:00 /etc/init.d/magent -u root -n 51200 -l192.168.12.30 -p 12000 -s 192.168.12.30:11211
root 15073 7508 0 16:47 pts/0 00:00:00 grep magent
-h this message
-u uid
-g gid
-p port, default is 11211. (0 to disable tcp support)
-s ip:port, set memcached server ip and port
-b ip:port, set backup memcached server ip and port
-l ip, local bind ip address, default is 0.0.0.0
-n number, set max connections, default is 4096
-D do not go to background
-k use ketama key allocation algorithm
-f file, unix socket path to listen on. default is off
-i number, max keep alive connections for one memcached server, default is 20
-v verbose
启动magent实例
/etc/init.d/magent -u root -n 4096 -l 192.168.12.30 -p 11200 -s 192.168.12.30:11211 -s 192.168.12.43:11211 -b 192.168.12.42:11211
/etc/init.d/magent -u root -n 4096 -l 192.168.12.43 -p 11200 -s 192.168.12.30:11211 -s 192.168.12.43:11211 -b 192.168.12.42:11211