Install Memcached on CentOS
Installation & Configuration
wget http://memcached.org/latest -O memcached.tar.gztar -zxvf memcached.tar.gzcd memcached./configure --prefix=/usr/local/memcachedmake && sudo make installln -sf /usr/local/memcached/bin/memcached /usr/bin/memcached
If '/var/lock/subsys' does not exist, create 'mkdir-p/var/lock/subsys 'to configure the system service. Add the file vim/etc/init. d/memcached.
#! /Bin/bash # memcached: MemCached Daemon # chkconfig:-90 25 # description: MemCached Daemon ### begin init info # Provides: memcached # Required-Start: $ syslog # Required-Stop: $ syslog # shocould-Start: $ local_fs # shocould-Stop: $ local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: memcached-Memory caching daemon # Description: memcached-Memory caching daemon ### end init info # If If the IP address is 127.0.0.1, only the local machine can access it. # If the IP address is the Intranet IP address of the Local Machine, only the Intranet can access it. # The IP address is the IP address used by the application to access Memcached, generally 127.0.0.1 or local Intranet IP address or local Internet IP address = 127.0.0.1PORT = 11211 USER = rootMAXCONN = 1024 CACHESIZE = 64 OPTIONS = "" RETVAL = 0 prog = "memcached" start () {echo-n $ "Starting $ prog: "/usr/local/memcached/bin/memcached-d-l $ IP-p $ PORT-u $ USER-m $ CACHESIZE-c $ MAXCONN-P/var/run/ memcached. pid $ OPTIONS if ["$? "! = 0]; then echo "failed" exit 1 else touch/var/lock/subsys/memcached echo "done" fi} stop () {echo-n $ "Stopping $ prog: "if [! -E/var/run/$ prog. pid]; then echo-n $ "$ prog is not running. "exit 1 fi kill 'cat/var/run/memcached. pid 'If ["$? "! = 0]; then echo "failed" exit 1 else rm-f/var/lock/subsys/memcached rm-f/var/run/memcached. pid echo "done" fi} restart () {$0 stop sleep 2 $0 start} # See how we were called. case "$1" in start) start; stop) stop; restart | reload) restart; *) echo $ "Usage: $0 {start | stop | status | restart | reload} "exit 1; esacexit $?
Grant executable permissions: chmod + x/etc/init. d/memcached firewall settings
# Set the rule vim/etc/sysconfig/iptables # if some machines are limited to access, you can set the following settings:-a input-s 127.0.0.1, 10.170.238.htm, 123.7.213.222/32-p udp-m udp -- dport 11211-j ACCEPT-A INPUT-s 127.0.0.1, 10.170.238.large, 123.7.213.222/32-p tcp-m tcp -- dport 11211-j ACCEPT-A INPUT-p tcp-m tcp -- dport 11211-j DROP-A INPUT-p udp-m udp -- dport 11211-j DROP # restart iptables to make the rule take effect. service iptables restart
Start/etc/init. d/memcached start