1

My memcache server is up and running on Server A.

service memcached start memcached -d -u nobody -m 512 -p 11211 127.0.0.1 chkconfig --list | grep memcache chkconfig memcached on 

I also have a web application on Server B (different IP). How can I configure Server A for memcache to allow incoming connections from Server B?

1
  • also try checking your firewall, in my case, centOS7, the firewall was rejecting connections Commented Jan 3, 2021 at 15:37

2 Answers 2

1

By default memcached only serves the localhost as it otherwise has no protection from the wider network / internet and is insecure. As you see in the output you posted it's currently only serving connections over 127.0.0.1:

memcached -d -u nobody -m 512 -p 11211 127.0.0.1 

So, you need to edit the configuration file and give it the IP address of the network interface that you want to serve. To do this head over to the directory where the config file is located. On ubuntu, this is:

cd /etc/ 

Then open the config file in your editor of choice:

sudo nano memcached.conf 

Then scrol down until you find this:

# Specify which IP address to listen on. The default is to listen on all IP addresses # This parameter is one of the only security measures that memcached has, so make sure # it's listening on a firewalled interface. -l 127.0.0.1 

Now just replace 127.0.0.1 with the IP of your network interface and save.

Now you'll need to restart the memcached server:

sudo service memcached restart 

Memcached will now be serving only requests received via that IP/network interface. You can test this with the following command:

ps aux | grep memcached 

If everything went ok, you should see the IP you entered in the config rather than the localhost.

2
  • Thanks for the help! And if I want to include both 127.0.0.1 and the new IP address can I just blank-space separate them? Commented Nov 20, 2017 at 17:33
  • To be honest, I'm not sure. I tried a comma and space (, ) between them and whilst everything ran smoothly I was only able to connect on the IP first in the list. I didn't get around to trying with just a space. I'd be keen to here if that works or not. Commented Nov 20, 2017 at 20:54
1

In Amazon ec2 linux

Open - sudo vi /etc/sysconfig/memcached

Replace line - OPTIONS="-l 127.0.0.1,::1" with line - OPTIONS="-l 0.0.0.0,::1"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.