Install Memcache on CentOS
- Download and install the Memcache Server
- The server is mainly used to install the memcache server.
- 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
- Libevent has been installed. 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; then makeinstall;
- 2. Install memcached again. You only need to specify the installation path of libevent during configuration, that is,./configure-with-libevent =/usr; then make; then makeinstall
- ;
- 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
- # Wgethttp: // www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
- # Wgethttp: // www.monkey.org /~ Provos/libevent-1.2.tar.gz
- 2. Install libevent first:
- #Tarzxvflibevent-1.2.tar.gz
- # Cdlibevent-1.2
- #./Configure-prefix =/usr
- # Make
- # Makeinstall
- 3. test whether the libevent is successfully installed:
- # Ls-al/usr/lib | greplibevent
- Lrwxrwxrwx1rootroot2111 ?? 1217: 38libevent-1.2.so.1-> libevent-1.2.so.1.0.3
- -Rwxr-xr-x1rootroot26354611 ?? 1217: 38libevent-1.2.so.1.0.3
- -Rw-r-r-1rootroot45415611 ?? 1217: 38libevent.
- -Rwxr-xr-x1rootroot81111 ?? 1217: 38libevent. la
- Lrwxrwxrwx1rootroot2111 ?? 1217: 38libevent. 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:
- # Cd/tmp
- #Tarzxvfmemcached-1.2.0.tar.gz
- # Cdmemcached-1.2.0
- #./Configure-with-libevent =/usr
- # Make
- # Makeinstall
- 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.
- 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-x1rootroot13798611 ?? 12:39/usr/local/bin/memcached
- -Rwxr-xr-x1rootroot14017911 ?? 12:39/usr/local/bin/memcached-debug
- Start Memcached:
- 1. Start the Memcache Server:
- #/Usr/local/bin/memcached-d-m10-uroot-l192.168.141.64-p12000-c256-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,
- 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.
- Test Memcached:
- Enter
- Copy code
- [Root @ localhost/] # telnet192.168.1.24838511
- Trying192.168.141.64...
- Connectedto192.168.1.248 (192.168.1.248 ).
- Escapecharacteris '^]'.
- Problem: If telent fails to be enabled, enable telent on the computer, click Control Panel, programs and functions, and click enable or disable the window function. Check the telent server and client.
- Save!
- Enter the following items when a black page appears!
- 1. Input: setkey10604
- 2. Input: zhou
- The following error occurs: STORED.
- 3. Input: getkey1
- The following message is displayed: VALUEkey104
- Zhou
- END
- Copy code
- So far, Memcached has been installed successfully!
- Test the code
- Such similar functions cannot be separated from persistent connections. Transient connections are generally single request data, and the server cannot "push" the data to the client. However, it is much better to use the backend
- Combined with the front-end technical group, the server's "push information" function can be implemented. If there is an update in the database, the backend program can immediately "push out" the data, instead of multiple reverse operations.
- Repeat the request, establish connections multiple times, and disconnect multiple times.
- Because php uses a short connection to connect to memcache, this method is to connect to memcached each time. After the read and write operations are completed, the connection is closed and the next time you need to read and write memcache, the connection is re-connected. Because php reads and writes memcache frequently, php naturally connects to memcache a lot. Creating a connection may incur soft interruptions. So we can see in top that % si will always be very high, 50% ~ 90%.
- Every time we access the PHP script, we get the returned results after all the PHP scripts are executed. If we need a script to run continuously, we need
- Php persistent connection for running purposes.
- Generally, the php environment is apache + php + linux. However, because apache imposes a time limit on php connections, the apache server will automatically disconnect the connection after the connection time is exceeded.