centos memcached php 5.2.17 ius repo

1 安装 IUS repo  自动打开  rpel

 

2.

yum install -y memcached

 

3.

yum install -y gcc make 

 

4.

service memcached start
chkconfig memcached on

pecl install memcache

 

5

php.ini

添加 

 

extension="memcache.so"

 

 

 

Configure Memcached

The most important value to configure is CACHESIZE. For example following configuration shows 512MB memory for Memcached. Edit /etc/sysconfig/memcached file, enter:

# vi /etc/sysconfig/memcached

Sample Output:

PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="512" OPTIONS=""

For high traffic websites you need to increase the following values:

  1. MAXCONN : Set 1024 max simultaneous connections. For high traffic websites increase this value as per requirement.
  2. CACHESIZE : Set 512MB max memory. For high traffic websites you can set it to 1GB.
  3. OPTIONS : Set server IP address so that Apache/php/nginx based server can connect to the server.

My sample updated file:

PORT="11211" USER="memcached" MAXCONN="4096" CACHESIZE="512" OPTIONS="-l 192.168.1.1"

 

How To Start and Stop Memcached

Try the all following commands:

# chkconfig memcached on
# /etc/init.d/memcached start
# /etc/init.d/memcached stop
# /etc/init.d/memcached restart
# /etc/init.d/memcached status

 

Verify Memcached is Running and Working

Run following command to verify if it is running or not.

# netstat -tulpn | grep :11211

Sample Output:

 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 19796/memcached tcp 0 0 :::11211 :::* LISTEN 19796/memcached udp 0 0 0.0.0.0:11211 0.0.0.0:* 19796/memcached udp 0 0 :::11211 :::* 19796/memcached 

Use the memcached-tool to get general stats of server:

# memcached-tool 192.168.1.1 stats

 

Configure Firewall for Memcached

Protect memcached server by allowing access to your own servers. Edit/etc/sysconfig/iptables and append the following rules.

## only accept connection to tcp/udp port 11211 if ip is between 192.168.1.1 and 192.168.1.10 ##
# iptables -A INPUT -p tcp --destination-port 11211 -m state --state NEW -m iprange --src-range 192.168.1.1-192.168.1.10 -j ACCEPT
# iptables -A INPUT -p udp --destination-port 11211 -m state --state NEW -m iprange --src-range 192.168.1.1-192.168.1.10 -j ACCEPT

 

Restart Iptables Firewall

Type the following command to restart iptables.

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

 

Test Remote Connection

Try the following command from remote server to test Memcached is listening or not.

# echo stats | netstat 192.168.1.1 -tulpn | grep :11211

Sample Output:

 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 19796/memcached tcp 0 0 :::11211 :::* LISTEN 19796/memcached udp 0 0 0.0.0.0:11211 0.0.0.0:* 19796/memcached udp 0 0 :::11211 :::* 19796/memcached 

 

Install Memcached PHP Module

 

# yum install php-pecl-memcache

 

Install Memcached Perl Module

 

# yum install perl-Cache-Memcached

 

Install Memcached Python Module

 

#  yum install python-memcached

 

Restart Web Server

 

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

For more information visit memcached project.

Last modified onSaturday, 05 January 2013 13:10

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169

Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
back to top