Memcached distributed Cache system deployment and debugging

Source: Internet
Author: User
Tags zts

Memcache distributed Cache system deployment and debugging

Working mechanism: By creating an area in memory to maintain a large hash table to speed up the page access speed, and the database is independent, is mainly used to cache the database data, stored in the memory of the data through the LRU algorithm to eliminate the memory; You can also eliminate the data stored in memory by deleting and setting the expiration time.


One memcache installation


1 memcached Server Installation
1.1 Memcached Official Website http://memcached.org/
Current stable version memcached-1.4.10.tar.gz

1.2 memcached relies on the Libevent library to check if the Libevent library is installed before memcached is installed, and if not, you need to install Libevent first
Libevent official website http://libevent.org/
Current stable version libevent-2.0.16-stable
Libevent is an event-triggered network library for Windows, Linux, BSD and other platforms, internal use of Select, Epoll, Kqueue and other system invoke management event mechanism

1.3 Installing Libevent and memcached

    1. # tar ZXVF libevent-2.0.16-stable.tar.gz
    2. # CD Libevent-2.0.16-stable
    3. #./configure --prefix=/usr/local/libevent
    4. # Make && make install
    5. # tar ZXVF memcached-1.4.10.tar.gz
    6. # CD memcached-1.4.10
    7. #./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
    8. # Make && make install


1.4 Simple test

  1. #/usr/local/memcached/bin/memcached-u root-d-M 200-l 127.0.0.1-p 11211-p/var/run/memcached.pid
  2. # PS aux | grep memcache | Grep-v ' grep '
  3. Root 8979 0.0 0.2 64732 1072? SSL 12:03 0:00/usr/local/memcached/bin/memcached-u root-d-M 200-l 127.0.0.1-p 11211-p/var/run/memcached.pid
  4. # Lsof-i: 11211
  5. COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
  6. memcached 8999 root 26u IPv4 12244 TCP one.t.com:11211 (LISTEN)
  7. memcached 8999 root 27u IPv4 12245 UDP one.t.com:11211



2 Memcache Client Installation
2.1 PHP Memcache Client
Http://pecl.php.net/package/memcache
Current stable version memcache-2.2.6.tgz

  1. # tar ZXVF memcache-2.2.6.tgz
  2. # CD memcache-2.2.6
  3. #/usr/local/php/bin/phpize
  4. #./configure--enable-memcache --with-php-config=/usr/local/php/bin/php-config
  5. # Make && make install
  6. Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
  7. # Vim/etc/php.ini
  8. Then modify the php.ini
  9. Extension_dir = "./"
  10. Revision changed to
  11. Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
  12. and add a row
  13. extension=memcache.so
  14. #/etc/init.d/php-fpm Restart


#memcache. PHP Test Files

    1. <?
    2. $memcache = new Memcache;//Create a Memcache object
    3. $memcache->connect (' localhost ', 11211) or Die ("Could not Connect");//Connect memcached server
    4. $memcache->set (' key ', ' test ');//set a variable into memory, the name is the key value is test
    5. $get_value = $memcache->get (' key ');//Remove the value of key from memory
    6. echo $get _value;
    7. ?>
    8. Output test, indicating the success of the building!

#php调用memcache


2.2. NET Memcache Client
http://blog.csdn.net/xiaoyong322/article/details/6544027
Http://code.google.com/p/memcached/wiki/Clients


Two memcache installing shell scripts and installation packages
1 memcached Installation Script

2 memcached Service Script

3 Memcached installation Package


Three memcached command parameter description

    1. /usr/local/memcached/bin/memcached  -d -u root -m  6144 -l 10.10.10.1 -p 11211 -c 100000 -p /var/run/memcached.pid  
    2. -p  The port   of the listener,
    3. -l  the IP address of the connection,  default all IP addresses  
    4. -d  start  start the memcached service  
    5. -u  run   (valid only when running as root)  
    6. -m  Maximum memory usage, MB; default 64mb 
    7. -p  listening  TCP port number; default  11211 
    8. -c  The maximum number of simultaneous connections, the default is 1024 
    9. -p memcache pid file,  need to use  -d   parameter  
    10. -f  block size growth factor, default is 1.25 
    11. -n  minimum allocation space, key+value+flags default is 48  
    12. -h  Display Help  



Quad memcached Server Debug


Telnet to the Memcache server, such as Telnet 10.0.1.252 11211
Stats View basic information
Stats items can see a lot of items in the line
Stats cachedump 1 0 (3 is the number following the items, 0 means all are displayed)
Get Key (key is the string after item)

  1. #memcached server 1
  2. $ telnet 10.10.10.1 11211
  3. Trying 10.10.10.1 ...
  4. Connected to 10.10.10.1.
  5. Escape character is ' ^] '.
  6. Stats
  7. STAT PID 1750
  8. STAT Uptime 106479
  9. STAT Time 1325943604
  10. STAT version 1.4.10
  11. STAT libevent 2.0.16-stable
  12. STAT Pointer_size 64
  13. STAT Rusage_user 42.595524
  14. STAT Rusage_system 140.332666
  15. STAT Curr_connections 1531
  16. STAT total_connections 1057087
  17. STAT Connection_structures 1874
  18. STAT Reserved_fds 20
  19. STAT Cmd_get 33790491
  20. STAT Cmd_set 1557865
  21. STAT Cmd_flush 0
  22. STAT Cmd_touch 0
  23. STAT get_hits 30863261
  24. STAT get_misses 2927230
  25. STAT delete_misses 157
  26. STAT Delete_hits 186
  27. STAT incr_misses 0
  28. STAT Incr_hits 0
  29. STAT decr_misses 0
  30. STAT Decr_hits 0
  31. STAT cas_misses 0
  32. STAT Cas_hits 0
  33. STAT Cas_badval 0
  34. STAT Touch_hits 0
  35. STAT touch_misses 0
  36. STAT Auth_cmds 0
  37. STAT auth_errors 0
  38. STAT Bytes_read 8488077314
  39. STAT Bytes_written 173942242454
  40. STAT limit_maxbytes 6442450944
  41. STAT Accepting_conns 1
  42. STAT Listen_disabled_num 0
  43. STAT Threads 4
  44. STAT Conn_yields 9
  45. STAT Hash_power_level 19
  46. STAT hash_bytes 4194304
  47. STAT hash_is_expanding 0
  48. STAT expired_unfetched 31545
  49. STAT evicted_unfetched 0
  50. STAT bytes 1309377867
  51. STAT Curr_items 404976
  52. STAT Total_items 1557865
  53. STAT Evictions 0
  54. STAT reclaimed 47812
  55. #memcached server 2
  56. # telnet 10.0.1.252 11211
  57. Trying 10.0.1.252 ...
  58. Connected to 10.0.1.252 (10.0.1.252).
  59. Escape character is ' ^] '.
  60. Stats items
  61. STAT Items:1:number 1
  62. STAT Items:1:age 10975
  63. STAT items:1:evicted 0
  64. STAT Items:1:evicted_nonzero 0
  65. STAT Items:1:evicted_time 0
  66. STAT Items:1:outofmemory 0
  67. STAT Items:1:tailrepairs 0
  68. STAT items:1:reclaimed 0
  69. STAT items:1:expired_unfetched 0
  70. STAT items:1:evicted_unfetched 0
  71. END
  72. Stats Cachedump 1 0
  73. ITEM key [4 B; 1325927086 S]
  74. END
  75. Get key
  76. VALUE Key 0 4
  77. Test
  78. END

Extended
Memcache Agreement Chinese version


End

Memcached saves disk reads and writes, database connections, SQL parsing resources, and it uses memory to manage data, so it can provide better performance than a direct read database. In large systems, access to the same data is frequent, and memcached can significantly reduce database stress.
Memcached is also often used as a storage medium for data sharing between servers, such as in a Web cluster where the session can be saved in memcached and shared by multiple applications.
Memcached is to put data in memory, not persistent storage, and once the server restarts, the data will be lost.

Memcached distributed Cache system deployment and debugging

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.