Linux下Memcache服務器的安裝

 LinuxMemcache服務器的安裝 

環境需求:

安裝Memcached需要libevent庫的支持,所以請在安裝Memcached之前檢查有沒有安裝libevent。測試環境還需要PHP的支持,本文假設PHP已經安裝到/usr/local/php目錄下。

服務器端主要是安裝memcache服務器端,Memcache用到了libevent這個庫用於Socket的處理,所以還需要安裝libevent。

memcached下載地址:http://www.danga.com/memcached/

libevent下載地址: http://monkey.org/~provos/libevent/

安裝配置:

下載libevent:

mkdir /home/oldboy/tools -p
cd /home/oldboy/tools/
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz

安裝libevent:

tar zxf libevent-1.4.13-stable.tar.gz

cd libevent-1.4.13-stable

./configure –-prefix=/usr ;echo $?

make && make install ;echo $?

cd ..

檢查libevent是否安裝成功:

[root@jason tools]# ls -al /usr/lib |grep libevent

lrwxrwxrwx  1 root root     21 Feb 20 10:00libevent-1.4.so.2 -> libevent-1.4.so.2.1.3

-rwxr-xr-x  1 root root 373222 Feb 20 10:00 libevent-1.4.so.2.1.3

-rw-r--r--  1 root root 604082 Feb 20 10:00 libevent.a

-rwxr-xr-x  1 root root    831 Feb 20 10:00libevent.la

lrwxrwxrwx  1 root root     21 Feb 20 10:00libevent.so -> libevent-1.4.so.2.1.3

lrwxrwxrwx  1 root root     26 Feb 20 10:00libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.3

-rwxr-xr-x  1 root root 137345 Feb 20 10:00 libevent_core-1.4.so.2.1.3

-rw-r--r--  1 root root 229088 Feb 20 10:00 libevent_core.a

-rwxr-xr-x  1 root root    866 Feb 20 10:00libevent_core.la

lrwxrwxrwx  1 root root     26 Feb 20 10:00libevent_core.so -> libevent_core-1.4.so.2.1.3

lrwxrwxrwx  1 root root     27 Feb 20 10:00libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.3

-rwxr-xr-x  1 root root 295876 Feb 20 10:00 libevent_extra-1.4.so.2.1.3

-rw-r--r--  1 root root 469194 Feb 20 10:00 libevent_extra.a

-rwxr-xr-x  1 root root    873 Feb 20 10:00libevent_extra.la

lrwxrwxrwx  1 root root     27 Feb 20 10:00libevent_extra.so -> libevent_extra-1.4.so.2.1.3

下載安裝memcached,同時指定libevent的位置:

cd /home/oldboy/tools

wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz

tar zxf memcached-1.4.13.tar.gz

cd memcached-1.4.13

./configure --with-libevent=/usr ;echo $?

make && make install ;echo $?

cd ..

安裝完成後會在/usr/local/bin/目錄下發現mencached

[root@jason tools]# ls -al /usr/local/bin/

total 33548

drwxr-xr-x. 2 root root    4096 Feb 20 10:02 .

drwxr-xr-x. 16 root root    4096 Feb 19 13:31 ..

-rwxr-xr-x. 1 root root 7975624 Feb 18 11:00 ccmake

-rwxr-xr-x. 1 root root 7860667 Feb 18 11:00 cmake

-rwxr-xr-x. 1 root root 8421359 Feb 18 11:00 cpack

-rwxr-xr-x. 1 root root 9779615 Feb 18 11:01 ctest

-rwxr-xr-x   1 root root 297114 Feb 20 10:02 memcached

啓動:

[root@jason tools]# memcached -p 11211 -u root -m 16m -c 10240 -P/var/run/memcached_11211.pid -d

[root@jason tools]# memcached -p 11212 -u root -m 16m -c 10240 -P /var/run/memcached_11212.pid-d

[root@jason tools]# lsof -i:11211

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

memcached 14960 root   26u IPv4  19716      0t0 TCP *:memcache (LISTEN)

memcached 14960 root   27u IPv6  19717      0t0 TCP *:memcache (LISTEN)

memcached 14960 root   28u IPv4  19720      0t0 UDP *:memcache

memcached 14960 root   29u IPv6  19721      0t0 UDP *:memcache

[root@jason tools]# lsof -i:11212

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

memcached 14967 root   26u IPv4  19743      0t0 TCP *:11212 (LISTEN)

memcached 14967 root   27u IPv6  19744      0t0 TCP *:11212 (LISTEN)

memcached 14967 root   28u IPv4  19747      0t0 UDP *:11212

memcached 14967 root   29u IPv6  19748      0t0 UDP *:11212

如:/usr/local/bin/memcached -d -m 200 -u root -l 192.168.1.91 -p 12000 -c1000 -P /tmp/memcached.pid

相關解釋如下:
-d選項是啓動一個守護進程,
-m是分配給Memcache使用的內存數量,單位是MB,這裏是200MB
-u是運行Memcache的用戶,我這裏是root
-l是監聽的服務器IP地址,如果有多個地址的話,我這裏指定了服務器的IP地址192.168.1.91
-p是設置Memcache監聽的端口,我這裏設置了12000,最好是1024以上的端口
-c選項是最大運行的併發連接數,默認是1024,我這裏設置了1000
-P是設置保存Memcache的pid文件,我這裏是保存在 /tmp/memcached.pid

停止Memcache進程:

 kill `cat /tmp/memcached.pid`

加入開機自啓動:

cat >>/etc/rc.local<<EOF

#memcached start along with sys by lisp

memcached -p 11211 -u root -m 16m -c 10240 -P/var/run/memcached_11211.pid -d

memcached -p 11212 -u root -m 16m -c 10240 -P/var/run/memcached_11212.pid -d

EOF


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章