Monday, December 5, 2011

How To Install memcached with memcache PHP Extension on CentOS 5.x

Nguồn: http://www.sohailriaz.com/how-to-install-memcached-with-memcache-php-extension-on-centos-5x/

In this how to i will describe how to install memcached on your server with PHP Extension. memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. My server is running CentOS 5.3 with CPanel.

1) Install memcached.

Enable rpmforge respository to install latest memcached rpm using yum.

For i386 / i686

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

For x86_64

rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

Use yum to install memcached

yum -y install memcached

As soon as memcached installation completed, edit options for memcached in /etc/sysconfig/memcached to meet your need.

vi /etc/sysconfig/memcached

PORT=”11211″ #define on which port to urn
USER=”nobody” #same as apache user
MAXCONN=”1024″ #maximum number of connections allowed
CACHESIZE=”64″ #memory used for caching
OPTIONS=”" #use for any custom options

Save the file. All options can be seen by using following command

memcached -h

Start memcached

/etc/init.d/memcached start
Starting Distributed memory caching (memcached): [ OK ]

to check the running status of memcached

/etc/init.d/memcached status
memcached (pid 6475) is running…

and

netstat -anp | grep 11211
tcp 0 0 :::11211 :::* LISTEN 6475/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 6475/memcached

2) Install PHP Extension.

Download and install latest stable memcache version from PECL.

cd /usr/src
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
phpize
./configure
make
make install

memcache.so will be install in php modules directory, now enable memcache.so extension in php.ini

To find out your php.ini location, execute following command

php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

vi /usr/local/lib/php.ini

extension = “memcache.so”

save the file and restart httpd server.

/etc/init.d/httpd restart

To check is memcache extension loaded in php, execute following command.

php -i | grep memcache
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user sqlite memcache
PWD => /usr/src/memcache-2.2.5
_SERVER["PWD"] => /usr/src/memcache-2.2.5
_ENV["PWD"] => /usr/src/memcache-2.2.5

This information can also be seen using phpinfo().

http://www.cyberciti.biz/faq/rhel-fedora-linux-install-memcached-caching-system-rpm/

ow do I install memcached a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load under CentOS / RHEL / Fedora / Redhat Linux?

Memcached is very fast caching system for MySQL. It uses libevent or epoll (Linux runtime) to scale to any number of open connections and uses non-blocking network I/O.

Required Packages

  1. memcached : High Performance, Distributed Memory Object Cache.
  2. memcached-selinux : SELinux policy module supporting memcached.
  3. perl-Cache-Memcached : Perl client for memcached.
  4. php-pecl-memcache : Php client / extension to work with the Memcached caching daemon.
  5. python-memcached : A Python memcached client library.

Step # 1: Turn on EPEL Repo

Type the following command to enable EPEL repo which carries required memcache packages.
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
See this FAQ for further details.

Step # 2: Install memcached

Type the following command to install memcached with php extension:
# yum install memcached php-pecl-memcache memcached-selinux
Sample outputs:

Loaded plugins: downloadonly, rhnplugin, security, verify
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package memcached.x86_64 0:1.2.8-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================
Installing:
memcached x86_64 1.2.8-1.el5 epel 60 k
Transaction Summary
==============================================================================================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 60 k
Is this ok [y/N]: y
Downloading Packages:
memcached-1.2.8-1.el5.x86_64.rpm | 60 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : memcached 1/1
Installed:
memcached.x86_64 0:1.2.8-1.el5
Complete!

Step # 3: Configure memcached

Edit /etc/sysconfig/memcached, enter:
# vi /etc/sysconfig/memcached
Update it as follows:

PORT="11211"
USER="memcached"
# max connection 2048
MAXCONN="2048"
# set ram size to 2048 - 2GiB
CACHESIZE="4096"
# listen to loopback ip 127.0.0.1, for network connection use real ip e.g., 10.0.0.4
OPTIONS="-l 127.0.0.1"

The above will starts memcached up as a daemon, using 4GB of memory, and listening on IP 127.0.0.1, port 11211. Save and close the file.

Step # 4: Run memcached

Type the following command to start memcached, enter:
# chkconfig memcached on
# service memcached start

To stop / restart use the following commands:
# service memcached stop
# service memcached restart

How Do I See Memory Memcached Slabs?

Type the following command:
# memcached-tool IP_ADDRESS:Port
# memcached-tool IP_ADDRESS:Port display
# memcached-tool 127.0.0.1:11211

Sample outputs:

  #  Item_Size   Max_age  1MB_pages Count   Full?
1 104 B 5134 s 1 10 no
2 136 B 5135 s 1 40 no
3 176 B 0 s 1 0 no
4 224 B 2648 s 1 7 no
8 552 B 1810 s 1 12 no
9 696 B 1810 s 1 6 no
10 872 B 2935 s 1 8 no
11 1.1 kB 4262 s 1 18 no
12 1.3 kB 2990 s 1 23 no
13 1.7 kB 2434 s 1 22 no
14 2.1 kB 3489 s 1 11 no
15 2.6 kB 2964 s 1 16 no
16 3.3 kB 2861 s 1 14 no
17 4.1 kB 2076 s 1 5 no
18 5.2 kB 2981 s 1 5 no
20 8.1 kB 64 s 1 1 no
21 10.1 kB 1865 s 1 3 no
29 60.2 kB 1550 s 1 2 no

How Do I See Memory Memcached Stats?

Type the following command:
# memcached-tool IP_Address:Port stats
# memcached-tool 127.0.0.1:11211 stats

Sample outputs:

#127.0.0.1:11211   Field       Value
accepting_conns 1
bytes 399395
bytes_read 504797
bytes_written 17313658
cmd_flush 0
cmd_get 1141
cmd_set 248
connection_structures 9
curr_connections 5
curr_items 205
evictions 0
get_hits 898
get_misses 243
limit_maxbytes 1073741824
listen_disabled_num 0
pid 40159
pointer_size 64
rusage_system 0.227965
rusage_user 0.034994
threads 5
time 1255803547
total_connections 344
total_items 259
uptime 5829
version 1.2.8

No comments:

Router Packet Networking

Đây là video ngắn khá hay, mô tả đường đi của một gói tin trên Mạng Internet.