centos memcached安裝

來源:互聯網
上載者:User

標籤:centos   memcached   安裝   

1、安裝libevent

安裝memcached前需要先安裝libevent

wget http://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz

 tar zxvf libevent-2.0.22-stable.tar.gz 

 cd libevent-2.0.22-stable

   ./configure 

  make && make install

2、安裝memcached

 wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz

 tar zxvf memcached-1.2.7.tar.gz

 cd memcached-1.2.7

 ./configure

 make && make install

注意:make的時候報錯

memcached.c: 在函數‘add_iov’中:

memcached.c:696:30: 錯誤: ‘IOV_MAX’未聲明(在此函數內第一次使用)

memcached.c:696:30: 附註: 每個未聲明的標識符在其出現的函數內只報告一次

make[2]: *** [memcached-memcached.o] 錯誤 1

需要修改 memcached.c 檔案:

複製代碼

/* FreeBSD 4.x doesn‘t have IOV_MAX exposed. */

#ifndef IOV_MAX

#if defined(__FreeBSD__) || defined(__APPLE__)

# define IOV_MAX 1024

#endif

#endif


改成:


/* FreeBSD 4.x doesn‘t have IOV_MAX exposed. */

#ifndef IOV_MAX

# define IOV_MAX 1024

#endif

複製代碼

再make&&make install,編譯之後退出root使用者。

安裝完成後memcached的預設目錄為/usr/local/bin/memcached

3、啟動memcached

/usr/local/bin/memcached -m 32m -p 11211 -d -u root -P /var/run/memcached.pid -c 256

啟動時報如下錯誤的解決方案

/usr/local/bin/memcached: error while loading shared libraries: libevent-2.0.22.so.1: cannot open shared object file: No such file or directory

找不到libevent-2.0.22.so的解決方案

echo "/usr/local/lib" >> /etc/ld.so.conf

ldconfig

啟動參數說明:
-d 選項是啟動一個守護進程。
-u root 表示啟動memcached的使用者為root。
-m 是分配給Memcache使用的記憶體數量,單位是MB,預設64MB。
-M return error on memory exhausted (rather than removing items)。
-u 是運行Memcache的使用者,如果當前為root 的話,需要使用此參數指定使用者。
-l 是監聽的伺服器IP地址,預設為所有網卡。
-p 是設定Memcache的TCP監聽的連接埠,最好是1024以上的連接埠。
-c 選項是最大啟動並執行並發串連數,預設是1024。
-P 是設定儲存Memcache的pid檔案。
-f <factor> chunk size growth factor (default: 1.25)。
-I Override the size of each slab page. Adjusts max item size(1.4.2版本新增)。  也可以啟動多個守護進程,但是連接埠不能重複

測試啟動是否正常

telnet localhost 11211
2.查看memcached啟動命令
ps aux|grep memcached
 
2.1.2. 停止memcached

kill ‘cat /var/run/memcached/pid‘

6、安裝Memcache的PHP擴充

wget http://pecl.php.net/get/memcache-2.2.5.tgz

tar zxvf memcache-2.2.5.tar.gz

cd memcache-2.2.5

/home/webserver/php/bin/phpize

./configure --enable-memcache --with-php-config=/home/webserver/php/bin/php-config

make && make install

安裝完成後會出現如下提示

Installing shared extensions:

/home/webserver/php/lib/php/extensions/no-debug-non-zts-20121212/

修改php.ini檔案 

把extension_dir = “./” 修改為extension_dir = “/home/webserver/php/lib/php/extensions/no-debug-non-zts-20121212/”

添加如下一行代碼

extension=memcache.so

7、測試Memcache的PHP是否安裝成功

運行如下代碼

<?php

$mem = new Memcache;

$mem->connect( ‘127.0.0.1‘ , 11211);

$mem->set (‘test‘ , "hello world!" , 0 ,12);

$val = $mem->get( ‘test‘);

echo $val;

?>

   

centos memcached安裝

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.