Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have compiled the memcached-repcached with --enable-replication option, and started it like below:

on the server 1:

# /usr/local/memcached/bin/memcached -v -d -u memcached -l 192.168.7.106 -p 11216 -c 2048 -m 512 -P /usr/local/memcached/var/run/test.pid -x 192.168.3.82 -X 11216
# replication: connect (peer=192.168.3.82:11216)
replication: marugoto copying
replication: close
replication: failed to initialize replication server socket

on the server 2:

# /usr/local/memcached/bin/memcached -v -d -u memcached -l 192.168.3.82 -p 11216 -c 2048 -m 512 -P /usr/local/memcached/var/run/test.pid -x 192.168.7.106 -X 11216
replication: connect (peer=192.168.7.106:11216)
replication: marugoto copying

But it seems that the server 2 only connect to memcached instance on the server 1, it didn't listen on port 11216:

# lsof -i :11216
COMMAND     PID      USER   FD   TYPE   DEVICE SIZE NODE NAME
memcached 12786 memcached    6u  IPv4 55213579       TCP 192.168.3.82:56176->192.168.7.106:11216 (ESTABLISHED)

therefore I cannot telnet on server 2:

# telnet 192.168.3.82 11216
Trying 192.168.3.82...
telnet: connect to address 192.168.3.82: Connection refused
telnet: Unable to connect to remote host: Connection refused

But if I try to replicate 2 memcached instances on only one server with different port, it works fine:

$ telnet 192.168.7.106 11216
Trying 192.168.7.106...
Connected to 192.168.7.106.
Escape character is '^]'.
set foo 0 0 3
bar
STORED

$ telnet 192.168.7.106 11217
Trying 192.168.7.106...
Connected to 192.168.7.106.
Escape character is '^]'.
marugoto_end
rep foo 0 0 3 1
bar
get foo
VALUE foo 0 3
bar
END

Did I miss something?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

looks like you mismatched the port settings:

-x 192.168.3.82 -X 11216

and

-x 192.168.7.106 -X 11216

use same ports for replication (which is ok as you use different machines)

But, why did you start these daemons with other ports:

-l 192.168.7.106 -p 11217

and

-l 192.168.3.82 -p 11216

I sugest changing 11217 to 11216 and that should start working right away. I guess you already started with default settings to see repcached basically working, right? My default settings worked fine, like: http://marcusspiegel.de/2010/05/02/howto-install-memcached-with-repcached-build-in-server-side-replication-on-debian-lenny

outputs from a working example:

See how I started memcached (truncated from pstree):

  |-memcached,2915 -m 64 -p 11211 -u root -P /var/run/memcachedrep.pid -d -x 192.168.18.11

and on the other node:

  |-memcached,2965 -m 64 -p 11211 -u root -P /var/run/memcachedrep.pid -d -x 192.168.18.10

Ports used:

tcp        0      0 192.168.18.11:54122     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.11:54133     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.11:54130     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.11:54125     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.11:52466     192.168.18.10:11211     TIME_WAIT   -               
tcp6       0      0 192.168.18.11:11212     192.168.18.10:37881     VERBUNDEN   2965/memcached

and the other node

tcp        0      0 192.168.18.10:57768     192.168.18.10:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:45406     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:45412     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:56134     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:40624     192.168.18.10:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:37881     192.168.18.11:11212     VERBUNDEN   2915/memcached  
tcp        0      0 192.168.18.10:57750     192.168.18.10:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:45428     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:45419     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:45410     192.168.18.11:11211     TIME_WAIT   -               
tcp        0      0 192.168.18.10:57766     192.168.18.10:11211     TIME_WAIT   -       

Keep in mind The port used for replication (11212) is different form that port used for serving the cache (11211)!

The replication port has to be the same on both machines and must be accessible from each others interfaces. The serving port is setup to be the same on both nodes as both nodes are connecting to the same ports as clients, too. That mimiks a setup like Master-Master-Replication in MySQL.

share|improve this answer
    
Wow, now it works. I was confused with replication port when thinking it can be the same with listening port. Thank you very much! –  quanta Oct 7 '12 at 2:58

Sorry, it's my mistake. It should be 11216 (I mixed up with the port when testing with 2 instances on the server 1).

On your blog, you didn't specific the TCP port for replication (-X). By the default, it's 11212, not 11211, therefore you cannot telnet to 11211. Moreover, you have a typo mistake with the IP address in DAEMON_ARGS, 192.168.168.62 instead of 192.168.168.2.

I've tested again, and still got the "Connection refused" error when telnet. Below is details:

Start memcached on the 106:

# /usr/local/memcached/bin/memcached -v -d -u memcached -l 192.168.7.106 -p 11216 -c 2048 -m 512 -P /usr/local/memcached/var/run/test.pid -x 192.168.3.82 -X 11216
replication: connect (peer=192.168.3.82:11216)
replication: marugoto copying
replication: close
replication: listen
failed to listen
replication: accept

Start memcached on the 82:

# /usr/local/memcached/bin/memcached -v -d -u memcached -l 192.168.3.82 -p 11216 -c 2048 -m 512 -P /usr/local/memcached/var/run/test.pid -x 192.168.7.106 -X 11216
replication: connect (peer=192.168.7.106:11216)
replication: marugoto copying
replication: start

on the 106:

# lsof -i :11216
COMMAND   PID      USER   FD   TYPE   DEVICE SIZE NODE NAME
memcached 777 memcached    7u  IPv4 10701963       TCP 192.168.7.106:11216->192.168.3.82:60861 (ESTABLISHED)

on the 82:

# lsof -i :11216
COMMAND     PID      USER   FD   TYPE   DEVICE SIZE NODE NAME
memcached 18305 memcached    6u  IPv4 55702870       TCP 192.168.3.82:60861->192.168.7.106:11216 (ESTABLISHED)
memcached 18305 memcached    9u  IPv4 55702872       TCP 192.168.3.82:11216 (LISTEN)

Testing with telnet:

# telnet 192.168.7.106 11216
Trying 192.168.7.106...
telnet: connect to address 192.168.7.106: Connection refused
telnet: Unable to connect to remote host: Connection refused

I also tried to bind memcached to any interface (didn't specific -l when start), but it still don't listen on port 11216:

$ ps -ef | grep 11216
502       2305     1  0 10:37 ?        00:00:00 /usr/local/memcached/bin/memcached -v -d -u memcached -p 11216 -c 2048 -m 512 -P /usr/local/memcached/var/run/test.pid -x 192.168.3.82 -X 11216

# lsof -i :11216
COMMAND    PID      USER   FD   TYPE   DEVICE SIZE NODE NAME
memcached 2305 memcached    7u  IPv6 10707474       TCP 192.168.7.106:11216->192.168.3.82:47534 (ESTABLISHED)
share|improve this answer
    
Thanks for advise! Although defaut ports are 11211 in my install... anyway. There is a line in your post telling: failed to listen on your 106. That might indicate another deamon already running or at least that port beeing already used by another process –  Marcus Spiegel Mar 22 '11 at 15:03
    
Default port for replication is 11212, not 11211 -X <num> TCP port number for replication (default: 11212) I also checked (lsof, netstat -nal) to make sure there is no process listen on port 11216 before starting memcached. The failed to listen msg appears when I start memcached on the 106 first. After I start memcached on the 82, it will be replication: accept. You can see it from my previous post. If you already configured repcached successfully with 2 servers, please show me the output. –  quanta Mar 23 '11 at 3:42
    
Hi Quanta, I just added the output from a woking 2-node setup that is currently used in production - in my 1st answer –  Marcus Spiegel Mar 24 '11 at 8:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.