开发者

How do I see if memcached is already running on my chosen port?

I am havin开发者_Go百科g some problems with memcached and one idea I am having is that perhaps it is already running on the port I am trying to run it on, started by some other user on our network. Is there a way to tell what memcached ports are currently in use?


To see if it is running you could also try telnetting into the port:

telnet localhost 11211

If this works you will see the following (telling you that the given port is open):

Connected to localhost.
Escape character is '^]'.

Now if memcached IS running you can see some basic stats by issuing the given command:

stats

If this fails you will know that memcached is not running.


Try

netstat -ap | grep TheChosenPort#

and see if anything is listening on those TCP or UDP ports.


netstat

In Linux, check via netstat, e.g.

$ sudo netstat -nap | grep memcached
tcp        0      0 127.0.0.1:11211  0.0.0.0:*  LISTEN      5067/memcached

ps

Use ps to filter the processes:

$ ps wuax | grep memcache
497 5067  0.0  1.3 384824 53928 ? Ssl  Apr11   1:28 memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid -l 127.0.0.1

The port can be found next to -p, e.g. -p 11211. If port hasn't been specified, default is 11211.

Bash

You can send stats command to the given port and see if the memcached responds, e.g.

exec 3<>/dev/tcp/localhost/11211; printf "stats\nquit\n" >&3; cat <&3

Telnet

Use telnet to connect to the host and run stats (as above), e.g.

$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
stats
STAT pid 23669
STAT uptime 433859

Then hit Ctrl-] and Ctrl-D to finish.


Use the following command

ps -U user | grep -v grep | grep memcached


You can check memcached status

service memcached status

You will see a line like this at the bottom:

       └─1560 /usr/bin/memcached -vv -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid

The -p 11211 is what port it's running on.


If you're asking this question, it sounds like you're running a really old version. If you did this on a recent version, you'd see this:

% ./memcached
failed to listen on TCP port 11211: Address already in use
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜