Linux教程網
分別把memcached和libevent下載回來,放到 /tmp 目錄下:
# cd /tmp
# wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
1、安裝libevent
shell>tar –zxvf libevent-1.4.9-stable.tar.gz //解壓源文件包
shell>cd libevent-1.4.8-stable //進入解壓後的目錄
shell>./configure --prefix=/usr/local/libevent //譯後生成的目標文件夾
shell>make
shell>make install
2、安裝memcached
安裝memcached時需要指定libevent的安裝路徑
shell>tar –zxvf memcached-1.2.6.tar.gz //解壓源文件包
shell>cd memcached-1.2.6 //進入解壓後的目錄
shell>./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached //設置libevent的位置和編譯後生成的目標文件夾
shell>make
shell>make install
3.測試libevent是否安裝成功
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3
-rw-r–r– 1 root root 454156 11?? 12 17:38 libevent.a
-rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug
Linux下安裝完memcached後,netstat -ant | grep LISTEN 看到memcache用的11211端口已在監聽狀態
4、啟動memcached
cd =/usr/local/memcached/bin
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.3.205 -p 11211 -c 256 -P /tmp/memcached.pid
-d選項是啟動一個守護進程,
-m是分配給Memcache使用的內存數量,單位是MB,我這裡是10MB,
-u是運行Memcache的用戶,我這裡是root,
-l是監聽的服務器IP地址,如果有多個地址的話,我這裡指定了服務器的IP地址192.168.0.200,
-p是設置Memcache監聽的端口,我這裡設置了12000,最好是1024以上的端口,
-c選項是最大運行的並發連接數,默認是1024,我這裡設置了256,按照你服務器的負載量來設定,
-P是設置保存Memcache的pid文件,我這裡是保存在 /tmp/memcached.pid
5、測試Memcached
[root@localhost /]# telnet 192.168.141.64 11211
Trying 192.168.141.64...
Connected to 192.168.141.64 (192.168.141.64).
Escape character is '^]'.
set key1 0 60 4
zhou
STORED
get key1
VALUE key1 0 4
zhou
END
至此Memcached安裝成功!
memcached是以KEY-VALUE的方式進行數據存儲的,KEY的大小限制:Key(max)<=250個字符;
VALUE在存儲時有限制:Value(max)<= 1M;
memcached默認過期時間:ExpiresTime(max)= 30(days)。
6、開機自動啟動
想開機自動啟動的話,只需在/etc/rc.d/rc.local中加入一行,下面命令
/usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u apache -c 256
Copyright ©
Linux教程網 All Rights Reserved