cat /etc/redhat-release
CentOS release 6.7 (Final)linux
防火牆、selinux 關閉api
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安全