灌Memcached於Fedora 17/16, CentOS(RHEL) 6.3/5.8

在部分舊版的fedora或是CentOS上,直接用yum是沒有辦法裝memcached的。所以這種時候,必須要引入額外的repositories

(1)安裝Remi repository (Fedora 12~17, RHEL 6不需要)

## Remi Dependency on CentOS and Red Hat (RHEL)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

(2) 安裝memcached的軟体包(package)
如果是fedora 17/16/15/14/13/12或CentOS 6.3/6.2/6.1/6

yum install memcached

如果是 CentOS 5.8

yum --enablerepo=remi install memcached

(3) 設置memcached

vim /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="512"
OPTIONS=""

(4) 啟動memcached

# Set Memcached to start automatically on boot
chkconfig memcached on
# Start Memcached
/etc/init.d/memcached start
## OR ##
service memcached start

(5) 檢查memcached是否正常的運作。

echo stats | nc localhost 11211
STAT pid 7599
STAT uptime 10
STAT time 1265288542
STAT version 1.4.4
STAT pointer_size 32
STAT rusage_user 0.003999
STAT rusage_system 0.052991
STAT curr_connections 10
STAT total_connections 11
STAT connection_structures 11
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 6
STAT bytes_written 0
STAT limit_maxbytes 536870912
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
END

# Try to get some value
echo get some_value | nc localhost 11211
END

# Not found, but check the stats again
echo stats | nc localhost 11211
STAT pid 7599
STAT uptime 10
STAT time 1265288542
STAT version 1.4.4
[...]
STAT cmd_get 1
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 1
STAT delete_misses 0
[...]
STAT evictions 0
END

(6) 打開firewall

加下方的 INPUT 規則:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT

重新啟動 Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

 

在cpanel/WHM的centos主機上灌php的memcached擴展

如果運氣好的話,用下方的指令就可以搞定了。
yum install php php-pecl-memcache

直接用yum install安裝,有時候會因為repo的問題而裝不起來。所以用tarball來裝,反而快。

Step 1 – 下載memcache
mkdir repo
cd repo
wget  http://pecl.php.net/get/memcache-3.0.6.tgz
tar -xvfz memcache-3.0.6.tgz

Step 2 – 編繹 & 安裝
cd memcache-3.0.6
phpize

這時候,應該會看到類似的訊息:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
./configure
make
make install

Step 3 – 修改php.ini
在php中,啟用memcache
echo "extension=memcache.so" >> /usr/local/lib/php.ini
service httpd restart