Your website may encounter access bottlenecks. How to solve this problem has always been a dark cloud on the project team.
Because I have no experience in creating too many websites, I collected a lot of information on the Internet, so I learned about memcached and its application.
I. Prepare the compilation environment
Bytes ---------------------------------------------------------------------------------------------------------
Yum install gcc
Yum install gcc-C ++ libstdc ++-devel
Yum install zlib-devel
Bytes ---------------------------------------------------------------------------------------------------------
Ii. source code package preparation
The server is mainly installed on the memcache server, the latest version is memcached-v1.4.13.
Wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
In addition, memcache uses the libevent library for socket processing, so you also need to install libevent
Wget
Https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz -- no-check-Certificate
Prepare the memcached PHP extension source code installation package:
Wget http://pecl.php.net/get/memcache-3.0.6.tgz
Iii. installation and configuration
1. Compile and install libevent
./Configure -- prefix =/usr
Make & make install
Test whether the libevent is successfully installed:
Ls-Al/usr/lib | grep libevent
2. Install memcached and specify the libevent installation location during installation.
./Configure -- With-libevent =/usr
Make & make install
Test whether memcached is successfully installed:
Ls-Al/usr/local/bin/MEM *
3. Enable the memcached daemon
Bytes ---------------------------------------------------------------------------------------------------------
Memcached-D-u Root
Bytes ---------------------------------------------------------------------------------------------------------
# Connection Parameters
-P listening port
-L connected IP address. The default value is local
-D start: Start the memecache service.
-D restart
-D stop | Shutdown
-D install
-D uninstall
-U is only valid for running as root
-M maximum memory usage, unit MB, default 64 MB, maximum 2G
-An error is returned when M memory is exhausted.
-C maximum number of simultaneous connections. The default value is 1024.
-The F block size increases because the default value is 1.25.
-N: minimum space allocated. The default value is key + value + flags.
-H Show Help
4. Use telnet to test whether the installation is successful
Bytes ---------------------------------------------------------------------------------------------------------
Telnet local host 11211
# A client error occurs when you press Enter.
Quit # exit
Bytes ---------------------------------------------------------------------------------------------------------
Iv. php extension Installation
1. Compile and install libmemcached
Bytes ---------------------------------------------------------------------------------------------------------
./Configure -- prefix =/usr/local/libmemcached
Make & make install
Bytes ---------------------------------------------------------------------------------------------------------
2. Find the phpize directory.
Bytes ---------------------------------------------------------------------------------------------------------
Find/-name phpize
Bytes ---------------------------------------------------------------------------------------------------------
Enter the value based on the returned value. In centos, it is generally/usr/bin/phpize.
3. install PHP-memcache
Bytes ---------------------------------------------------------------------------------------------------------
/Usr/bin/phpize
./Configure -- enable-memcache -- With-PHP-Config =/usr/bin/PHP-config -- prefix =/usr/local/memcached -- With-zlib-Dir
#. /Configure -- With-PHP-Config =/usr/bin/PHP-config -- prefix =/usr/local/memcached -- With-libmemcached-Dir =/usr/local/libmemcached
Make & make install
Bytes ---------------------------------------------------------------------------------------------------------
After the installation is complete, the following message is displayed:
Installing shared extensions:/usr/lib/PHP/modules/
4. Modify the PHP configuration
Modify extension_dir = "./" in PHP. ini
Bytes ---------------------------------------------------------------------------------------------------------
Extension_dir = "/usr/lib/PHP/extensions/no-debug-non-zts-2007xxxx /"
Extension = memcached. So
Bytes ---------------------------------------------------------------------------------------------------------
5. Some instructions
The following warning message may exist during installation:
Bytes ---------------------------------------------------------------------------------------------------------
# Configure: Warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
Wget
Http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
Tar-zxvf re2c-0.13.5.tar.gz
CD re2c-0.13.5
./Configure & make install
Bytes ---------------------------------------------------------------------------------------------------------