Install Memcached on CentOS
Install Memcached on CentOS
Installation & Configuration
Wget http://memcached.org/latest-O memcached.tar.gz
Tar-zxvf memcached.tar.gz
Cd memcached
./Configure -- prefix =/usr/local/memcached
Make & sudo make install
Ln-sf/usr/local/memcached/bin/memcached/usr/bin/memcached
If '/var/lock/subsys' does not exist, 'mkdir-p/var/lock/subsys 'is created'
Configure system services
Add 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 the IP address is 127.0.0.1, only local access is restricted
# If the IP address is the Intranet IP address of the local machine, it can only be accessed by the Intranet
# The IP address is the IP address used by the application to access Memcached. It is generally 127.0.0.1 or the Local intranet IP address or the local Internet IP address.
IP = 127.0.0.1
PORT = 11211
USER = root
MAXCONN = 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. Pi'
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
;;
Esac
Exit $?
Grant executable permissions: chmod + x/etc/init. d/memcached
Firewall settings
# Setting rules
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.133, 123.7.213.222/32-p udp-m udp -- dport 11211-j ACCEPT
-A input-s 127.0.0.1, 10.170.238.133, 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
Install and configure Memcached source code in CentOS 6.6
Memcached installation and startup script
Performance problems of using Memcached in PHP
Install Memcached in Ubuntu and its command explanation
Install and apply Memcached
Use Nginx + Memcached's small image storage solution
Getting started with Memcached
For details about Memcached, click here
Memcached: click here