The server side is mainly to install memcache server side, the current latest version is memcached-1.3.0. Download: www. danga. commemcacheddistmemcached-1... the server side is mainly to install memcache server side, the current latest version is memcached-1.3.0.
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:
# cd /tmp# wget http://www.danga.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:
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:
# ls -al /usr/lib | grep libevent lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3 -rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3 -rw-r-r- 1 root root 454156 11?? 12 17:38 libevent.a -rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
Not bad. they have all been installed.
4. install memcached and specify the libevent installation location during installation:
# 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:
# 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
Install the php extension of memcache
1. select the desired memcache version in the http://pecl.php.net/package/memcache.
2. install memcache extension for php
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 :. /configure -- enable-memcache -- with-php-config =/usr/bin/php-config -- with-zlib-dir, where enable and with are the first 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. error:/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 !, It indicates that the environment has been successfully set up and the memcache charm is appreciated.
connect("192.168.0.200 ", 12000); $mem->set('key', 'this is a test!', 0, 60); $val = $mem->get('key'); echo $val;