Ubuntu: Running Memcached as daemon
Asked Answered
P

3

10

I have installed memcached on Ubuntu. How can I run it as a daemon so that it runs in the background and I can use it in my rails application?

Phosphate answered 23/3, 2011 at 20:34 Comment(0)
Q
20

memcached is configured to run at boot by default, at least on 10.10:

# apt-get install memcached
...
Setting up memcached (1.4.5-1ubuntu1) ...
Starting memcached: memcached.
# ls -l /etc/rc*.d/*memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc0.d/K20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc1.d/K20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc2.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc3.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc4.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc5.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc6.d/K20memcached -> ../init.d/memcached
#  

In runlevels 2, 3, 4, and 5, memcached will be running.

If you're not sure, you can run the initscript with status:

# /etc/init.d/memcached status
 * memcached is running
Quandary answered 23/3, 2011 at 20:40 Comment(3)
I have installed it from source, as I had some problem installing with apt-get. Now I have ran is in daemon mode using -d switch. But /etc/init.d/memcached status say No such file or directory. However when I try 'memcached status' it say failed to listen on TCP port 11211: Address already in use. So it means it's running in background.Phosphate
Ah, you should have mentioned that you installed from source :) See if there is a contributed initscript in the memcached sources that you can install into /etc/init.d and all symlink into the /etc/rc*.d/ directories as the default packaging provides. (If the memcached source doesn't include an initscript, you might just want to run cd /tmp; apt-get source memcached and steal the initscript from the Ubuntu packaging, then edit it to reference wherever you installed your memcached executable. It might also need you to create user and group accounts.)Quandary
If you get permission denied errors when you enter the install command then remember to add sudo before it - sudo apt-get install memcached.Corduroy
N
3

Just in case anyone else ends up here looking for how to run the daemon directly (like inside a docker container for example). The flag you're looking for is -d.

/usr/bin/memcached start -u memcached -d
Nobody answered 21/12, 2018 at 16:40 Comment(0)
C
0

To install memcached on ubuntu

apt-get install memcached

To start memcached

/etc/init.d/memcached start

To restart memcached

/etc/init.d/memcached start

To check the status of memcached

/etc/init.d/memcached status

To edit memcached config

sudo vi /etc/memcached.conf

By default memcached will run on 127.0.0.1:11211 and is configured to run at boot by default

Chiles answered 3/9, 2015 at 0:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.