memcached installation and configuration in Windows and Linux environments (RPM)

Source: Internet
Author: User

First, memcached installation configurationWindows Platform Installation

1, memcached-1.2.6-win32-bin.zip:http://code.jellycan.com/memcached/, perform memcached.exe-d install installation.

2, daemon mode start: memcached.exe-m 512-d start
-D cannot specify port default port 11211 for daemon start
-m Specifies the memory size

3. Specify port start: Memcached.exe–p 33000-m 512
You can start multiple services, and the command-line window closes and the service stops.

Linux Platform Installation

1. Prepare documents

: http://code.google.com/p/memcached/downloads/list

Currently the latest version is memcached-1.4.15.tar.gz (can wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz)

This is illustrated by the example of memcached-1.4.15.tar.gz.

libevent-2.0.12-stable.tar.gz:http://libevent.org/(currently the latest version of libevent-2.0.20-stable.tar.gz can be

wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz)

2, install libevent, first verify Ls/usr/lib |grep libevent see if installed.

If a message similar to the following is installed

Ls/usr/lib |grep libevent

Libevent-1.4.so.2
libevent-1.4.so.2.1.3
Libevent-2.0.so.5
libevent-2.0.so.5.1.8
Libevent.a
Libevent_core-1.4.so.2
libevent_core-1.4.so.2.1.3
Libevent_core-2.0.so.5
libevent_core-2.0.so.5.1.8
Libevent_core.a
Libevent_core.la
Libevent_core.so
Libevent_extra-1.4.so.2
libevent_extra-1.4.so.2.1.3
Libevent_extra-2.0.so.5
libevent_extra-2.0.so.5.1.8
Libevent_extra.a
Libevent_extra.la
Libevent_extra.so
Libevent.la
Libevent_pthreads-2.0.so.5
libevent_pthreads-2.0.so.5.1.8
Libevent_pthreads.a
Libevent_pthreads.la
Libevent_pthreads.so
Libevent.so

#用tar命令解压安装文件

[Email protected] local]# TAR-ZXVF libevent-2.0.20-stable.tar.gz

Configure with the./configure command to check the current environment

[Email protected] Libevent-2.0.20-stable]./configure–prefix=/usr

[Email protected] Libevent-2.0.20-stablemake
[[Email protected] Libevent-2.0.20-stablemake Install

Installing memcached

[Email protected] local]# TAR-ZXVF memcached-1.4.15.tar.gz

[Email protected] local]# CD memcached-1.4.15

[Email protected] memcached-1.4.15]#./configure

[[email protected] memcached-1.4.15]# make
[[Email protected] Memcached-1.4.15make Install

Verifying the installation
#ll/usr/local/bin | grep memcached

-rwxr-xr-x 1 root root 245683 Sep 16:04 memcached

Start memcached

#/usr/local/bin/memcached-d-M 512-c 512-p 11211-u root-t 10

The-D option is to start a daemon.

-M is the amount of memory allocated to Memcache, in megabytes.

-U is the user running memcache.

-L is the server IP address of the listener, if there is more than one address, specify the next server I listen to the P address.

-P is set memcache listening port, I set up here 11211, preferably more than 1024 ports, we use the Uniform 11211-c option is the maximum number of concurrent connections, the default is 1024.

-P is a PID file that is set to save Memcache.

-VV starts with very vrebose mode, debugging information and error output to the console.

See also #/usr/local/bin/memcached-h

Several processes can be started on a single machine, such as

[Email protected] local]# Ps-ef | grep Memcach
Root 26928 1 0 16:17? 00:00:00/usr/local/bin/memcached-d-M 64-c 64-p 11211-u root-l 10.33.2.75-p/tmp/memcached.pid
Root 26968 1 0 16:18? 00:00:00/usr/local/bin/memcached-d-M 64-c 64-p 11212-u root-l 10.33.2.75-p/tmp/memcached2.pid
Root 26975 1 0 16:18? 00:00:00/usr/local/bin/memcached-d-M 64-c 64-p 11213-u root-l 10.33.2.75-p/tmp/memcached3.pid

Note: If everything in front of you is OK, congratulations, you can use it normally. If there are some errors, do not worry:

Error while loading shared Libraries:libevent-2.0.so.5:cannot open Shared object file:no such file or directory

Workaround:

1. First Find/-name libevent-2.0.so.5 Locate the missing link file.

2.ld_debug=libs/usr/local/bin/memcached-v

3. From the debug information to know where the program to find the link library. My side of the program to trying file=/usr/lib/libevent-1.4.so.2 and my link library's actual storage location (according to the machine bit, my is 64 bit) is/usr/local/lib64/ Libevent-1.4.so.2 (just choose one of the following locations)

4. Make a soft connection ln-s/usr/local/lib64/libevent-2.0.so.5/usr/lib/libevent-2.0.so.5

17768:trying file=/lib64/tls/x86_64/libevent-2.0.so.5
17768:trying file=/lib64/tls/libevent-2.0.so.5
17768:trying file=/lib64/x86_64/libevent-2.0.so.5
17768:trying file=/lib64/libevent-2.0.so.5
17768:trying file=/usr/lib64/tls/x86_64/libevent-2.0.so.5
17768:trying file=/usr/lib64/tls/libevent-2.0.so.5
17768:trying file=/usr/lib64/x86_64/libevent-2.0.so.5
17768:trying file=/usr/lib64/libevent-2.0.so.5

Verify that startup is successful

[Email protected] ~]# Netstat-ntlp|grep memcached

Stop memcached (Find process, kill process)

[Email protected] ~]# pgrep-l memcached
16321 memcached

[Email protected] ~]# kill-9 16321

Or

# Kill '/tmp/memcached.pid ' Second, test memcached

1, enter in the command: Telnet 192.168.120.28 11211 (the IP and memcached boot port of the host you installed), then directly tap the stats command

Stats
STAT PID 16321
STAT Uptime 2831
STAT Time 1322126000
STAT version 1.4.6
STAT libevent 2.0.12-stable
STAT Pointer_size 64
STAT Rusage_user 0.004999
STAT Rusage_system 0.004999
STAT curr_connections 12
STAT total_connections 18
STAT Connection_structures 13
STAT Cmd_get 6
STAT Cmd_set 7
STAT Cmd_flush 0
STAT Get_hits 5
STAT get_misses 1
STAT delete_misses 0
STAT Delete_hits 1
STAT incr_misses 0
STAT Incr_hits 0
STAT decr_misses 0
STAT Decr_hits 0
STAT cas_misses 0
STAT Cas_hits 0
STAT Cas_badval 0
STAT Auth_cmds 0
STAT auth_errors 0
STAT Bytes_read 5023
STAT Bytes_written 7246
STAT limit_maxbytes 536870912
STAT Accepting_conns 1
STAT Listen_disabled_num 0
STAT Threads 4
STAT Conn_yields 0
STAT bytes 2479
STAT Curr_items 2
STAT Total_items 7
STAT Evictions 0
STAT reclaimed 0
END

iii. common commands for Memcache

Query status command: stats
Query version number versions
Quit command quit
Empty the cached data (in fact, mark all cached data as expired): Flush_all

Protocol and data access for memcached

The so-called protocol, which can be understood as the syntax rules for its operations (data access), commonly used commands and parameters for accessing data are as follows:

Set: Deposit a record
Key: The value of the record
Flags: a decimal int that identifies the client flag when the record is stored and is returned when the record is fetched.
Exptim: Data expiration, 0 means no expiration, other values represent a valid number of milliseconds, after expiration, the client will not get this record, memcached in the expired records will be emptied or deleted.
Get: Represents the value that is taken from the Memcached key, and returns the end flag if there is no corresponding value.
Append: Indicates that the value corresponding to key is added at the end of the input
Delete: Remove the value corresponding to key

Reference excerpt from http://cnazure.com/2011/12/windows-linux-memcached-install-configuration/

memcached Common commands and instructions for use storage commands

Format of the stored command:

12 <command name> <key> <flags> <exptime> <bytes> <data block>

The parameters are described as follows:

<command name> Set/add/replace
<key> Find keywords
<flags> The client uses it to store extra information about key-value pairs
<exptime> The survival time of this data, 0 means forever
<bytes> Number of bytes stored
<data block> Stored data blocks (can be directly understood as value in the key-value structure)
1. Add

(1), the set that is stored anyway

This set command is used very frequently in memcached. The set command can not only be added simply, if the set key already exists, the command can update the key corresponding to the original data, that is, to achieve the role of the update.

You can view the added records in the form of "Get Key Name":

As you know, we can also remove the Delete command and add it again.

(2), add only when data does not exist

(3) Replace when the data is present

2. Delete

As you can see, deleting a key value that already exists and a record that does not exist can return different results.

Second, read command 1, get

The key of the GET command can represent one or more keys, separated by a space

2, gets

As you can see, the GET command returns a number (medium 13) More than the normal gets command. This number checks to see if the data has changed. When the data corresponding to the key changes, the number returned will also change.

3. CAs

CAS is the meaning of checked and set, which can only be stored if the last parameter matches the parameters obtained by the GET, otherwise "EXISTS" is returned.

Iii. Status Command 1, stats

2. Stats items


Perform stats items, you can see the stat items row, and if memcached stores a lot of content, there will also be a lot of stat items listed here.

3, stats cachedump slab_id limit_num

We perform the stats cachedump 1 0 command effect as follows:

The slab_id here is 1, which is determined by the results returned by the stats items in 2 (the number following the STAT items); Limit_num looks like it's going to return as many records as it's worth, but 0 means it shows all the records, and N (n>0) Indicates that N records are displayed, and if n exceeds all records under the slab, the result is the same as the result returned by 0.


Limit_num records can be traversed by stats items, stats cachedump slab_id memcached with the Get command.

4. Other Stats commands

such as stats slabs,stats sizes,stats Reset, etc. use is also more common.

Iv. Other common commands 1, append

Add the cached data after the existing cache data, such as the existing cache key does not exist for the server response as not_stored.

2, Prepend

is very similar to append, but it is useful for adding cached data before existing cache data.

3, Flush_all

The command has an optional numeric parameter. It always executes successfully and the server sends a "ok\r\n" response. The effect is to invalidate an existing project immediately (the default), or after a specified time. After that the FETCH command is executed and nothing is returned (unless the same key name is re-stored). Flush_all actually does not immediately release the memory occupied by the project, but is executed later when new items are stored (this is determined by memcached's lazy detection and deletion mechanism).

The Flush_all effect is that it causes all items to be updated earlier than the time set by Flush_all, and the command is ignored when the FETCH command is executed.

4. Other commands

Memcached also has a lot of commands, such as the storage of digital type can be used by the INCR/DECR command to increase or decrease operations, and so on, here only the development and operation of the regular use of commands, the other no longer one by one examples.

Add: A simple understanding of several caches in the. NET Framework

The importance of caching in a Web site is beyond doubt. I think many ASP. NET developers prefer to use a cache that is not a third-party caching solution (such as distributed cache memcached, Redis, and so on) when developing Web applications, but should be a variety of caching solutions already available in the. Network framework. Let's talk about the understanding of caching in the. NET Framework in the context of your own development experience.

1, System.Web.Caching.Cache

It is estimated that most of the people who have done the ASP have used the cache under this namespace, and we can use the HttpContext.Current.Cache instance directly without instantiating it. Of course, the cache class under this namespace allows you to instantiate, and of course you can completely control how to initialize this class by customizing your own caching system. I've seen a lot of articles in the garden. The CRUD auxiliary class libraries that introduce the Cache are mostly for System.Web.Caching.Cache.

It should be explained that we can also use the Httpruntime.cache under this namespace to implement caches in different representations of the Web, console, WinForm, and so on, without having to instantiate them at all. Httpruntime.cache is one of the more used classes in personal development, and now prefers the enhanced cache class MemoryCache in. NET framework4.0.

2. Output Cache

As we all know, output cache is mainly paged out cache and page partial cache. Plainly, is to cache the entire page of HTML or part of the HTML, there is nothing worth discussing, but recently saw Dudu this blog just suddenly discovered, unexpectedly use it is really very fastidious, I did not find this problem before? It seems that the ability to find and solve problems is equally important, and sometimes the former is even more important.

3, System.Runtime.Caching

Now the most used class memorycache in personal development is derived from this namespace, and the using System.Runtime.Caching is required before use. MemoryCache inherits from ObjectCache, IEnumerable, IDisposable, where ObjectCache is an abstract class. People who have used MemoryCache know that this memorycache has a property called default, which can usually be used as follows:

private static ObjectCache MemCache = Memorycache.default;

Of course we can also initialize the cache object through the public memorycache (string name, NameValueCollection config = null) constructor.

Then we can configure the memory usage quota scheme and the quota check cycle for each MemoryCache instance running in the Web. config file, the following example references MSDN:

  <system.runtime.caching>    <memoryCache>      <namedCaches>        <add name= "Default" cachememorylimitmegabytes= "  pollinginterval=" 00:02:00 "/>      </namedCaches>    </ Memorycache>  </system.runtime.caching>

These configuration implications lie in the ability to explicitly specify the memory usage quota scheme and the quota check cycle that each MemoryCache instance runs. For example, we can configure to change the memory quota of the Memorycache.default instance on demand (not knowing how much memory is available for the cache, perhaps the legendary 800M or so). The cache expiration policy is much the same as its cache framework, unlike System.Web.Caching.Cache, which is called ChangeMonitor, and provides a file-and directory-based cache dependency policy, except that the name is CacheDependency. The cache expiration policy is also more important to explore, but in personal development more emphasis on data caching and replacement, there is no contact and use of a more perfect expiration policy solution.

Excerpted from http://www.cnblogs.com/jeffwongishandsome/archive/2011/11/06/2238265.html

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.