Linuxでmemcacheをインストール

1.サーバー側のインストール
1.1 memcachedのダウンロード
wget http://www.monkey.org/~provos/libevent-1.3.tar.gz

1.2 libeventのインストール
[root@localhost ~]# tar -zxvf libevent-1.3.tar.gz -C ../software/
[root@localhost ~]# cd ../software/libevent-1.3/
[root@localhost ~]# ./configure –prefix=/usr
[root@localhost ~]# make
[root@localhost ~]# make install
[root@localhost ~]# ls -al /usr/lib |grep libevent
lrwxrwxrwx 1 root root 22 Dec 13 21:15 libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
-rwxr-xr-x 1 root root 31736 Jul 13 2006 libevent-1.1a.so.1.0.2
lrwxrwxrwx 1 root root 21 Dec 20 09:59 libevent-1.3.so.1 -> libevent-1.3.so.1.0.3
-rwxr-xr-x 1 root root 260084 Dec 20 09:59 libevent-1.3.so.1.0.3
-rw-r–r– 1 root root 331260 Dec 20 09:59 libevent.a
-rwxr-xr-x 1 root root 805 Dec 20 09:59 libevent.la
lrwxrwxrwx 1 root root 21 Dec 20 09:59 libevent.so -> libevent-1.3.so.1.0.3

1.3 memcachedのインストール
[root@localhost ~]# cd memcached-1.4.5/
[root@localhost ~]# ./configure -with-libevent=/usr
[root@localhost ~]# make
[root@localhost ~]# make install
/usr/local/bin/memcached
[root@localhost ~]# cd /usr/local/bin/
[root@localhost bin]# ls
iperf memcached unrar

1.4 memcached を実行

[root@localhost bin]# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.250.111 -p 11211 -c 256 -P /tmp/memcached.pid

[root@localhost softpacket]# netstat -anlpt |grep 11211
tcp 0 0 192.168.250.111:11211 0.0.0.0:* LISTEN 11129/memcached

2.クライアント側のインストール
2.1 php拡張のインストール
[root@localhost softpacket]# tar -zxvf memcache-3.0.5.tgz -C ../software/
[root@localhost software]# cd memcache-3.0.5/
[root@localhost memcache-3.0.5]# ls
config9.m4 memcache_ascii_protocol.c memcache.php memcache_session.c
config.m4 memcache_binary_protocol.c memcache_pool.c memcache_standard_hash.c
config.w32 memcache.c memcache_pool.h php_memcache.h
CREDITS memcache_consistent_hash.c memcache_queue.c README
example.php memcache.dsp memcache_queue.h

[root@localhost memcache-3.0.5]# /usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

[root@localhost memcache-3.0.5]# ./configure –enable-memcache –with-php-config=/usr/local/php5/bin/php-config –with-zlib-dir
[root@localhost memcache-3.0.5]#make
[root@localhost memcache-3.0.5]#make install

2.2 php.iniを編集、memcacheの拡張モジュールを追加
extension=memcache.so

2.3 apacheが再起動
connect('127.0.0.1’, 11211) or die (“接続できない");
$version = $memcache->getVersion();
echo “Server’s version: “.$version."\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test’;
$tmp_object->int_attr = 123;
$memcache->set('key’, $tmp_object, false, 10) or die (“サーバー側でデータの保存に失敗した");
echo “Store data in the cache (data will expire in 10 seconds)\n";
$get_result = $memcache->get('key’);
echo “Data from the cache:\n";
var_dump($get_result);
?>

2.4 memcache環境でテスト
connect('127.0.0.1’, 11211) or die (“Could not connect");
$version = $memcache->getVersion();
echo “Server’s version: “.$version."\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'startnews24’;
$tmp_object->int_attr = com;
$memcache->set('key’, $tmp_object, false, 10) or die (“Failed to save data at the server");
echo “Store data in the cache (data will expire in 10 seconds)\n";
$get_result = $memcache->get('key’);
echo “Data from the cache:\n";
var_dump($get_result);
?>

Linux

Posted by arkgame