tar -zxvf libevent-1.4.9-stable.tar.gz -C /usr/src/
cd /usr/src/libevent-1.4.9-stable/
./configure --prefix=/usr/local/libevent
make && make install 安装Memcached
rpm -e php php-cli php-ldap php-common php-mysql --nodeps
//忽略依赖关系卸载系统已安装的RPM包软件(如果有的话,最好输入确认下)
tar -zxvf libmcrypt-2.5.8.tar.gz -C /usr/src/
cd /usr/src/libmcrypt-2.5.8/
./configure && make && make install
ln -s /usr/local/lib/libmcrypt.* /usr/lib/
tar -zxvf mhash-0.9.9.9.tar.gz -C /usr/src/
cd /usr/src/mhash-0.9.9.9/
./configure && make && make install
ln -s /usr/local/lib/libmhash.* /usr/lib/
tar -zxvf mcrypt-2.6.8.tar.gz -C /usr/src/
cd /usr/src/mcrypt-2.6.8/
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
./configure && make && make install 安装PHP
tar -zxvf php-5.3.28.tar.gz -C /usr/src/
cd /usr/src/php-5.3.28/
./configure --prefix=/usr/local/php --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php --enable-mbstring --with-mysql=/usr/local/mysql/
选项:
--with-mcrypt:加载数据加密等扩展工具支持
--with-apxs2:设置Apache HTTP Server提供的apxs模块支持程序的文件位置
--with-config-file-path:设置PHP的配置文件php.ini将要存放的位置
--enable-mbstring:启动多字节字符串功能,以便支持中文等代码
--with-mysql:设置MySQL数据库服务程序的安装位置
make && make install PHP配置(LAMP+Memcache)
cp /usr/src/php-5.3.28/php.ini-development /usr/local/php/php.ini
//拷贝PHP模板文件到PHP工作目录
vim /usr/local/php/php.ini
226 short_open_tag = On //允许识别PHP短语法标记,即
784 default_charset = "utf-8" //设置默认字符集为utf-8,注意删除前面";"
tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/
cp php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/
vim /usr/local/php/php.ini
zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so
zend_loader.enable=1
vim /usr/local/httpd/conf/httpd.conf
310 AddType application/x-httpd-php .php
167 DirectoryIndex index.php index.html
httpd -t
/etc/init.d/httpd start
vim /usr/local/httpd/htdocs/test1.php //测试PHP网页能否正确显示
vim /usr/local/httpd/htdocs/test3.php
3.安装Memcache(LAMP+Memcache)
tar -zxvf memcache-2.2.7.tgz -C /usr/src/
cd /usr/src/memcache-2.2.7/
/usr/local/php/bin/phpize //根据系统信息生成对应的configure文件
若出现报错:
……
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
解决方法:
yum -y install autoconf
注:以上为解决方案,只当执行"/usr/local/php/bin/phpize"报错时使用
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
make && make install
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ //复制扩展目录
vim /usr/local/php/php.ini
819 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/" //指定目录
820 extension = memcache.so //启动扩展模块
/etc/init.d/httpd restart
vim /usr/local/httpd/htdocs/test2.php
yum -y install telnet
telnet 192.168.1.100 11211 //连接Memcached的11211端口
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
set key 0 60 2
( key:键值key-value结构中的key,用于查找缓存值
flags:可以包括键值对的整型参数,客户机使用它存储关于键值对的额外信息
exptime:在缓存中保存键值对的时间长度(以秒为单位,0 表示永远)
bytes:在缓存中存储的字节数
noreply(可选):该参数告知服务器不需要返回数据
value:存储的值(始终位于第二行)(可直接理解为key-value结构中的value)
key → key
flag → 0
exptime → 600 (以秒为单位)
bytes → 2(数据存储的字节数)
value → hehe
)
he //设置保存key的值
STORED //服务器返回结果,该处代表保存成功
get key //获取key对应的键值
VALUE key 0 2
he
END
stats //显示当前所有 Memcache 服务器运行的状态信息
STAT pid 12863 //memcached 启动的进程 ID
STAT uptime 4008 //到目前为止启动了多少秒
STAT time 1464713917 //Unix时间(从1970年1月1日开始统计的秒数)
STAT version 1.2.6 //memcached 的版本信息
STAT pointer_size 64 //当前操作系统的指针大小
STAT rusage_user 0.278957 //进程的累计用户时间
STAT rusage_system 0.371943 //进程的累计系统时间
STAT curr_items 1 //服务器当前存储的items数量
STAT total_items 2 //从服务器启动以后存储的items总数量
STAT bytes 79 //当前服务器存储items占用的字节数
STAT curr_connections 2 //当前的并发连接数
STAT total_connections 4 //总的连接数
STAT connection_structures 3 //服务器分配的连接构造数
STAT cmd_get 2 //执行 get 命令的次数
STAT cmd_set 2 //执行 set 命令的次数
STAT get_hits 2 //get 的命中次数
STAT get_misses 0 //get 的非命中数
STAT evictions 0 //为获取空闲内存而删除的 items 数
STAT bytes_read 98 //总读取字节数(请求字节数)
STAT bytes_written 97 //总发送字节数(结果字节数)
STAT limit_maxbytes 33554432 //允许使用的最大内存容量
STAT threads 1 //当前线程数
END
quit //退出
Connection closed by foreign host. 2.总结 错误
Memcache 的协议的错误部分主要是三个错误提示之提示指令