How to configure memcache in windows

Source: Internet
Author: User

Decompress the memcache Server installation package to the C: \ memcached folder and use the cmd command window to install the package.

1> Start> Run: CMD (OK)

2> cd C: \ memcached (Press ENTER)

3> memcached-d install (Press enter to execute the installation)

4> memcached-d start (Press enter to start the memcache server. The default memory is 64 MB and port 11211 is used)

Now the memcache server can be used normally.

Run on the server:
#./Memcached-d-m 2048-l 10.0.0.40-p 11211
This starts a process that occupies 2 GB of memory and opens port 11211 to receive requests. Because the 32-bit system can only handle 4G memory addressing, 2-3 processes can be run on 32-bit servers with 4G memory and monitored on different ports.

Another example is memcached-d-m 10-u root-l 192.168.105.73-p 12000-c 256-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.105.73,
-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 am saving it in/tmp/memcached. pid

Memcache server security:

The Memcache server directly performs operations after being connected through the client without any verification process. In this way, it is dangerous to directly expose the server to the Internet, if data leaks are viewed by other unrelated personnel, the server may be infiltrated. Besides, some unknown bugs or buffer overflow may exist, which are unknown to us, so the danger is foreseeable. For the sake of security, we provide two suggestions to slightly prevent hacker intrusion or data leakage.

The following describes how to modify the configuration of the memcache Server:

1> web application server calls are provided using an intranet ip address. Direct calls through the Internet are not allowed, for example, placing the memcache server on the server 192.168.1.55.

2> modify the port, for example, to 11200.

3> allocate memory, for example, allocate 1024 MB (1 GB memory)

The method is as follows:

1> Start> Run: CMD (OK)

2> cd C: \ memcached (Press ENTER)

3> memcached-m 1024-p 11200-l 192.168.1.55 (Press ENTER)

Note that the command line does not return to the C: \ memcached> status at this time, and the memcache server is quietly in the stop status. This window cannot be closed. Open a new cmd window

4> Start> Run: CMD (OK)

5> cd C: \ memcached (Press ENTER)

6> memcached-d start (Press ENTER) to close the cmd window.

Now you can use the newly configured memcache server.

Although the above method solves the problem of modifying the default configuration, there will always be a cmd window that cannot be closed, otherwise it will return to the default configuration of port 11211.

A better solution is to modify the Registry configuration of the Service:

1> Start> Run: regedit (Press ENTER)

2> in the registry, find HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ memcached Server.

3> the default ImagePath key value is: "c: \ memcached \ memcached.exe"-d runservice, changed to: "c: \ memcached \ memcached.exe "-d runservice-m 512-p 11200-l 192.168.1.55 (OK, close the registry)

4> right-click my computer> Manage> Find the memcache service and restart it to take effect.

At this time, computers in the same network segment can still use this memcache server. We can only use the specified web application server through the firewall. For example, only access from the Web server 192.168.1.2 to the Memcache server can be effectively prevented from unauthorized access, and other rules can be added to enhance security, this can be done according to your own needs.

The Memcache server directly performs operations after being connected through the client without any verification process. In this way, it is dangerous to directly expose the server to the Internet, if data leaks are viewed by other unrelated personnel, the server is infiltrated because Mecache runs with the root permission. Besides, some unknown bugs or buffer overflow may exist, these are all unknown, so the danger is foreseeable. For the sake of security, I have made two suggestions to slightly prevent hacker intrusion or data leakage.

Intranet access
It is recommended that the access between the two servers is in the Intranet format, generally between the Web server and the Memcache server. Generally, the server has two NICs, one pointing to the Internet and the other pointing to the Intranet, so that the Web server can access the Memcache server through the Intranet Nic, when the Memcache server is started, it listens to the Intranet IP address and port, and the access between the Intranet can effectively prevent other illegal access.
# Memcached-d-m 1024-u root-l 192.168.0.200-p 11211-c 1024-P/tmp/memcached. pid
The Memcache server sets listening to port 11211 of the ip address 192.168.0.200 over the Intranet, occupying 1024 MB of memory and allowing a maximum of concurrent connections.

Set firewall
Firewall is a simple and effective method. If both servers are connected to the Internet and Memcache needs to be accessed through an Internet IP address, you can use a firewall or proxy program to filter out illegal access.
In Linux, we can use iptables or FreeBSD ipfw to specify rules to prevent unauthorized access. For example, we can set to allow only our Web servers to access our Memcache server, at the same time, other accesses are blocked.
# Iptables-F
# Iptables-P INPUT DROP
# Iptables-a input-p tcp-s 192.168.0.2-dport 11211-j ACCEPT
# Iptables-a input-p udp-s 192.168.0.2-dport 11211-j ACCEPT
The above iptables rule only allows access from the Web server 192.168.0.2 to the Memcache server. It can effectively prevent some illegal access and add other rules to enhance security, this can be done according to your own needs.

It is often necessary to monitor the running status of Memcached on the server, such as the number of cache queries and hit rate. But
The memcached-tool is written in perl in linux, and I have never tried whether it can be used in windows. Later, I found a simple way to do this, that is, using Telnet.

1. In windows, connect to the memcached port. In the cmd command line, type telnet 192.168.1.1 11211 11211 as the port number bound to memcached.
2. After connecting to the port, enter the stats command to obtain the parameters that describe the running status of the Memcached server.
STAT pid 4356 server process ID
STAT uptime 56625 server running time, in seconds
STAT time 1225249079 current UNIX time of the server
STAT version 1.1.0 server version
STAT pointer_size 64
STAT rusage_user 151.845489 cumulative user time of the process (seconds: subtle)
STAT rusage_system 121.667603 accumulated system time of the process (seconds: subtle)
STAT ibuffer_size 4096
STAT curr_connections 13 connection count
STAT total_connections 54136 total number of connections received since the server was running
STAT connection_structures 318 Number of connection structures allocated by the server
STAT performance_get 100595 total number of retrieved requests
STAT performance_set 6510 total number of storage requests
STAT get_hits 96543 total number of successful requests
STAT get_misses 4052 total number of failed requests
STAT bytes_read 4427679 total number of bytes the server reads from the network
STAT bytes_written 6585596 total number of bytes the server sends to the network

1> uptime is the number of seconds for memcached to run,
2> pai_get is the number of times the cache is queried.
3> split the two data to get the average number of requests cached per second-the recent niupu traffic is very low, so the average request is more than once per second,
With such great pressure, it is no problem to use the file system cache, and it does not reflect the advantages of using memcached.
4>. The number of times the key => value is set in the cmd_set below. The entire memcached is a large hash, which is not found by using ipv_get.
Then, it will call cmd_set to write it into the cache.
5> followed by get_hits, which is the number of cache hits. Cache hit rate = get_hits/pai_get * 100%.
6> The following get_misses number plus get_hits should be equal to pai_get.
7>, while total_itemscurr_items indicates the number of key-value pairs in the cache.
8> total_items = resource_set = get_misses on the graph. However, when the maximum available memory is used up, memcached deletes some content and the above equation is not true.

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.