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?
Best Answer
looks like you mismatched the port settings:
and
use same ports for replication (which is ok as you use different machines)
But, why did you start these daemons with other ports:
and
I sugest changing
11217
to11216
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-lennyoutputs from a working example:
See how I started memcached (truncated from pstree):
and on the other node:
Ports used:
and the other node
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.