Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we create two instances of memcached server in same server in different port?

Tags:

memcached

I tried to add in the way -l 11211 -l 11212 in memcached conf file. But it is just listening to first one i.e 1121

like image 456
panalbish Avatar asked May 08 '11 15:05

panalbish


People also ask

Which port is used for Memcached?

By default, UEM Server components such as DS, CN, API, and SSP talk over TCP on port 11211. When you install Memcached into your configuration, it automatically selects this port. If your network is locked down and ports must be unlocked manually, unlock port 11211 before you proceed with the installation.

What is the difference between Memcache and Memcached?

They both have very basic difference while storing value. Memcache mostly considers every value as string whereas Memcached stores it value's original type. Thumbs up for your answer !

How many key value pairs are stored on the Memcached server?

Memcached statistics hold a lot of valuable information. For example, the total number of items (i.e. key-value pairs) stored in Memcached, can be useful information to move forward. The total number of items stored in Memcached is 10.


2 Answers

Here's what memcached says the -l command is for:

-l <addr>     interface to listen on (default: INADDR_ANY, all addresses)               <addr> may be specified as host:port. If you don't specify               a port number, the value you specified with -p or -U is               used. You may specify multiple addresses separated by comma               or by using -l multiple times 

First off you need to specify the interface you want memcached to listen on if you are using the -l flag. Use 0.0.0.0 for all interfaces and use 127.0.0.1 is you just want to be able to access memcached from localhost. Second, don't use two -l flags. Use only one and separate each address by a comma. The command below should do what you want.

memcached -l 0.0.0.0:11211,0.0.0.0:11212 

Keep in mind that this will have one memcached instance listen on two ports. To have two memcached instances on one machine run these two commands.

memcached -p 11211 -d  memcached -p 11212 -d 
like image 36
mikewied Avatar answered Sep 21 '22 20:09

mikewied


First I used mikewied's solution, but then I bumped into the problem of auto starting the daemon. Another confusing thing in that solution is that it doesn't use the config from etc. I was about to create my own start up scripts in /etc/init.d but then I looked into /etc/init.d/memcached file and saw this beautiful solution

# Usage: # cp /etc/memcached.conf /etc/memcached_server1.conf # cp /etc/memcached.conf /etc/memcached_server2.conf # start all instances: # /etc/init.d/memcached start # start one instance: # /etc/init.d/memcached start server1 # stop all instances: # /etc/init.d/memcached stop # stop one instance: # /etc/init.d/memcached stop server1 # There is no "status" command. 

Basically readers of this question just need to read the /etc/init.d/memcached file.

Cheers

like image 57
Davyd Dzhahaiev Avatar answered Sep 17 '22 20:09

Davyd Dzhahaiev