1.准备安装包:
libevent-2.1.8-stable.tar.gz
memcached-1.5.0.tar.gz
memcache-2.2.7.tgz
2.安装libevent
tar xf /opt/libevent-2.1.8-stable.tar.gz
cd libevent-2.1.8-stable
mkdir /usr/local/libevent
./configure --prefix=/usr/local/libevent
make && make install
echo $?
3.安装memcached
tar xf memcached-1.5.0.tar.gz -C /opt/
mkdir /usr/local/memcached
cd /opt/memcached-1.5.0
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make && make install
id www
memcached参数
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB
-u 是运行Memcache的用户,如果当前为 root 的话,需要使用此参数指定用户。
-l 是监听的服务器IP地址
-p 是设置Memcache监听的端口, 最好是1024以上的端口
-c 是最大运行的并发连接数,默认是1024
-P 是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
4.普通用户启动memcached:
/usr/local/memcached/bin/memcached -d -u www -m 4096 -l 127.0.0.1 -c 10000 -p 11313 -P /tmp/11313.pid
5.检查服务:
[root@localhost memcached-1.5.0]# netstat -lp | grep memcached
tcp 0 0 localhost:11313 *:* LISTEN 19688/memcached
udp 0 0 localhost:11313 *:* 19688/memcached
6.安装php扩展memcache
tar xf /opt/memcache-2.2.7.tgz -C /opt/
cd /opt/memcache-2.2.7
find / -name "php-config"
/usr/local/php/bin/phpize
./configure --enable-memcache=/usr/local/memcached --with-php-config=/usr/local/php/bin/php-config
make &&make install
[root@localhost vhost]# tail -2 /usr/local/php/etc/php.ini
[memcache]
extension = memcache.so
[root@localhost vhost]# tail -2 /usr/local/php/etc/php.ini
[memcache]
extension = memcache.so
7.测试:
cat test.php
<?php
phpinfo()
?>