如何在不同的端口上使用memcached

时间:2013-08-14 08:07:55

标签: java memcached spymemcached

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

但仍在侦听端口11211而不是11212.Why?

1 个答案:

答案 0 :(得分:15)

memcached for windows不会监听具有相同实例的多个端口,您需要多个服务实例才能使其作为不同端口上的服务运行。

要实现此目的,您需要使用不同的机制来安装服务,而不是memcached -d install机制。

我们可以使用sc来完成此任务。所有这些命令都需要从提升的命令提示符运行。

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

然后我们开始吧:

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             *:*�

但请注意,配置后,udp端口仍然是11211,因此需要更改以确保udp也可以用于这两种服务。

您可以在sc配置行中添加-u 11211-u 11212

要停止并使用个人memcached服务:

sc stop memcached11211
sc stop memcached11212

删除服务:

sc delete memcached11211
sc delete memcached11212

如果您只是在不同的端口上尝试,那么只需使用多个cmd窗口并以此方式运行。