Install Memcache on CentOS

Source: Internet
Author: User

Install Memcache on CentOS

  1. Download and install the Memcache Server
  2. The server is mainly used to install the memcache server.
  3. Download: http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
  4. 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
  5. Libevent has been installed. You do not need to install it)
  6. Official Website: http://www.monkey.org /~ Provos/libevent/
  7. Download: http://www.monkey.org /~ Provos/libevent-1.3.tar.gz
  8. Use the wget command to directly download these two items.
  9. 1. Install libevent first. During configuration, You need to specify an installation path, that is,./configure-prefix =/usr; then make; then makeinstall;
  10. 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
  11. ;
  12. This completes the installation of the Memcache server in Linux. The detailed method is as follows:
  13. 1. Download memcached and libevent respectively and put them in the/tmp directory:
  14. # Cd/tmp
  15. # Wgethttp: // www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
  16. # Wgethttp: // www.monkey.org /~ Provos/libevent-1.2.tar.gz
  17. 2. Install libevent first:
  18. #Tarzxvflibevent-1.2.tar.gz
  19. # Cdlibevent-1.2
  20. #./Configure-prefix =/usr
  21. # Make
  22. # Makeinstall
  23. 3. test whether the libevent is successfully installed:
  24. # Ls-al/usr/lib | greplibevent
  25. Lrwxrwxrwx1rootroot2111 ?? 1217: 38libevent-1.2.so.1-> libevent-1.2.so.1.0.3
  26. -Rwxr-xr-x1rootroot26354611 ?? 1217: 38libevent-1.2.so.1.0.3
  27. -Rw-r-r-1rootroot45415611 ?? 1217: 38libevent.
  28. -Rwxr-xr-x1rootroot81111 ?? 1217: 38libevent. la
  29. Lrwxrwxrwx1rootroot2111 ?? 1217: 38libevent. so-> libevent-1.2.so.1.0.3
  30. Not bad. They all have been installed.
  31. 4. Install memcached and specify the libevent installation location during installation:
  32. # Cd/tmp
  33. #Tarzxvfmemcached-1.2.0.tar.gz
  34. # Cdmemcached-1.2.0
  35. #./Configure-with-libevent =/usr
  36. # Make
  37. # Makeinstall
  38. 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.
  39. After the installation is complete, the memcached will be placed in/usr/local/bin/memcached,
  40. 5. Test whether memcached is successfully installed:
  41. # Ls-al/usr/local/bin/mem *
  42. -Rwxr-xr-x1rootroot13798611 ?? 12:39/usr/local/bin/memcached
  43. -Rwxr-xr-x1rootroot14017911 ?? 12:39/usr/local/bin/memcached-debug
  44. Start Memcached:
  45. 1. Start the Memcache Server:
  46. #/Usr/local/bin/memcached-d-m10-uroot-l192.168.141.64-p12000-c256-P/tmp/memcached. pid
  47. -D option is to start a daemon,
  48. -M indicates the amount of memory allocated to Memcache. The unit is MB. Here I am 10 MB,
  49. -U is the user who runs Memcache. Here I am root,
  50. -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,
  51. -P is the port for Memcache listening. I have set port 12000 here, preferably port 1024 or above,
  52. -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,
  53. -P is the pid file for saving Memcache. Here I save it in/tmp/memcached. pid,
  54. 2. to end the Memcache process, run:
  55. # Kill 'cat/tmp/memcached. Pi'
  56. You can also start multiple daemon processes, but the ports cannot be repeated.
  57. Test Memcached:
  58. Enter
  59. Copy code
  60. [Root @ localhost/] # telnet192.168.1.24838511
  61. Trying192.168.141.64...
  62. Connectedto192.168.1.248 (192.168.1.248 ).
  63. Escapecharacteris '^]'.
  64. 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.
  65. Save!
  66. Enter the following items when a black page appears!
  67. 1. Input: setkey10604
  68. 2. Input: zhou
  69. The following error occurs: STORED.
  70. 3. Input: getkey1
  71. The following message is displayed: VALUEkey104
  72. Zhou
  73. END
  74. Copy code
  75. So far, Memcached has been installed successfully!
  76. Test the code
  77. 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
  78. 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.
  79. Repeat the request, establish connections multiple times, and disconnect multiple times.
  80. 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%.
  81. 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
  82. Php persistent connection for running purposes.
  83. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.