Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Use memcached on different port

i have excuted c:\memcached>memcached -l 0.0.0.0:11211,0.0.0.0:11212
getaddrinfo(): No such host is known.
failed to listen on TCP port 11211: No error.
and that was the response i got
if i will execute c:\memcached>memcached -p 11211 -d
memcached: option requires an argument -- d
Illegal argument "?" this was the response i got. so i tried these following commands
c:\memcached>memcached -p 11211 -d start
c:\memcached>memcached -p 11212 -d start

but still its listening to port 11211 not on 11212.why?

like image 821
navin kumar Avatar asked Aug 14 '13 08:08

navin kumar


People also ask

Which port is used for Memcached?

By default, UEM Server components such as DS, CN, API, and SSP talk over TCP on port 11211. When you install Memcached into your configuration, it automatically selects this port. If your network is locked down and ports must be unlocked manually, unlock port 11211 before you proceed with the installation.

What protocol does Memcached use?

Communicating with a memcached server can be achieved through either the TCP or UDP protocols. When using the TCP protocol, you can use a simple text based interface for the exchange of information. When communicating with memcached, you can connect to the server using the port configured for the server.

How does Memcached work internally?

In order to alleviate the load from the database, a cache is used to store the requested data so that when a user requests for some information, the application will first look into the cache and if it is found there, the application won't go to the database for it; rather, it will fetch the data from the cache and ...


1 Answers

memcached for windows will not listen on multiple ports with the same instance, you will need multiple instances of the service to get it to run as a service on different ports.

To accomplish this, you will need to use a different mechanism for installing the service, rather than the memcached -d install mechanism.

We can use sc to accomplish this. All these commands will need to be run from an elevated command prompt.

sc create "Memcached11211" binPath= "C:\memcached\memcached.exe -d runservice -p 11211"  DisplayName= "Memcached11211" start= auto
sc create "Memcached11212" binPath= "C:\memcached\memcached.exe -d runservice -p 11212"  DisplayName= "Memcached11212" start= auto

Then we start them:

C:\memcached>sc start Memcached11211

SERVICE_NAME: Memcached11211
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 5412
        FLAGS              :

C:\memcached>sc start Memcached11212

SERVICE_NAME: Memcached11212
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 7976
        FLAGS              :

C:\memcached>netstat -an | grep 112
File STDIN:
  TCP    0.0.0.0:11211          0.0.0.0:0              LISTENING
  TCP    0.0.0.0:11212          0.0.0.0:0              LISTENING
  TCP    [::]:11211             [::]:0                 LISTENING
  TCP    [::]:11212             [::]:0                 LISTENING
  UDP    0.0.0.0:11211          *:*
  UDP    0.0.0.0:11211          *:*
  UDP    [::]:11211             *:*
  UDP    [::]:11211             *:*�

Note however that as configured, the udp port is still 11211, so it would need to be changed to ensure that udp can be used as well for both services.

You would add a -u 11211 and -u 11212 to the sc configuration lines.

To stop and individual memcached service you would use:

sc stop memcached11211
sc stop memcached11212

to remove the services do:

sc delete memcached11211
sc delete memcached11212

If however you're just trying it out on different ports then just use multiple cmd windows and run it that way.

like image 60
Petesh Avatar answered Sep 20 '22 23:09

Petesh