I. Installation of libevent development kits
The code is as follows |
Copy Code |
Yum Install Libevent-devel
|
Second, install memcached
We get memcached installation package memcached-1.4.15.tar.gz from http://memcached.org/.
1. Configuration (Specify installation directory via parameter prefix)
The code is as follows |
Copy Code |
./configure--prefix=/usr/local/memcached--ENABLE-SASL
|
2. Compiling and installing
The code is as follows |
Copy Code |
Make Make install
|
Iii. installation of libmemcached
Download the installation package libmemcached-1.0.15.tar.gz from the http://libmemcached.org/.
Configuration, compilation, and installation (–with-memcached specifies memcached execution program)
The code is as follows |
Copy Code |
./configure--with-memcached=/usr/local/memcached/bin/memcached Make Make install |
Iv. Installing PHP memcached Extensions
The code is as follows |
Copy Code |
/usr/local/php/bin/pecl Install memcached |
If you encounter this error:
Error while loading shared Libraries:libevent-1.4.so.2:cannot open Shared object file:no such file or directory
Indicates that although the Libevent 2.0 library is installed, it cannot be found in the system library because it was not added to the system library after installation and only exists in the user library:
Make a soft connection ln-s/usr/local/libevent/lib/libevent-1.4.so.2
/usr/lib/libevent-1.4.so.2 5. (or copy libevent-1.4.so.2 to/usr/lib/, or you can
Startup parameters:
-D Sets the memory size that the memcached can use in a daemon (daemon) mode, with the M-m setting memcached does not lru-l set the IP address of the listener, and if this is the case, this parameter can usually not be set;-P Set the listening port, the default is 11211, so you can also not set this parameter;-u specifies the user, if the current is root, you need to use this parameter to specify the user. -P Records memcache run PID to file/usr/local/bin/memcached.pid-n set the initial chunk size-f chunk size factor growth factor, default is 1.25
for boot startup , memcached is not registered as a system service, so the startup mode is slightly different:
The code is as follows |
Copy Code |
# echo "/usr/local/bin/memcached-d-M 10-u root-l 192.168.5.47-p 12000-p/tmp/memcached.pid" >>/etc/rc.d/rc.loc Al |
Test memcached:
The code is as follows |
Copy Code |
[root@localhost/]# telnet 192.168.141.64 12000 Trying 192.168.141.64 ... Connected to 192.168.141.64 (192.168.141.64). Escape character is ' ^] '. Set Key1 0 60 4 Zhou STORED Get Key1 VALUE Key1 0 4 Zhou End |
This memcached installation is successful!
Create a Memcached object
code is as follows |
copy code |
<?php /* Create a Normal object */ $m 1 = new Memcached (); Echo Get_class ($m); /* Create persistent Object */ $m 2 = new Memcached (' Story_pool '); $m 3 = new Memcached (' Story_pool '); /* Now $M2 and $M3 share the same connection */ |