歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下安裝Memcache

Linux下安裝Memcache

日期:2017/2/28 16:06:52   编辑:Linux教程
Memcache是一個開源項目,它是一個高性能的分布式的內存對象緩存系統,通過在內存裡維護一個統一的巨大的Hash表,能夠用來存儲各種格式的數據。

1: 還是下載

Memcache是用C編寫的,要用到C的libevent來處理接口

點擊下載memcached-1.4.0.tar.gz

下載libevent-2.0.13-stable.tar.gz

下載memcache-3.0.6.tgz


我下載到了/root/Downloads


2:解壓編譯

a:先安裝libevent

  1. #cd /Downloads
  2. #tar zvxf libevent-2.0.13-stable.tar.gz
  3. #cd libevent-2.0.13-stable
  4. #./configure --prefix=/usr
  5. #make
  6. #make install

查看下安裝是否成功

  1. # ls -al /usr/lib | grep libevent

  1. lrwxrwxrwx 1 root root 21 2011-03-30 11:03 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3
  2. -rw-r--r-- 1 root root 91768 2009-12-06 05:52 libevent-1.4.so.2.1.3
  3. lrwxrwxrwx 1 root root 21 2011-09-16 01:41 libevent-2.0.so.5 -> libevent-2.0.so.5.1.2
  4. -rwxr-xr-x 1 root root 817306 2011-09-16 01:41 libevent-2.0.so.5.1.2
  5. -rw-r--r-- 1 root root 1048354 2011-09-16 01:41 libevent.a
  6. lrwxrwxrwx 1 root root 26 2011-09-16 01:41 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.2
  7. -rwxr-xr-x 1 root root 499865 2011-09-16 01:41 libevent_core-2.0.so.5.1.2
  8. -rw-r--r-- 1 root root 657028 2011-09-16 01:41 libevent_core.a
  9. -rwxr-xr-x 1 root root 968 2011-09-16 01:41 libevent_core.la
  10. lrwxrwxrwx 1 root root 26 2011-09-16 01:41 libevent_core.so -> libevent_core-2.0.so.5.1.2
  11. lrwxrwxrwx 1 root root 27 2011-09-16 01:41 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.2
  12. -rwxr-xr-x 1 root root 335387 2011-09-16 01:41 libevent_extra-2.0.so.5.1.2
  13. -rw-r--r-- 1 root root 391398 2011-09-16 01:41 libevent_extra.a
  14. -rwxr-xr-x 1 root root 975 2011-09-16 01:41 libevent_extra.la
  15. lrwxrwxrwx 1 root root 27 2011-09-16 01:41 libevent_extra.so -> libevent_extra-2.0.so.5.1.2
  16. -rwxr-xr-x 1 root root 933 2011-09-16 01:41 libevent.la
  17. lrwxrwxrwx 1 root root 29 2011-09-16 01:41 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.2
  18. -rwxr-xr-x 1 root root 80238 2011-09-16 01:41 libevent_openssl-2.0.so.5.1.2
  19. -rw-r--r-- 1 root root 86344 2011-09-16 01:41 libevent_openssl.a
  20. -rwxr-xr-x 1 root root 1004 2011-09-16 01:41 libevent_openssl.la
  21. lrwxrwxrwx 1 root root 29 2011-09-16 01:41 libevent_openssl.so -> libevent_openssl-2.0.so.5.1.2
  22. lrwxrwxrwx 1 root root 30 2011-09-16 01:41 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.2
  23. -rwxr-xr-x 1 root root 15733 2011-09-16 01:41 libevent_pthreads-2.0.so.5.1.2
  24. -rw-r--r-- 1 root root 12998 2011-09-16 01:41 libevent_pthreads.a
  25. -rwxr-xr-x 1 root root 996 2011-09-16 01:41 libevent_pthreads.la
  26. lrwxrwxrwx 1 root root 30 2011-09-16 01:41 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.2
  27. lrwxrwxrwx 1 root root 21 2011-09-16 01:41 libevent.so -> libevent-2.0.so.5.1.2
b. 安裝memcached
  1. #cd ..
  2. #tar zxvf memcached-1.4.0.tar.gz
  3. #cd memcached-1.4.0
  4. # ./configure –with-libevent=/usr
  5. # make
  6. # make install


c. 安裝memcache

  1. #cd ..
  2. #tar vxzf memcache-3.0.6.tgz
  3. #cd memcache-3.0.6
  4. #/usr/local/php/bin/phpize
  5. #./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
  6. #make
  7. #make install
  8. #gvim /etc/php5/apache2/php.ini

修改php.ini中的extension_dir = “./”

  1. extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
添加
  1. extension=memcache.so

3: 啟動和關閉

#/usr/local/bin/memcached -d -m 128 -u root -l 127.0.0.1 -p 11211 -c 256 -P /var/temp/memcached.pid

#kill `cat /var/temp/memcached.pid` 或者#killall memcached

重啟apache

sudo /etc/init.d/apche2 restart


4:測試

< ?php
$mem = new Memcache;
$mem->connect(“127.0.0.1″, 11211);
$mem->set(‘key’, ‘This is a test!’, 0, 60);
$val = $mem->get(‘key’);
echo $val;
?>

5: Ubuntu/debian 。

直接sudo

sudo apt-get install memcached

啟動

memcached -d -m 128 -p 11211 -u root -l 127.0.0.1

太輕松了。。。

Copyright © Linux教程網 All Rights Reserved