How do I setup multiple memcached instances running on different ports?
Solution 1
As Robert Bihlmeyer said on https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784357#13, a simple solution is to remove /lib/systemd/system/memcached.service
.
Without this file, the systemd falls back on /etc/init.d/memcached
, which supports multiple configurations.
I confirmed this problem on Ubuntu 16.04 and solved it this way.
Solution 2
This can easily be done by creating a file /lib/systemd/system/[email protected] with basically the same contents as the memcached.service file with a few small changes:
[Unit]
Description=memcached daemon for %i
After=network.target
[Service]
ExecStart=/usr/share/memcached/scripts/systemd-memcached-wrapper /etc/memcached_%i.conf
[Install]
WantedBy=multi-user.target
You can then use systemctl to manage each service individually:
systemctl enable memcached@server1
systemctl start memcached@server2
Solution 3
Having the same issue in Debian Jessie. Will report back if I find a solution.
In the mean time you can manually start the services to achieve the desired result.
Example:
sudo /etc/init.d/memcached stop
memcached -d -m 64 -l 127.0.0.1 -p 11211 -u memcache
memcached -d -m 64 -l 127.0.0.2 -p 11211 -u memcache
Update 1: Aha! There is a bug in Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784357. Could this also affect Ubuntu?
Related videos on Youtube
Tojo Chacko
Updated on September 18, 2022Comments
-
Tojo Chacko over 1 year
I am running Ubuntu 15.10 and already have memcached installed on my system. My current project requirement is to run two instances of memcached on the same server but with different ports. I start with
/etc/memcached.conf
file and check that it has option of specifying the port number. So, I thought I just need to have two identical conf files with different port numbers.Then I check the memcached start up script
/etc/init.d/memcached
so that I could specify the location of the conf files. But to my surprise I see that the start up script already has an option to run multiple memcached instances.# 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. FILES=(/etc/memcached_*.conf) # check for alternative config schema if [ -r "${FILES[0]}" ]; then
I tried the above option, but it still keeps starting a single instance, instead of starting two instances. Am I missing something here ?
-
the_nuts about 6 yearsUnfortunately it reappears after some time, maybe with updates... How to make sure it will not be recreated?
-
Otheus over 5 yearsSuitable (with modifications) for RedHat, CentOS, etc. Just be sure to disable the "main" one:
systemctl disable memcached
-
David over 5 years[email protected] file should be better in /etc/systemd/system directory. As explained at systemd file hierarchy /lib and /usr/lib are for private vendor data (distro files). System configurations should go better in /etc.