1,通过yum安装
复制代码 代码如下:
yum -y install memcached
安装完成后执行:
memcached -h
出现memcached帮助信息说明安装成功
2,加入启动服务
复制代码 代码如下:
chkconfig –level 2345 memcached on
3, 配置Memcached
复制代码 代码如下:
vim /etc/sysconfig/memcached
文件中内容如下,按需要修改:
PORT=”11211” #端口
USER=”root” #用户名
MAXCONN=”1024” #最大连接数
CACHESIZE=”64” #内存大小
OPTIONS=”” #附加参数
4,安装libmemached
复制代码 代码如下:
wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
tar -zxvf libmemcached-1.0.16.tar.gz
cd libmemcached-1.0.16
./configure
make && make install
5,安装php-devel
复制代码 代码如下:
yum install php-devel
6,安装PHP Memcached扩展
复制代码 代码如下:
wget http://pecl.php.net/get/memcached-2.1.0.tgz
tar -zxvf memcached-2.1.0.tgz
cd memcached-2.1.0
phpize
(如果显示没有安装显示没有安装phpize:-bash: phpize: command not found
请输入命令:yum install php-devel //安装phpize
再次输入命令:phpize
)
./configure –with-php-config=/usr/bin/php-config –with-libmemcached-dir=/usr/local/libmemcached –disable-memcached-sasl
make && make install
7,vi /etc/php.d/memcached.ini 保存退出
复制粘贴以下代码:
; —– Enable memcache extension module
extension=memcached.so
; —– Options for the memcache module
; Whether to transparently failover to other servers on errors
;memcache.allow_failover=1
; Data will be transferred in chunks of this size
;memcache.chunk_size=32768
; Autocompress large data
;memcache.compress_threshold=20000
; The default TCP port number to use when connecting to the memcached server
;memcache.default_port=11211
; Hash function {crc32, fnv}
;memcache.hash_function=crc32
; Hash strategy {standard, consistent}
;memcache.hash_strategy=consistent
; Defines how many servers to try when setting and getting data.
;memcache.max_failover_attempts=20
; The protocol {ascii, binary} : You need a memcached >= 1.3.0 to use the binary protocol
; The binary protocol results in less traffic and is more efficient
;memcache.protocol=ascii
; Redundancy : When enabled the client sends requests to N servers in parallel
;memcache.redundancy=1
;memcache.session_redundancy=2
; Lock Timeout
;memcache.lock_timeout = 15
; —– Options to use the memcache session handler
; Use memcache as a session handler
;session.save_handler=memcache
; Defines a comma separated of server urls to use for session storage
;session.save_path=”tcp://localhost:11211?persistent=1&weight=1&timeout=1&retry_interval=15”
最后:wq保存退出。
8,重启apache服务:systemctl restart httpd.service