5
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?

navin kumar
  • 191
  • 3
  • 6
  • 16
  • the `-d` option on windows manages a windows style service - it's completely different from the -d option on linux. When you do `-d start` it starts the windows service, and **completely ignores** the -p option. If you want to test it on multiple ports open up two cmd windows and launch it separately in each **without** the -d option – Anya Shenanigans Aug 14 '13 at 08:52

1 Answers1

18

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.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • when i tried with c:\memcached>sc start Memcached11211 got the following error. [SC] StartService: OpenService FAILED 1060: The specified service does not exist as an installed service. Any idea..why it came.? I just open the Elevated command prompt then executed the first two sc statment.then i changed the directory where my memcached.exe file is ,That is c:\memcached. – navin kumar Aug 14 '13 at 10:33
  • Did the service register? You should have seen: `[SC] CreateService SUCCESS` once you created the service. If you do not see this message then the `sc start memcached11211` will fail as the service **was not installed**. You can check if the service exists, and it's state using: `sc query memcached11211`. Additionally, make sure you're using the entire command line - the `displayname=""` is needed – Anya Shenanigans Aug 14 '13 at 10:42
  • DESCRIPTION: Creates a service entry in the registry and Service Database. USAGE: sc create [service name] [binPath= ] ... OPTIONS: NOTE: The option name includes the equal sign. A space is required between the equal sign and the value. type= (default = own) start= (default = demand) error= (default = normal) – navin kumar Aug 14 '13 at 10:48
  • binPath= group= tag= depend= obj= (default = LocalSystem) DisplayName= password= – navin kumar Aug 14 '13 at 10:49
  • when i Executed the first SC command in the Elevated Command prompt. – navin kumar Aug 14 '13 at 10:50
  • I've updated the SC command line - it doesn't need spaces on some platforms; it looks like it needs the space on your system – Anya Shenanigans Aug 14 '13 at 10:50
  • Do i have to provide the space after the equal sign? – navin kumar Aug 14 '13 at 10:53
  • You have to provide the space after the equal sign, otherwise on your platform it will fail. You could have just mentioned the **important** piece, that the `option=` needs a space on your system (it looks to have been changed for Windows 8 to accept either with or without a space) – Anya Shenanigans Aug 14 '13 at 10:55
  • yaa its working now. thanx alot. But how i will spacify the size of the memcached for each port. i want to specify the size for the memcached other than its default value. – navin kumar Aug 14 '13 at 11:09
  • can we increase size by specifying -m 1024? – navin kumar Aug 14 '13 at 11:12
  • add those parameters to the `binpath=` option of the `sc create` command, or if you're updating the settings, you can use `sc config binpath= "new command line with parameters"`. You'll need to restart the service to have the change take effect – Anya Shenanigans Aug 14 '13 at 12:35
  • Thanks for this, @Petesh; this answer was a lifesaver when the elsewhere documented `memcache -d install` and `memcache -d start` failed on me. And it's nice to know about `sc` also. Would that I could favorite an answer and not a question. – DopeGhoti Nov 19 '14 at 05:02