[CentOS] multiple memcached buckets in CentOS 7

Wed Mar 18 05:06:38 UTC 2015
Alberto Rivera Laporte <arlaporte at gmail.com>

>
>
> Now, under CentOS 7, I see we have two files controlling memcached under
> the new sysctl system. At least, using sysctl is new to me!
>
> I see we have this file:
>
> [root at web1:~] #cat  /usr/lib/systemd/system/memcached.service
> [Unit]
> Description=Memcached
> Before=httpd.service
> After=network.target
>
> [Service]
> Type=simple
> EnvironmentFile=-/etc/sysconfig/memcached
> ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN
> $OPTIONS
>
> [Install]
> WantedBy=multi-user.target
>
> And we have this one under sysconfig:
>
> [root at web1:~] #cat /etc/sysconfig/memcached
> PORT="11211"
> USER="memcached"
> MAXCONN="1024"
> CACHESIZE="64"
> OPTIONS=""
>
> So I'm trying to figure out how to achive the same effect that I would
> under the old init script way of doing things.
>
> Can someone please give me an example of how to get the same thing done
> under the new system?
>
>
As you said earlier on earlier ( non-systemd) versions of the memcached
init scripts, you would define all instances of memcache under the start
function.

With systemd it will be as easy as creating additional unit files ( one for
each memcached instance) with its corresponding config file.  That should
allow to stop / start / restart  each memcache instance individually while
also being systemd compliant.


Examples:

## first instance ##
#  /usr/lib/systemd/system/memcached.service
[Unit]
Description=Memcached
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN
$OPTIONS

#  /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
## end first instance

## second instance ##

## second instance ##
#  /usr/lib/systemd/system/memcached-11214.service
[Unit]
Description=Memcached-11214
Before=httpd.service
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached-11214
ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN
$OPTIONS

#  /etc/sysconfig/memcached-11214
PORT="11214"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
## end second instance

Lastly enable each service if not already enabled:
# instance 1
systemctl enable /usr/lib/systemd/system/memcached.service
systemctl start memcached.service

# instance 2
systemctl enable /usr/lib/systemd/system/memcached-11214.service
systemctl start memcached-11214.service

You can also still use legacy sysv init scripts as there is support for
backwards compatibility however the systemd approach is much simpler while
adhering to the systemd standard.

Good luck.