Download: http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
In addition, memcache uses the libevent library for socket processing, so you also need to install libevent, the latest version of libevent is the libevent-1.3. (If your system has already installed libevent, you do not need to install it)
Official Website: http://www.monkey.org /~ Provos/libevent/
Download: http://www.monkey.org /~ Provos/libevent-1.3.tar.gz
Use the wget command to directly download these two items.
1. Install libevent first. During configuration, You need to specify an installation path, that is,./configure-prefix =/usr; then make install;
2. install memcached again. You only need to specify the installation path of libevent during configuration, that is,./configure-with-libevent =/usr; then make install;
This completes the installation of the memcache server in linux. The detailed method is as follows:
1. Download memcached and libevent respectively and put them in the/tmp directory:
Copy codeThe Code is as follows: # cd/tmp
# Wget http://www.3ppt.com/memcached/dist/memcached-1.2.0.tar.gz
# Wget http://www.monkey.org /~ Provos/libevent-1.2.tar.gz
2. Install libevent first:
# Tar zxvf libevent-1.2.tar.gz
# Cd libevent-1.2
#./Configure-prefix =/usr
# Make
# Make install
(Note: an error occurs during execution here:
1, no acceptable c compiler found in $ path
Because gcc is not installed on centos by default, yum is used for installation.
# Yum install gcc * make *
)
3. test whether the libevent is successfully installed:Copy codeThe Code is as follows: # ls-al/usr/lib | grep libevent
Lrwxrwxrwx 1 root 21 11 ?? Libevent-1.2.so.1> libevent-1.2.so.1.0.3
-Rwxr-xr-x 1 root 263546 11 ?? Libevent-1.2.so.1.0.3
-Rw-r-1 root 454156 11 ?? 12 libevent.
-Rwxr-xr-x 1 root 811 11 ?? Libevent. la
Lrwxrwxrwx 1 root 21 11 ?? 12 libevent. so-> libevent-1.2.so.1.0.3
Not bad. They all have been installed.
4. Install memcached and specify the libevent installation location during installation:Copy codeThe Code is as follows: # cd/tmp
# Tar zxvf memcached-1.2.0.tar.gz
# Cd memcached-1.2.0
#./Configure-with-libevent =/usr
# Make
# Make install
If an error is reported in the middle, check the error information carefully and configure or add the corresponding library or path according to the error information.
(Note: an error occurs during installation:
1 linux warning: A clock error is detected. Your creation may be incomplete
Solution:
Modify current time:
[Root] # date-s '2017/5 8:01:00'
Write the current system time to cmos
# Clock-w
)
After the installation is complete, the memcached will be placed in/usr/local/bin/memcached,
5. Test whether memcached is successfully installed:Copy codeThe Code is as follows: # ls-al/usr/local/bin/mem *
-Rwxr-xr-x 1 root 137986 11 ?? 12 :39/usr/local/bin/memcached
-Rwxr-xr-x 1 root 140179 11 ?? 12 :39/usr/local/bin/memcached-debug
Php tutorial extension for installing memcache
1. Select the desired memcache version in the http://pecl.php.net/package/memcache.
2. Install memcache extension for phpCopy codeThe Code is as follows: tar vxzf memcache-2.2.1.tgz
Cd memcache-2.2.1
/Usr/local/php/bin/phpize
./Configure-enable-memcache-with-php-config =/usr/local/php/bin/php-config-with-zlib-dir
Make
Make install
(Note:
1 phpize not found
Solution:
By default, centos does not install php-devel.
Yum install php-devel
2 make: *** [memcache. lo] error 1
Zlib Not Installed
Yum install zlib-devel
3. Change the configuration command to./configure -- enable-memcache -- with-php-config =/usr/bin/php-config -- with-zlib-dir.
Here, enable and with are preceded by two --
)
3. A message similar to this will appear after the above installation:
Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/
4. Modify extension_dir = "./" in php. ini
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx /"
5. Add a row to load the memcache extension: extension = memcache. so
Basic settings of memcached:
1. Start the memcache Server:
#/Usr/local/bin/memcached-d-m 10-u root-l 192.168.0.200-p 12000-c 256-p/tmp/memcached. pid
-D option is to start a daemon,
-M indicates the amount of memory allocated to memcache. The unit is mb. Here I am 10 mb,
-U is the user who runs memcache. Here I am root,
-L is the IP address of the listening server. If there are multiple IP addresses, I have specified the IP address 192.168.0.200,
-P is the port for memcache listening. I have set port 12000 here, preferably port 1024 or above,
-The "c" option is the maximum number of concurrent connections. The default value is 1024. I have set 256 here, which is based on the load of your server,
-P is the pid file for saving memcache. Here I save it in/tmp/memcached. pid,
(Note:
1
An error occurred:/usr/local/bin/memcached: error while loading shared libraries: libevent-1.3.so.1: cannot open shared object file: no such file or directory
Set link directly
# Ln-s/usr/local/libevent/lib/libevent-1.3.so.1/lib64/libevent-1.3.so.1
)
2. to end the memcache process, run:
# Kill 'cat/tmp/memcached. Pi'
You can also start multiple daemon processes, but the ports cannot be repeated.
3. restart apache and service httpd restart
Test the memcache environment:
Run the following PHP file. If this is a test! is output !, Indicates that the environment is successfully set up. Start to appreciate the charm of memcache!Copy codeThe Code is as follows: <? Php
$ Mem = new memcache;
$ Mem-> connect ("192.168.0.200", 12000 );
$ Mem-> set ('key', 'This is a test! ', 0, 60 );
$ Val = $ mem-> get ('key ');
Echo $ val;
?>