在部分舊版的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